Author: rombert
Date: Tue Sep 29 21:59:28 2015
New Revision: 1705937

URL: http://svn.apache.org/viewvc?rev=1705937&view=rev
Log:
SLING-4458 - Resources not matching the filter can be deleted when
updating a node

Consult the Filter when deleting nodes in the AddOrUpdateNodeCommand

Modified:
    
sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommandTest.java
    
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java

Modified: 
sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommandTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommandTest.java?rev=1705937&r1=1705936&r2=1705937&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommandTest.java
 (original)
+++ 
sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommandTest.java
 Tue Sep 29 21:59:28 2015
@@ -220,6 +220,47 @@ public class AddOrUpdateNodeCommandTest
             }
         });
     }
+    
+    @Test
+    public void nodeNotPresentButOutsideOfFilterIsNotRemoved() throws 
Exception {
+
+        final CommandContext context = new CommandContext(new Filter() {
+            
+            @Override
+            public FilterResult filter(String repositoryPath) {
+                if ( repositoryPath.equals("/content/not-included-child")) {
+                    return FilterResult.DENY;
+                }
+                
+                return FilterResult.ALLOW;
+            }
+        });
+        
+        doWithTransientRepository(new CallableWithSession() {
+            @Override
+            public Void call() throws Exception {
+                Node content = session().getRootNode().addNode("content", 
"nt:unstructured");
+                content.addNode("included-child");
+                content.addNode("not-included-child");
+                
+                session().save();
+
+                ResourceProxy resource = newResource("/content", 
"nt:unstructured");
+                resource.addChild(newResource("/content/included-child", 
"nt:unstructured"));
+
+                AddOrUpdateNodeCommand cmd = new 
AddOrUpdateNodeCommand(repo(), credentials(), context, null, resource, logger);
+                cmd.execute().get();
+
+                session().refresh(false);
+
+                content = session().getRootNode().getNode("content");
+                content.getNode("included-child");
+                content.getNode("not-included-child");
+                return null;
+            }
+        });
+        
+    }
 
     private ResourceProxy newResource(String path, String primaryType) {
 

Modified: 
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java?rev=1705937&r1=1705936&r2=1705937&view=diff
==============================================================================
--- 
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java
 (original)
+++ 
sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java
 Tue Sep 29 21:59:28 2015
@@ -143,6 +143,12 @@ public class AddOrUpdateNodeCommand exte
                 }
                 continue;
             }
+
+            if ( context.filter() != null 
+                    && context.filter(). filter(child.getPath()) == 
FilterResult.DENY ) {
+                getLogger().trace("Not deleting node at {0} since it is not 
included in the filter", child.getPath());
+                continue;
+            }
             
             getLogger()
                     .trace("Deleting node {0} as it is no longer present in 
the local checkout", child.getPath());


Reply via email to