Skip to content

Commit

Permalink
switch to normalize path
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Dec 20, 2024
1 parent e105141 commit 605ef60
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 39 deletions.
8 changes: 8 additions & 0 deletions core/src/main/java/lucee/commons/io/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,12 @@ public static void move(File src, File dest) throws IOException {
}
}

public static String getNormalizedPath(File file) {
return file.toPath().normalize().toString();
}

public static File getNormalizedFile(File file) {
return file.toPath().normalize().toFile();
}

}
26 changes: 13 additions & 13 deletions core/src/main/java/lucee/commons/io/res/type/file/FileResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,29 +130,29 @@ public void copyTo(Resource res, boolean append) throws IOException {

}

public Resource getNormalizedResource() {
return new FileResource(provider, getNormalizedPath());
}

public String getNormalizedPath() {
return toPath().normalize().toString();
}

@Override
public Resource getAbsoluteResource() {
return new FileResource(provider, getAbsolutePath());
}

@Deprecated // use getNormalizedResource instead
@Override
public Resource getCanonicalResource() throws IOException {
return new FileResource(provider, getCanonicalPath());
return new FileResource(provider, getNormalizedPath());
}

@Deprecated // use getNormalizedPath instead
@Override
public String getCanonicalPath() {
try {
// java 12 performance regression LDEV-5218
if (SystemUtil.JAVA_VERSION > SystemUtil.JAVA_VERSION_11 )
return Path.of(getPath()).toAbsolutePath().normalize().toString();
return super.getCanonicalPath();
}
catch (IOException e) {
return getAbsolutePath();
}
catch (java.nio.file.InvalidPathException ipe) {
return getPath();
}
return toPath().normalize().toString();
}

@Override
Expand Down
29 changes: 23 additions & 6 deletions core/src/main/java/lucee/commons/io/res/util/ResourceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,9 @@ else if (path.endsWith("..")) {
* pathname
*
* @throws SecurityException If a required system property value cannot be accessed.
* @deprecated use instead getNormalizedPathEL
*/
@Deprecated
public static String getCanonicalPathEL(Resource res) {
try {
return res.getCanonicalPath();
Expand All @@ -756,7 +758,9 @@ public static String getCanonicalPathEL(Resource res) {
* pathname
*
* @throws SecurityException If a required system property value cannot be accessed.
* @deprecated use instead getNormalizedPathEL
*/
@Deprecated
public static Resource getCanonicalResourceEL(Resource res) {
if (res == null) return res;
try {
Expand All @@ -767,18 +771,31 @@ public static Resource getCanonicalResourceEL(Resource res) {
}
}

public static File getCanonicalFileEL(File file) {
if (file == null) return file;
public static String getNormalizedPathEL(Resource res) {
try {
if (res instanceof FileResource) return ((FileResource) res).getNormalizedPath();
return res.getCanonicalPath();
}
catch (IOException e) {
return res.toString();
}
}

public static Resource getNormalizedResourceEL(Resource res) {
try {
if (SystemUtil.JAVA_VERSION > SystemUtil.JAVA_VERSION_11 )
return file.getAbsoluteFile();
return file.getCanonicalFile();
if (res instanceof FileResource) return ((FileResource) res).getNormalizedResource();
return res.getCanonicalResource();
}
catch (IOException e) {
return file.getAbsoluteFile();
return res.getAbsoluteResource();
}
}

public static File getCanonicalFileEL(File file) {
if (file == null) return file;
return file.toPath().normalize().toFile();
}

/**
* creates a new File
*
Expand Down
14 changes: 2 additions & 12 deletions core/src/main/java/lucee/commons/lang/ClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,7 @@ public static String[] getClassPath(Config config) {
int len = arr.size();
for (int i = 1; i <= len; i++) {
File file = FileUtil.toFile(Caster.toString(arr.get(i, ""), "").trim());
if (file.exists()) try {
pathes.put(file.getCanonicalPath(), "");
}
catch (IOException e) {
LogUtil.warn("class-util", e);
}
pathes.put(FileUtil.getNormalizedPath(file), "");
}
}

Expand Down Expand Up @@ -669,12 +664,7 @@ private static void _getClassPathesFromLoader(URLClassLoader ucl, Map pathes) {

for (int i = 0; i < urls.length; i++) {
File file = FileUtil.toFile(urls[i].getPath());
if (file.exists()) try {
pathes.put(file.getCanonicalPath(), "");
}
catch (IOException e) {
LogUtil.warn("class-util", e);
}
if (file.exists()) pathes.put(FileUtil.getNormalizedPath(file), "");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.io.IOException;
import java.net.InetSocketAddress;

import lucee.commons.io.FileUtil;

/**
* Describes an {@link InetSocketAddress} that actually uses AF_UNIX sockets instead of AF_INET.
*
Expand Down Expand Up @@ -37,7 +39,7 @@ public UNIXSocketAddress(final File socketFile, int port) throws IOException {
if (port != 0) {
NativeUnixSocket.setPort1(this, port);
}
this.socketFile = socketFile.getCanonicalPath();
this.socketFile = FileUtil.getNormalizedPath(socketFile);
}

/**
Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/lucee/runtime/net/http/ReqRspUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.xml.sax.InputSource;

import lucee.commons.io.CharsetUtil;
import lucee.commons.io.FileUtil;
import lucee.commons.io.IOUtil;
import lucee.commons.io.SystemUtil;
import lucee.commons.lang.ExceptionUtil;
Expand Down Expand Up @@ -552,11 +553,7 @@ public static String getRootPath(ServletContext sc) {
if (root == null) throw new RuntimeException("cannot determinate webcontext root, the ServletContext from class [" + sc.getClass().getName()
+ "] is returning null for the method call sc.getRealPath(\"/\"), possibly due to configuration problem.");

try {
root = new File(root).getCanonicalPath();
}
catch (IOException e) {
}
root = FileUtil.getNormalizedPath(new File(root));
rootPathes.put(id, root);
return root;
}
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.2.0.236-SNAPSHOT"/>
<property name="version" value="6.2.0.237-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.2.0.236-SNAPSHOT</version>
<version>6.2.0.237-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 605ef60

Please sign in to comment.