Skip to content

Commit

Permalink
Fix erroneous identity comparison in UnionFileSystem#newDirStream a…
Browse files Browse the repository at this point in the history
…nd remove redundant checks (#1)
  • Loading branch information
PaintNinja authored Mar 15, 2024
1 parent 80b4a40 commit e41b2d5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
17 changes: 6 additions & 11 deletions src/main/java/cpw/mods/niofs/union/UnionFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public synchronized Throwable fillInStackTrace() {
}
}
private final UnionPath root = new UnionPath(this, "/");
private final UnionPath notExistingPath = new UnionPath(this, "/SNOWMAN");
private final UnionFileSystemProvider provider;
private final String key;
private final List<Path> basepaths;
Expand Down Expand Up @@ -254,7 +253,7 @@ private static boolean zipFsExists(UnionFileSystem ufs, Path path) {
private Optional<Path> findFirstFiltered(final UnionPath path) {
for (Path p : this.basepaths) {
Path realPath = toRealPath(p, path);
if (realPath != notExistingPath && testFilter(realPath, p)) {
if (testFilter(realPath, p)) {
if (realPath.getFileSystem() == FileSystems.getDefault()) {
if (realPath.toFile().exists()) {
return Optional.of(realPath);
Expand All @@ -278,11 +277,9 @@ public <A extends BasicFileAttributes> A readAttributes(final UnionPath path, fi
for (Path base : this.basepaths) {
// We need to know the full path for the filter
Path realPath = toRealPath(base, path);
if (realPath != notExistingPath) {
Optional<BasicFileAttributes> fileAttributes = this.getFileAttributes(realPath);
if (fileAttributes.isPresent() && testFilter(realPath, base)) {
return (A) fileAttributes.get();
}
Optional<BasicFileAttributes> fileAttributes = this.getFileAttributes(realPath);
if (fileAttributes.isPresent() && testFilter(realPath, base)) {
return (A) fileAttributes.get();
}
}
throw new NoSuchFileException(path.toString());
Expand Down Expand Up @@ -346,11 +343,9 @@ public DirectoryStream<Path> newDirStream(final UnionPath path, final DirectoryS
final var allpaths = new LinkedHashSet<Path>();
for (final var bp : basepaths) {
final var dir = toRealPath(bp, path);
if (dir == notExistingPath) {
continue;
} else if (dir.getFileSystem() == FileSystems.getDefault() && !dir.toFile().exists()) {
if (dir.getFileSystem() == FileSystems.getDefault() && !dir.toFile().exists()) {
continue;
} else if (dir.getFileSystem().provider().getScheme() == "jar" && !zipFsExists(this, dir)) {
} else if (dir.getFileSystem().provider().getScheme().equals("jar") && !zipFsExists(this, dir)) {
continue;
} else if (Files.notExists(dir)) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cpw/mods/niofs/union/UnionPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ public Path resolve(final Path other) {
public Path relativize(final Path other) {
if (other.getFileSystem()!=this.getFileSystem()) throw new IllegalArgumentException("Wrong filesystem");
if (other instanceof UnionPath p) {
if (this.absolute != p.absolute) {
//if (this.absolute != p.absolute) {
// Should not be allowed but union fs relies on it
// also there is no such concept of a current directory for union paths
// meaning absolute and relative paths should have the same effect,
// so we just allow this.
//throw new IllegalArgumentException("Different types of path");
}
//}
var length = Math.min(this.pathParts.length, p.pathParts.length);
int i = 0;
while (i < length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public Enumeration<URL> getResources(String name) throws IOException {
// TODO: [SM] If our parent is null we should look a the bootstrap classloader, but that requires calling super, which will duplicate resources

return new Enumeration<>() {
private Enumeration<Enumeration<URL>> itr = Collections.enumeration(results);
private final Enumeration<Enumeration<URL>> itr = Collections.enumeration(results);
private Enumeration<URL> current = findNext();

private Enumeration<URL> findNext() {
Expand Down Expand Up @@ -598,7 +598,7 @@ private ModuleReader getModuleReader(ModuleReference reference) {
});
}

private static ModuleReader NOOP_READER = new ModuleReader() {
private static final ModuleReader NOOP_READER = new ModuleReader() {
@Override
public Optional<URI> find(String name) throws IOException {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,7 @@ public CodeSigner[] getCodeSigners(String entry, byte[] data) {
}
}

private static class Reader implements ModuleReader {
private final SecureJar.ModuleDataProvider jar;

public Reader(final SecureJar.ModuleDataProvider jar) {
this.jar = jar;
}

private record Reader(SecureJar.ModuleDataProvider jar) implements ModuleReader {
@Override
public Optional<URI> find(final String name) throws IOException {
return jar.findFile(name);
Expand Down

0 comments on commit e41b2d5

Please sign in to comment.