reschke commented on code in PR #362: URL: https://github.com/apache/jackrabbit-filevault/pull/362#discussion_r1992105659
########## vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java: ########## @@ -239,12 +243,45 @@ public boolean covers(@NotNull String path) { } /** - * Checks if the given item is an ancestor of the root node. + * Checks if the given item is an ancestor of the filter's root path. * @param path path of the item to check * @return {@code true} if the given item is an ancestor */ public boolean isAncestor(@NotNull String path) { - return path.equals(root) || root.startsWith(path + "/") || "/".equals(path); + boolean isAncestor = path.equals(root) || path.equals("/") || root.startsWith(path + "/"); + log.debug("isAncestor(root={}, path={}) -> {}", root, path, isAncestor); + return isAncestor; + } + + /** + * Matches the given path with this filter's root. If it is an ancestor, returns the name of the first + * path segment of the remaining filter root "below" path. + * + * @param path Path to check + * @return first path segment of non-matched path, or {@code null} when path not ancestor + */ + public @Nullable String getDirectChildNameTowardsFilterRoot(@NotNull String path) { + String result = null; + + String rootMatch = appendSlashIfNeeded(root); + String pathMatch = appendSlashIfNeeded(path); + + if (rootMatch.startsWith(pathMatch)) { Review Comment: Well, we can avoid those for the comparison (which internally normalizes), but we'd need it anyway for the string operations below. It would be nice to have something like "getDescendantRelativeTo", but right now it's not there (could be inspired by nio Path https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html#relativize-java.nio.file.Path-. ########## vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java: ########## @@ -239,12 +243,45 @@ public boolean covers(@NotNull String path) { } /** - * Checks if the given item is an ancestor of the root node. + * Checks if the given item is an ancestor of the filter's root path. * @param path path of the item to check * @return {@code true} if the given item is an ancestor */ public boolean isAncestor(@NotNull String path) { - return path.equals(root) || root.startsWith(path + "/") || "/".equals(path); + boolean isAncestor = path.equals(root) || path.equals("/") || root.startsWith(path + "/"); + log.debug("isAncestor(root={}, path={}) -> {}", root, path, isAncestor); + return isAncestor; + } + + /** + * Matches the given path with this filter's root. If it is an ancestor, returns the name of the first + * path segment of the remaining filter root "below" path. + * + * @param path Path to check + * @return first path segment of non-matched path, or {@code null} when path not ancestor + */ + public @Nullable String getDirectChildNameTowardsFilterRoot(@NotNull String path) { + String result = null; + + String rootMatch = appendSlashIfNeeded(root); + String pathMatch = appendSlashIfNeeded(path); + + if (rootMatch.startsWith(pathMatch)) { Review Comment: Well, we can avoid those for the comparison (which internally normalizes), but we'd need it anyway for the string operations below. It would be nice to have something like "getDescendantRelativeTo", but right now it's not there (could be inspired by nio Path https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html#relativize-java.nio.file.Path-). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org