Skip to content

Fix build on Windows OS #3882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.URI;
Expand Down Expand Up @@ -137,43 +138,38 @@ private static void extract(String inPath, String outPath) throws Exception {
Path source = Paths.get(inPath);

try (ZipInputStream zis = new ZipInputStream(new FileInputStream(source.toFile()))) {

// list files in zip
ZipEntry zipEntry = zis.getNextEntry();

while (zipEntry != null) {
Path path = target.resolve(zipEntry.getName()).normalize();

boolean isDirectory = false;

if (zipEntry.getName().endsWith(File.separator)) {
isDirectory = true;
if (!path.startsWith(target + File.separator)) {
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
}

Path targetDirResolved = target.resolve(zipEntry.getName());

Path normalizePath = targetDirResolved.normalize();
if (!normalizePath.startsWith(target)) {
throw new IOException("Bad zip entry: " + zipEntry.getName());
}

Path newPath = normalizePath;

if (isDirectory) {
Files.createDirectories(newPath);
if (zipEntry.isDirectory()) {
if (!Files.isDirectory(path)) {
Files.createDirectories(path);
}
} else {
if (newPath.getParent() != null) {
if (Files.notExists(newPath.getParent())) {
Files.createDirectories(newPath.getParent());
// fix for Windows-created archives
Path parent = path.getParent();
if (!Files.isDirectory(parent)) {
Files.createDirectories(parent);
}

// write file content
try (OutputStream os = Files.newOutputStream(path)) {
byte[] buffer = new byte[1024];
int len;
while ((len = zis.read(buffer)) > 0) {
os.write(buffer, 0, len);
}
}
Files.copy(zis, newPath, StandardCopyOption.REPLACE_EXISTING);
}

zipEntry = zis.getNextEntry();

}
zis.closeEntry();

}
}

Expand All @@ -182,10 +178,9 @@ private static void extract(String inPath, String outPath) throws Exception {
* Compress temp directory back into Jar after transformed
*
*/

public static void jar(Path sourcePath, String outJarPath) throws IOException {

URI uri = URI.create("jar:file:" + outJarPath);
URI uri = URI.create("jar:" + Paths.get(outJarPath).normalize().toUri());

Files.walkFileTree(sourcePath, new SimpleFileVisitor<Path>() {
@Override
Expand Down