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;
result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz");
OutputStream gzipOutputStream = new GzipCompressorOutputStream(
new BufferedOutputStream(new FileOutputStream(result)));
TarArchiveOutputStream out = new TarArchiveOutputStream(gzipOutputStream);
@ -137,7 +136,19 @@ public class SibaManager
if (file.isDirectory())
{
directoryToSave(file, outputStream, pathLength);
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);
}
}
else
{

View File

@ -46,8 +46,8 @@ public class SibaManagerTest
public void backupTest02() throws ArchiveException, IOException, SibaNullException
{
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.
String encoding = null;
String md5LineTarget = FileUtils.readFileToString(target, encoding);