From 988ad9ccec387af958ec25d04ad4795de1879484 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Thu, 17 Sep 2020 12:02:36 +0200 Subject: [PATCH] Fix JCR file system rename for compatibility with mounts. --- .../argeo/jcr/fs/JcrFileSystemProvider.java | 27 +++++++++--- .../org/argeo/jcr/fs/WorkspaceFileStore.java | 42 +++++++++++++++++++ 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java b/org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java index 7a38ba370..74d9a198e 100644 --- a/org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java +++ b/org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java @@ -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 diff --git a/org.argeo.jcr/src/org/argeo/jcr/fs/WorkspaceFileStore.java b/org.argeo.jcr/src/org/argeo/jcr/fs/WorkspaceFileStore.java index 0b81d5569..6d9d05c2a 100644 --- a/org.argeo.jcr/src/org/argeo/jcr/fs/WorkspaceFileStore.java +++ b/org.argeo.jcr/src/org/argeo/jcr/fs/WorkspaceFileStore.java @@ -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; + } + } -- 2.30.2