This is an automated email from the ASF dual-hosted git repository.

tmaret pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git


The following commit(s) were added to refs/heads/master by this push:
     new 0e1688c  SLING-10598 - Content package extractor avoid fetching nodes 
outside the base path (#81)
0e1688c is described below

commit 0e1688cd98aa0865e62bb70e00921836f2ca8369
Author: Timothee Maret <[email protected]>
AuthorDate: Tue Jul 13 09:23:04 2021 +0200

    SLING-10598 - Content package extractor avoid fetching nodes outside the 
base path (#81)
---
 .../bookkeeper/ContentPackageExtractor.java        | 36 ++++++++++++++--------
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/distribution/journal/bookkeeper/ContentPackageExtractor.java
 
b/src/main/java/org/apache/sling/distribution/journal/bookkeeper/ContentPackageExtractor.java
index 860fb19..1ec394c 100644
--- 
a/src/main/java/org/apache/sling/distribution/journal/bookkeeper/ContentPackageExtractor.java
+++ 
b/src/main/java/org/apache/sling/distribution/journal/bookkeeper/ContentPackageExtractor.java
@@ -64,24 +64,34 @@ class ContentPackageExtractor {
         }
         log.debug("Scanning imported nodes for packages to install.");
         for (String path : paths) {
-            try {
-                Resource resource = resourceResolver.getResource(path);
-                if (resource != null) {
-                    Node node = resource.adaptTo(Node.class);
-                    if (isContentPackage(path, node)) {
-                        installPackage(path, node);
-                    }
-                } else {
-                    log.warn("Imported node {} does not exist. Skipping.", 
path);
+            if (isContentPackagePath(path)) {
+                handlePath(resourceResolver,path);
+            }
+        }
+    }
+
+    private void handlePath(ResourceResolver resourceResolver, String path) 
throws DistributionException {
+        try {
+            Resource resource = resourceResolver.getResource(path);
+            if (resource != null) {
+                Node node = resource.adaptTo(Node.class);
+                if (isContentPackage(node)) {
+                    installPackage(path, node);
                 }
-            } catch (Exception e) {
-                throw new DistributionException("Error trying to extract 
package at path " + path, e);
+            } else {
+                log.warn("Imported node {} does not exist. Skipping.", path);
             }
+        } catch (Exception e) {
+            throw new DistributionException("Error trying to extract package 
at path " + path, e);
         }
     }
 
-    private boolean isContentPackage(String path, Node node) throws 
RepositoryException {
-        return path.startsWith(PACKAGE_BASE_PATH) && 
node.isNodeType(NodeType.NT_FILE);
+    private boolean isContentPackagePath(String path) {
+        return path != null && path.startsWith(PACKAGE_BASE_PATH);
+    }
+
+    private boolean isContentPackage(Node node) throws RepositoryException {
+        return node!= null && node.isNodeType(NodeType.NT_FILE);
     }
 
     private void installPackage(String path, Node node) throws 
RepositoryException, PackageException, IOException {

Reply via email to