Modified SibaBackup for empty directory

This commit is contained in:
Didier Clermonté 2016-05-17 23:59:42 +02:00
parent 0662f108df
commit a448d7e7bf
2 changed files with 15 additions and 4 deletions

View File

@ -58,7 +58,6 @@ public class SibaManager
String outputFileNameWithoutExtension = fileToSave.getName() + "-" + textDate; String outputFileNameWithoutExtension = fileToSave.getName() + "-" + textDate;
result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz"); result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz");
OutputStream gzipOutputStream = new GzipCompressorOutputStream( OutputStream gzipOutputStream = new GzipCompressorOutputStream(
new BufferedOutputStream(new FileOutputStream(result))); new BufferedOutputStream(new FileOutputStream(result)));
TarArchiveOutputStream out = new TarArchiveOutputStream(gzipOutputStream); TarArchiveOutputStream out = new TarArchiveOutputStream(gzipOutputStream);
@ -136,9 +135,21 @@ public class SibaManager
{ {
if (file.isDirectory()) if (file.isDirectory())
{
if (file.listFiles().length == 0)
{
TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file);
String pathPartiel = file.getPath().substring(pathLength);
tarArchiveEntry.setName(pathPartiel);
outputStream.putArchiveEntry(tarArchiveEntry);
outputStream.closeArchiveEntry();
}
else
{ {
directoryToSave(file, outputStream, pathLength); directoryToSave(file, outputStream, pathLength);
} }
}
else else
{ {
TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file); TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file);

View File

@ -46,8 +46,8 @@ public class SibaManagerTest
public void backupTest02() throws ArchiveException, IOException, SibaNullException public void backupTest02() throws ArchiveException, IOException, SibaNullException
{ {
String md5LineSource = "qslfjqmlsfjmqlsjfqmlsjfsjf mqlsfjmljdf"; String md5LineSource = "qslfjqmlsfjmqlsjfqmlsjfsjf mqlsfjmljdf";
File target = SibaManager.backup(new File("../data/simplestuff"), new File("../tmp/")); File target = SibaManager.backup(new File("../data/simplestuff"), new File("/home/papou/tmp"));
System.out.println(target.getName());
// Load md5 file. // Load md5 file.
String encoding = null; String encoding = null;
String md5LineTarget = FileUtils.readFileToString(target, encoding); String md5LineTarget = FileUtils.readFileToString(target, encoding);