Skip to content
Open
Show file tree
Hide file tree
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
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2026 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package jdk.internal.access;

import java.nio.file.Path;

/**
* SharedSecrets interface used for the access from java.text.Bidi
*/

public interface JdkNioZipfsAccess {

// java.awt.font.TextAttribute constants
public boolean isSymbolicLink(Path path);
}
12 changes: 12 additions & 0 deletions src/java.base/share/classes/jdk/internal/access/SharedSecrets.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public class SharedSecrets {
@Stable private static JavaxCryptoSealedObjectAccess javaxCryptoSealedObjectAccess;
@Stable private static JavaxCryptoSpecAccess javaxCryptoSpecAccess;
@Stable private static JavaxSecurityAccess javaxSecurityAccess;
// SapMachine 2026-04-14: Support for symlink detection in zipfs.
@Stable private static JdkNioZipfsAccess jdkNioZipfsAccess;

public static void setJavaUtilCollectionAccess(JavaUtilCollectionAccess juca) {
javaUtilCollectionAccess = juca;
Expand Down Expand Up @@ -537,4 +539,14 @@ private static void ensureClassInitialized(Class<?> c) {
MethodHandles.lookup().ensureInitialized(c);
} catch (IllegalAccessException e) {}
}

// SapMachine 2026-04-14
public static void setJdkNioZipfsAccess(JdkNioZipfsAccess access) {
jdkNioZipfsAccess = access;
}

// SapMachine 2026-04-14
public static JdkNioZipfsAccess getJdkNioZipfsAccess() {
return jdkNioZipfsAccess;
}
}
2 changes: 2 additions & 0 deletions src/java.base/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@
jdk.net,
// SapMachine 2024-06-12: process group extension
jdk.sapext,
// SapMachine 2026-04-13: symlink support for zipfs entries in sapext.
jdk.zipfs,
jdk.sctp,
jdk.crypto.cryptoki;
exports jdk.internal.classfile.components to
Expand Down
54 changes: 54 additions & 0 deletions src/jdk.sapext/share/classes/com/sap/jdk/ext/util/ZipfsUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2026 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sap.jdk.ext.util;

import java.nio.file.Path;

import jdk.internal.access.JdkNioZipfsAccess;
import jdk.internal.access.SharedSecrets;

public class ZipfsUtils {

// Silence warning about implicit ctor.
private ZipfsUtils() {
}

/**
* Returns <code>true</code> if the given path is a {@link jdk.nio.zipfs.ZipPath} which
* represents a symbolic link.
*
* @param path The path in the zipfs.
* @return <code>true</code> if the path represents a symbolic link.
*/
public static boolean isSymbolicLink(Path path) {
JdkNioZipfsAccess access = SharedSecrets.getJdkNioZipfsAccess();

if (access == null) {
return false;
}

return access.isSymbolicLink(path);
}
}
13 changes: 13 additions & 0 deletions src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -3645,4 +3645,17 @@ public boolean equals(Object other) {
oname, 0, oname.length);
}
}

// SapMachine 2026-04-14: Returns true if the resolved path points to a symnbolic link.
boolean isSymlink(byte[] path) {
IndexNode inode = getInode(path);

if ((inode != null) && (inode.pos != -1)) {
long attrEx = ZipConstants.CENATX(cen, inode.pos);

return (attrEx & 0xF0000000L) == 0xA0000000L;
}

return false;
}
}
19 changes: 19 additions & 0 deletions src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ final class ZipPath implements Path {
private volatile int[] offsets;
private int hashcode = 0; // cached hashcode (created lazily)

// SapMachine 2026-04-14: Support for symlink detectiun.
static class JdkNioZipfsAccessImpl implements jdk.internal.access.JdkNioZipfsAccess {
public boolean isSymbolicLink(Path path) {
if (!(path instanceof ZipPath)) {
return false;
}

ZipPath zipPath = (ZipPath) path;
byte[] resolvedPath = zipPath.getResolvedPath();

return zipPath.zfs.isSymlink(resolvedPath);
}
}

// SapMachine 2026-04-14: Support for symlink detectiun.
static {
jdk.internal.access.SharedSecrets.setJdkNioZipfsAccess(new JdkNioZipfsAccessImpl());
}

ZipPath(ZipFileSystem zfs, byte[] path) {
this(zfs, path, false);
}
Expand Down
55 changes: 55 additions & 0 deletions test/jdk/sap/ZipfsUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2026 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

/**
* @test
* @summary Runs the test for com.sap.jdk.ext.util.ZipfsUtils.
*
* @run junit ZipfsUtilsTest
*/

import java.io.File;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.util.Map;

import com.sap.jdk.ext.util.ZipfsUtils;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ZipfsUtilsTest {

@Test
public void basicTest() throws Exception {
File file = new File(System.getProperty("test.src", "."), "zip-with-symlink.zip");
URI uri = new URI("jar", file.toURI().toString(), null);
FileSystem fs = FileSystems.newFileSystem(uri, Map.of());
assertFalse(ZipfsUtils.isSymbolicLink(fs.getPath("file")));
assertTrue(ZipfsUtils.isSymbolicLink(fs.getPath("symlink")));
}
}
Binary file added test/jdk/sap/zip-with-symlink.zip
Binary file not shown.
Loading