You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by tm...@apache.org on 2021/07/12 19:22:51 UTC

[sling-org-apache-sling-distribution-journal] branch SLING-10598 created (now 072e8da)

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

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


      at 072e8da  SLING-10598 - Content package extractor avoid fetching nodes outside the base path

This branch includes the following new commits:

     new 072e8da  SLING-10598 - Content package extractor avoid fetching nodes outside the base path

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-org-apache-sling-distribution-journal] 01/01: SLING-10598 - Content package extractor avoid fetching nodes outside the base path

Posted by tm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 072e8da50184ac9b3dab50343fd93dc4b7148d58
Author: tmaret <tm...@adobe.com>
AuthorDate: Mon Jul 12 21:22:26 2021 +0200

    SLING-10598 - Content package extractor avoid fetching nodes outside the base path
---
 .../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 {