@@ -270,7 +270,7 @@ public static Boolean decompress(String file, String path, CompressionConfigurat
270
270
}
271
271
}
272
272
} catch (Exception e ) {
273
- log .error (ARCHIVE_SIZE_ESTIMATION_ERROR + file , e );
273
+ log .error (ARCHIVE_SIZE_ESTIMATION_ERROR + "{}" , file , e );
274
274
storageMessages ("Error estimating archive size: " + file , messages [0 ]);
275
275
return false ;
276
276
}
@@ -672,10 +672,18 @@ private static void decompressGzip(File archive, String directory) throws IOExce
672
672
if (!archive .exists () || !archive .isFile ()) {
673
673
throw new IllegalArgumentException ("The archive file does not exist or is not a file." );
674
674
}
675
+
675
676
File targetDir = new File (directory );
676
- if (!targetDir .exists () || !targetDir .isDirectory ()) {
677
- throw new IllegalArgumentException ("The specified directory does not exist or is not a directory." );
677
+ if (!targetDir .exists ()) {
678
+ if (!targetDir .mkdirs ()) {
679
+ String error = "Failed to create target directory: " + directory ;
680
+ log .error (error );
681
+ throw new IOException (error );
682
+ }
683
+ } else if (!targetDir .isDirectory ()) {
684
+ throw new IllegalArgumentException ("The specified path exists but is not a directory." );
678
685
}
686
+
679
687
File tempFile = File .createTempFile ("decompressed_" , ".tmp" );
680
688
try (
681
689
FileInputStream fis = new FileInputStream (archive );
@@ -697,6 +705,7 @@ private static void decompressGzip(File archive, String directory) throws IOExce
697
705
isTar = true ;
698
706
}
699
707
} catch (IOException ignored ) {}
708
+
700
709
if (isTar ) {
701
710
try (FileInputStream tarFis = new FileInputStream (tempFile );
702
711
TarArchiveInputStream tarInput = new TarArchiveInputStream (tarFis )) {
@@ -706,12 +715,16 @@ private static void decompressGzip(File archive, String directory) throws IOExce
706
715
File outFile = new File (targetDir , entry .getName ());
707
716
if (entry .isDirectory ()) {
708
717
if (!outFile .exists () && !outFile .mkdirs ()) {
709
- throw new IOException ("Failed to create directory: " + outFile );
718
+ String error = "Failed to create directory: " + outFile ;
719
+ log .error (error );
720
+ throw new IOException (error );
710
721
}
711
722
} else {
712
723
File parent = outFile .getParentFile ();
713
724
if (!parent .exists () && !parent .mkdirs ()) {
714
- throw new IOException ("Failed to create directory: " + parent );
725
+ String error = "Failed to create parent directory: " + parent ;
726
+ log .error (error );
727
+ throw new IOException (error );
715
728
}
716
729
try (FileOutputStream os = new FileOutputStream (outFile )) {
717
730
byte [] buffer = new byte [8192 ];
@@ -742,6 +755,7 @@ private static void decompressGzip(File archive, String directory) throws IOExce
742
755
}
743
756
}
744
757
}
758
+
745
759
if (!tempFile .delete ()) {
746
760
tempFile .deleteOnExit ();
747
761
}
0 commit comments