@@ -67,57 +67,56 @@ public UnzipResult unzip(Path zip, Path target) throws IOException {
6767
6868 while (entries .hasMoreElements ()) {
6969 ZipArchiveEntry entry = entries .nextElement ();
70+ if (!entry .getName ().startsWith (projectDirInZip )) {
71+ log .debug ("Skipping non project file from zip - {}" , entry .getName ());
72+ continue ;
73+ }
7074
71- if (entry .getName ().startsWith (projectDirInZip )) {
72- String restOfPath =
73- trimSlashes (entry .getName ().substring (projectDirInZip .length ()));
75+ String restOfPath =
76+ trimSlashes (entry .getName ().substring (projectDirInZip .length ()));
7477
75- Path entryTargetPath =
76- target .resolve (trimSlashes (restOfPath .replace ("/" , File .separator )));
77- pathsInZip .add (entryTargetPath );
78+ Path entryTargetPath =
79+ target .resolve (trimSlashes (restOfPath .replace ("/" , File .separator )));
80+ pathsInZip .add (entryTargetPath );
7881
82+ log .debug (
83+ "Processing zipEntry with name {} to {}" ,
84+ entry .getName (),
85+ entryTargetPath );
86+ if (entry .isDirectory () || entryTargetPath .toFile ().isDirectory ()) {
87+ Files .createDirectories (entryTargetPath );
7988 log .debug (
80- "Processing zipEntry with name {} to {}" ,
81- entry .getName (),
82- entryTargetPath );
83- if (entry .isDirectory () || entryTargetPath .toFile ().isDirectory ()) {
84- Files .createDirectories (entryTargetPath );
85- log .debug (
86- "{} is a directory - creating and off to the next file " ,
87- entry .getName ());
88- continue ;
89- }
90- boolean shouldWrite ;
91- InputStream entryContent = zipFile .getInputStream (entry );
92- byte [] entryData = IOUtils .toByteArray (entryContent );
93- if (Files .exists (entryTargetPath )) {
94- log .trace ("Allowed to unzip, unzipping" );
95-
96- if (fileContentEquals (target .toFile (), entryData )) {
97- shouldWrite = false ;
98- result .unchangedFiles .add (entryTargetPath );
99- } else if (allowedToUnzip (entryTargetPath , target )) {
100- shouldWrite = true ;
101- result .overwrittenFiles .add (entryTargetPath );
102- } else {
103- shouldWrite = false ;
104- result .skippedFiles .add (entryTargetPath );
105- }
106- } else {
89+ "{} is a directory - creating and off to the next file " ,
90+ entry .getName ());
91+ continue ;
92+ }
93+ boolean shouldWrite ;
94+ InputStream entryContent = zipFile .getInputStream (entry );
95+ byte [] entryData = IOUtils .toByteArray (entryContent );
96+ if (Files .exists (entryTargetPath )) {
97+ log .trace ("Allowed to unzip, unzipping" );
98+
99+ if (fileContentEquals (target .toFile (), entryData )) {
100+ shouldWrite = false ;
101+ result .unchangedFiles .add (entryTargetPath );
102+ } else if (allowedToUnzip (entryTargetPath , target )) {
107103 shouldWrite = true ;
108- result .newFiles .add (entryTargetPath );
109- }
110- if (shouldWrite ) {
111- FileUtils .writeByteArrayToFile (entryTargetPath .toFile (), entryData );
104+ result .overwrittenFiles .add (entryTargetPath );
112105 } else {
113- log . trace ( "Not allowed to unzip, skipping file" ) ;
106+ shouldWrite = false ;
114107 result .skippedFiles .add (entryTargetPath );
115108 }
116- log .debug ("Done with file {}" , entryTargetPath );
117-
118109 } else {
119- log .debug ("Skipping non project file from zip - {}" , entry .getName ());
110+ shouldWrite = true ;
111+ result .newFiles .add (entryTargetPath );
112+ }
113+ if (shouldWrite ) {
114+ FileUtils .writeByteArrayToFile (entryTargetPath .toFile (), entryData );
115+ } else {
116+ log .trace ("Not allowed to unzip, skipping file" );
117+ result .skippedFiles .add (entryTargetPath );
120118 }
119+ log .debug ("Done with file {}" , entryTargetPath );
121120 }
122121 }
123122
0 commit comments