Alternative approach for PathResource without zipfs specifics

This commit is contained in:
Joakim Erdfelt 2022-08-09 19:00:02 -05:00
parent 537e35926a
commit 3bed1d2587
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
1 changed files with 12 additions and 14 deletions

View File

@ -50,9 +50,6 @@ public class PathResource extends Resource
{
Path abs = path;
// Boolean to track if Path is a ZipFS based
boolean isZipFs = uri.toASCIIString().startsWith("jar:file:");
/* Catch situation where the Path class has already normalized
* the URI eg. input path "aa./foo.txt"
* from an #resolve(String) is normalized away during
@ -63,12 +60,8 @@ public class PathResource extends Resource
*
* ZipFS has lots of restrictions, you cannot trigger many of the alias behavior
* like we can in Windows or OSX.
*
* In this case, a Path.toUri() of a directory will not return a trailing slash on zipfs
* so skip the URI based evaluation, the other tests below (like isSameName) will still validate
* the remaining alias behaviors we have.
*/
if (!isZipFs && !URIUtil.equalsIgnoreEncodings(uri, path.toUri()))
if (!URIUtil.equalsIgnoreEncodings(uri, cleanUri(path)))
{
try
{
@ -95,8 +88,7 @@ public class PathResource extends Resource
try
{
// Skip symlink tests on zipfs (not supported by zipfs)
if (!isZipFs && Files.isSymbolicLink(path))
if (Files.isSymbolicLink(path))
return path.getParent().resolve(Files.readSymbolicLink(path));
if (Files.exists(path))
@ -216,10 +208,7 @@ public class PathResource extends Resource
try
{
this.path = Paths.get(uri);
String uriString = uri.toString();
if (Files.isDirectory(path) && !uriString.endsWith(URIUtil.SLASH))
uri = URI.create(uriString + URIUtil.SLASH);
this.uri = uri;
this.uri = cleanUri(this.path);
this.alias = checkAliasPath();
}
catch (FileSystemNotFoundException e)
@ -354,6 +343,15 @@ public class PathResource extends Resource
Files.copy(this.path, destination);
}
private static URI cleanUri(Path path)
{
String raw = URIUtil.correctFileURI(path.toUri()).toASCIIString();
if (Files.isDirectory(path) && !raw.endsWith("/"))
raw += '/';
return URI.create(raw);
}
@Override
public String toString()
{