@@ -270,7 +270,7 @@ public static Boolean decompress(String file, String path, CompressionConfigurat
270270 }
271271 }
272272 } catch (Exception e ) {
273- log .error (ARCHIVE_SIZE_ESTIMATION_ERROR + file , e );
273+ log .error (ARCHIVE_SIZE_ESTIMATION_ERROR + "{}" , file , e );
274274 storageMessages ("Error estimating archive size: " + file , messages [0 ]);
275275 return false ;
276276 }
@@ -672,10 +672,18 @@ private static void decompressGzip(File archive, String directory) throws IOExce
672672 if (!archive .exists () || !archive .isFile ()) {
673673 throw new IllegalArgumentException ("The archive file does not exist or is not a file." );
674674 }
675+
675676 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." );
678685 }
686+
679687 File tempFile = File .createTempFile ("decompressed_" , ".tmp" );
680688 try (
681689 FileInputStream fis = new FileInputStream (archive );
@@ -697,6 +705,7 @@ private static void decompressGzip(File archive, String directory) throws IOExce
697705 isTar = true ;
698706 }
699707 } catch (IOException ignored ) {}
708+
700709 if (isTar ) {
701710 try (FileInputStream tarFis = new FileInputStream (tempFile );
702711 TarArchiveInputStream tarInput = new TarArchiveInputStream (tarFis )) {
@@ -706,12 +715,16 @@ private static void decompressGzip(File archive, String directory) throws IOExce
706715 File outFile = new File (targetDir , entry .getName ());
707716 if (entry .isDirectory ()) {
708717 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 );
710721 }
711722 } else {
712723 File parent = outFile .getParentFile ();
713724 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 );
715728 }
716729 try (FileOutputStream os = new FileOutputStream (outFile )) {
717730 byte [] buffer = new byte [8192 ];
@@ -742,6 +755,7 @@ private static void decompressGzip(File archive, String directory) throws IOExce
742755 }
743756 }
744757 }
758+
745759 if (!tempFile .delete ()) {
746760 tempFile .deleteOnExit ();
747761 }
0 commit comments