Skip to content

Commit

Permalink
Do not follow symlink when reading jar attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentgo committed May 7, 2024
1 parent 7723068 commit b6a1450
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileAttribute;
Expand Down Expand Up @@ -71,9 +71,6 @@ public class JarToolModularJarArchiver extends ModularJarArchiver {

private static final Pattern MRJAR_VERSION_AREA = Pattern.compile("META-INF/versions/\\d+/");

private static final boolean IS_POSIX =
FileSystems.getDefault().supportedFileAttributeViews().contains("posix");

private Object jarTool;

private boolean moduleDescriptorFound;
Expand Down Expand Up @@ -155,10 +152,11 @@ protected void postCreateArchive() throws ArchiverException {
private void fixLastModifiedTimeZipEntries() throws IOException {
long timeMillis = getLastModifiedTime().toMillis();
Path destFile = getDestFile().toPath();
PosixFileAttributes posixFileAttributes = Files.getFileAttributeView(
destFile, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS)
.readAttributes();
FileAttribute<?>[] attributes;
if (IS_POSIX) {
PosixFileAttributes posixFileAttributes = Files.getFileAttributeView(destFile, PosixFileAttributeView.class)
.readAttributes();
if (posixFileAttributes != null) {
attributes = new FileAttribute<?>[1];
attributes[0] = PosixFilePermissions.asFileAttribute(posixFileAttributes.permissions());
} else {
Expand Down

0 comments on commit b6a1450

Please sign in to comment.