Fix JCR file system rename for compatibility with mounts.
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 17 Sep 2020 10:02:36 +0000 (12:02 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 17 Sep 2020 10:02:36 +0000 (12:02 +0200)
org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java
org.argeo.jcr/src/org/argeo/jcr/fs/WorkspaceFileStore.java

index 7a38ba3701d45f071e1f654f1c4145dafc7c0c46..74d9a198e71299e8a08af786494792c74752afb6 100644 (file)
@@ -151,17 +151,32 @@ public abstract class JcrFileSystemProvider extends FileSystemProvider {
 
        @Override
        public void move(Path source, Path target, CopyOption... options) throws IOException {
-               Node sourceNode = toNode(source);
+               JcrFileSystem sourceFileSystem = (JcrFileSystem) source.getFileSystem();
+               WorkspaceFileStore sourceStore = sourceFileSystem.getFileStore(source.toString());
+               WorkspaceFileStore targetStore = sourceFileSystem.getFileStore(target.toString());
                try {
-                       Session session = sourceNode.getSession();
-                       synchronized (session) {
-                               session.move(sourceNode.getPath(), target.toString());
-                               save(session);
+                       if (sourceStore.equals(targetStore)) {
+                               sourceStore.getWorkspace().move(sourceStore.toJcrPath(source.toString()),
+                                               targetStore.toJcrPath(target.toString()));
+                       } else {
+                               // TODO implement it
+                               throw new UnsupportedOperationException("Can only move paths within the same workspace.");
                        }
                } catch (RepositoryException e) {
-                       discardChanges(sourceNode);
                        throw new IOException("Cannot move from " + source + " to " + target, e);
                }
+
+//             Node sourceNode = toNode(source);
+//             try {
+//                     Session session = sourceNode.getSession();
+//                     synchronized (session) {
+//                             session.move(sourceNode.getPath(), target.toString());
+//                             save(session);
+//                     }
+//             } catch (RepositoryException e) {
+//                     discardChanges(sourceNode);
+//                     throw new IOException("Cannot move from " + source + " to " + target, e);
+//             }
        }
 
        @Override
index 0b81d5569058882cfcae2a29db71cc5d0ff5956b..6d9d05c2a4b89da4caaa4b51a8b27d13972302fc 100644 (file)
@@ -17,6 +17,7 @@ import org.argeo.jcr.JcrUtils;
 public class WorkspaceFileStore extends FileStore {
        private final String mountPath;
        private final Workspace workspace;
+       private final String workspaceName;
        private final int mountDepth;
 
        public WorkspaceFileStore(String mountPath, Workspace workspace) {
@@ -34,6 +35,7 @@ public class WorkspaceFileStore extends FileStore {
                        mountDepth = mountPath.split(JcrPath.separator).length - 1;
                }
                this.workspace = workspace;
+               this.workspaceName = workspace.getName();
        }
 
        public void close() {
@@ -115,6 +117,16 @@ public class WorkspaceFileStore extends FileStore {
                return node;
        }
 
+       String toJcrPath(String fsPath) {
+               if (fsPath.length() == 1)
+                       return toJcrPath((String[]) null);// root
+               String[] arr = fsPath.substring(1).split("/");
+//             if (arr.length == 0 || (arr.length == 1 && arr[0].equals("")))
+//                     return toJcrPath((String[]) null);// root
+//             else
+               return toJcrPath(arr);
+       }
+
        private String toJcrPath(String[] path) {
                if (path == null)
                        return "/";
@@ -146,4 +158,34 @@ public class WorkspaceFileStore extends FileStore {
                return sb.toString();
        }
 
+       public String getMountPath() {
+               return mountPath;
+       }
+
+       public String getWorkspaceName() {
+               return workspaceName;
+       }
+
+       public int getMountDepth() {
+               return mountDepth;
+       }
+
+       @Override
+       public int hashCode() {
+               return workspaceName.hashCode();
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (!(obj instanceof WorkspaceFileStore))
+                       return false;
+               WorkspaceFileStore other = (WorkspaceFileStore) obj;
+               return workspaceName.equals(other.workspaceName);
+       }
+
+       @Override
+       public String toString() {
+               return "WorkspaceFileStore " + workspaceName;
+       }
+
 }