You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2024/08/08 14:33:47 UTC

(jackrabbit-filevault) 01/01: JCRVLT-767: vlt: potential incorrect identifier comparison (work in progress)

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

reschke pushed a commit to branch JCRVLT-767
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git

commit 100024ccede3084564ebdbf89cdf8894168ed91a
Author: Julian Reschke <re...@apache.org>
AuthorDate: Thu Aug 8 15:33:34 2024 +0100

    JCRVLT-767: vlt: potential incorrect identifier comparison (work in progress)
---
 .../vault/fs/impl/io/DocViewImporter.java          | 43 +++++++++++++++++++++-
 1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java
index 3572276b..814c5a58 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java
@@ -989,8 +989,17 @@ public class DocViewImporter implements DocViewParserHandler {
         VersioningState vs = new VersioningState(stack, node);
         Node updatedNode = null;
         Optional<String> identifier = ni.getIdentifier();
+
+        String nodeUUID = null;
+        try {
+            nodeUUID = node.getUUID();
+        } catch (RepositoryException ex) {
+            // node not referenceable
+        }
+
         // try to set uuid via sysview import if it differs from existing one
-        if (identifier.isPresent() && !node.getIdentifier().equals(identifier.get()) && !"rep:root".equals(ni.getPrimaryType().orElse(""))) {
+        if (identifier.isPresent() && nodeUUID != null && !nodeUUID.equals(identifier.get())
+                && !"rep:root".equals(ni.getPrimaryType().orElse(""))) {
             long startTime = System.currentTimeMillis();
             String previousIdentifier = node.getIdentifier();
             log.debug("Node stashing for {} starting, existing identifier: {}, new identifier: {}, import mode: {}",
@@ -1047,8 +1056,38 @@ public class DocViewImporter implements DocViewParserHandler {
                 }
                 // add remaining mixins (for all import modes)
                 for (String mixin : newMixins) {
+                    Property uuidProp = null;
                     vs.ensureCheckedOut();
-                    node.addMixin(mixin);
+
+                    if (mixin.equals("mix:referenceable") && identifier.isPresent()) {
+                        // if this is mix:ref and ni specifies an identifier,
+                        // try to set it
+                        try {
+                            uuidProp = node.setProperty(Property.JCR_UUID, identifier.get());
+                        } catch (RepositoryException ex) {
+                            log.debug("tried to set jcr:uuid to {} before adding mix:referenceable failed, continuing", ex);
+                        }
+
+                        try {
+                            node.addMixin(mixin);
+                        } catch (RepositoryException ex) {
+                            // try to add the mixin; this fails with classic
+                            // jackrabbit, so undo the change for jcr:uuid and retry
+                            if (uuidProp != null) {
+                                log.debug(
+                                        "failed to add mix:referenceable after setting jcr:uuid, retrying without (uuid will be lost)",
+                                        ex);
+                                // retry once after removing jcr:uuid
+                                uuidProp.remove();
+                                node.addMixin(mixin);
+                            } else {
+                                throw ex;
+                            }
+                        }
+                    } else {
+                        node.addMixin(mixin);
+                    }
+
                     updatedNode = node;
                 }
             }