Skip to content
Merged
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
Expand Up @@ -256,6 +256,15 @@ private FileAccessTree(FilesEntitlement filesEntitlement, PathLookup pathLookup,
this.exclusivePaths = sortedExclusivePaths;
this.readPaths = pruneSortedPaths(readPaths).toArray(new String[0]);
this.writePaths = pruneSortedPaths(writePaths).toArray(new String[0]);

logger.debug(
() -> Strings.format(
"Created FileAccessTree with paths: exclusive [%s], read [%s], write [%s]",
String.join(",", this.exclusivePaths),
String.join(",", this.readPaths),
String.join(",", this.writePaths)
)
);
}

// package private for testing
Expand Down Expand Up @@ -303,11 +312,17 @@ public static FileAccessTree withoutExclusivePaths(
}

public boolean canRead(Path path) {
return checkPath(normalizePath(path), readPaths);
var normalizedPath = normalizePath(path);
var canRead = checkPath(normalizedPath, readPaths);
logger.trace(() -> Strings.format("checking [%s] (normalized to [%s]) for read: %b", path, normalizedPath, canRead));
return canRead;
}

public boolean canWrite(Path path) {
return checkPath(normalizePath(path), writePaths);
var normalizedPath = normalizePath(path);
var canWrite = checkPath(normalizedPath, writePaths);
logger.trace(() -> Strings.format("checking [%s] (normalized to [%s]) for write: %b", path, normalizedPath, canWrite));
return canWrite;
}

/**
Expand All @@ -325,7 +340,6 @@ static String normalizePath(Path path) {
}

private boolean checkPath(String path, String[] paths) {
logger.trace(() -> Strings.format("checking [%s] against [%s]", path, String.join(",", paths)));
if (paths.length == 0) {
return false;
}
Expand All @@ -343,8 +357,9 @@ private boolean checkPath(String path, String[] paths) {
}

private static boolean isParent(String maybeParent, String path) {
logger.trace(() -> Strings.format("checking isParent [%s] for [%s]", maybeParent, path));
return path.startsWith(maybeParent) && path.startsWith(FILE_SEPARATOR, maybeParent.length());
var isParent = path.startsWith(maybeParent) && path.startsWith(FILE_SEPARATOR, maybeParent.length());
logger.trace(() -> Strings.format("checking isParent [%s] for [%s]: %b", maybeParent, path, isParent));
return isParent;
}

@Override
Expand Down