kwin commented on code in PR #362: URL: https://github.com/apache/jackrabbit-filevault/pull/362#discussion_r1991940097
########## 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)) { + // get filter root after matching path (will exclude leading "/" + String rel = rootMatch.substring(pathMatch.length()); + + // truncate before first "/" + int slashPos = rel.indexOf('/'); + if (slashPos >= 0) { + rel = rel.substring(0, slashPos); + } + + result = rel.isEmpty() ? null : rel; + } + + log.debug("getChildNameBelowRoot(root={}, path={}) -> {}", rootMatch, pathMatch, result); Review Comment: This is inconsistent with the current name of the method. ########## vault-core-it/vault-core-integration-tests/src/main/java/org/apache/jackrabbit/vault/packaging/integration/ManySiblingsIT.java: ########## @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jackrabbit.vault.packaging.integration; + +import org.apache.jackrabbit.oak.commons.junit.LogCustomizer; +import org.apache.jackrabbit.vault.fs.api.PathFilterSet; +import org.apache.jackrabbit.vault.fs.config.DefaultMetaInf; +import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter; +import org.apache.jackrabbit.vault.fs.impl.AggregateImpl; +import org.apache.jackrabbit.vault.packaging.ExportOptions; +import org.apache.jackrabbit.vault.packaging.VaultPackage; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.event.Level; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.nodetype.NodeType; +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +public class ManySiblingsIT extends IntegrationTestBase { + + @BeforeClass + public static void initRepository() throws RepositoryException, IOException { + initRepository(true, false); // always use BlobStore with Oak + } + + // JCRVLT-789 + @Test + public void testManySiblings() throws RepositoryException, IOException { Review Comment: I think some more tests with filters above or outside the path with the many children should be added (or this one being extended). ########## 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. Review Comment: I think what was meant was rather `Checks if the given path is an ancestor of the filter's root path`. A (string) path is given, not a JCR item! ########## 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: no need for normalization, just use https://jackrabbit.apache.org/api/2.18/org/apache/jackrabbit/util/Text.html#isDescendantOrEqual-java.lang.String-java.lang.String- ########## vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/WorkspaceFilter.java: ########## @@ -102,6 +103,19 @@ public interface WorkspaceFilter extends Dumpable { */ boolean isAncestor(@NotNull String path); + /** + * Matches the given path with all filter roots. For each, if it is an ancestor, + * add the name of the first path segment of the remaining filter root "below" path + * to the result set. + * + * @param path Path to check + * @return first path segments of non-matched paths, or {@code null} when result set Review Comment: For me there is three conditions: 1. all filter roots are below given path 2. a filter root is not related (i.e. neither ancestor nor descendent) 3. a filter root is an ancestor of this path Are you sure that both 2. and 3. should lead to the same return value `null`? -- 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