diff options
-rw-r--r-- | src/main/java/org/openslx/taskmanager/tasks/RecompressArchive.java | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/RecompressArchive.java b/src/main/java/org/openslx/taskmanager/tasks/RecompressArchive.java index d428f03..1b5cf8a 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/RecompressArchive.java +++ b/src/main/java/org/openslx/taskmanager/tasks/RecompressArchive.java @@ -3,6 +3,8 @@ package org.openslx.taskmanager.tasks; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,23 +47,32 @@ public class RecompressArchive extends AbstractTask @Override protected boolean execute() { - if ( execute2() ) { - return true; + String fn = new File( this.outputFile ).getName(); + String tmpFile = "/tmp/bwlp-" + System.nanoTime() + "-" + fn; + if ( execute2( tmpFile ) ) { + try { + FileUtils.deleteQuietly( new File( this.outputFile ) ); + Files.move( Paths.get( tmpFile ), Paths.get( this.outputFile ) ); + return true; + } catch ( Exception e ) { + status.error = e.toString(); + status.errorCode = Output.ErrorCode.WRITE_FAILED; + } } - FileUtils.deleteQuietly( new File( this.outputFile ) ); + FileUtils.deleteQuietly( new File( tmpFile ) ); return false; } - private boolean execute2() + private boolean execute2( String archiveFile ) { // Open output file archive TarArchiveOutputStream outArchive = null; try { try { FileUtils.forceMkdir( new File( new File( this.outputFile ).getParent() ) ); - outArchive = Archive.createTarArchive( this.outputFile ); + outArchive = Archive.createTarArchive( archiveFile ); } catch ( IOException e2 ) { - status.error = e2.getMessage(); + status.error = e2.toString(); status.errorCode = Output.ErrorCode.WRITE_FAILED; return false; } |