diff --git a/source/java/org/alfresco/repo/avm/AVMRepository.java b/source/java/org/alfresco/repo/avm/AVMRepository.java index 7776e61db2..51d94777b9 100644 --- a/source/java/org/alfresco/repo/avm/AVMRepository.java +++ b/source/java/org/alfresco/repo/avm/AVMRepository.java @@ -136,6 +136,43 @@ public class AVMRepository rep.createDirectory(pathParts[1], name); } + /** + * Create a new directory. This assumes that the parent is already + * copied and therefore should only be used with great care. + * @param parent The parent node. + * @param name The name of the new directory. + * @return A descriptor for the newly created directory. + */ + public AVMNodeDescriptor createDirectory(AVMNodeDescriptor parent, String name) + { + AVMNode node = AVMContext.fgInstance.fAVMNodeDAO.getByID(parent.getId()); + if (node == null) + { + throw new AVMNotFoundException(parent.getId() + " not found."); + } + if (!(node instanceof DirectoryNode)) + { + throw new AVMWrongTypeException("Not a directory."); + } + // We need the store to do anything so... + String [] pathParts = SplitPath(parent.getPath()); + AVMStore store = getAVMStoreByName(pathParts[0]); + DirectoryNode dir = (DirectoryNode)node; + DirectoryNode child = null; + if (dir instanceof LayeredDirectoryNode) + { + child = new LayeredDirectoryNodeImpl((String)null, store); + ((LayeredDirectoryNode)child).setPrimaryIndirection(false); + ((LayeredDirectoryNode)child).setLayerID(parent.getLayerID()); + } + else + { + child = new PlainDirectoryNodeImpl(store); + } + dir.putChild(name, child); + return child.getDescriptor(parent.getPath(), name, parent.getIndirection()); + } + /** * Create a new layered directory. * @param srcPath The target indirection for the new layered directory. @@ -1311,12 +1348,14 @@ public class AVMRepository * Force a copy on write. * @param path The path to force. */ - public void forceCopy(String path) + public AVMNodeDescriptor forceCopy(String path) { fLookupCount.set(1); String [] pathParts = SplitPath(path); AVMStore store = getAVMStoreByName(pathParts[0]); // Just force a copy if needed by looking up in write mode. - store.lookup(-1, pathParts[1], true, false); + Lookup lPath = store.lookup(-1, pathParts[1], true, false); + AVMNode node = lPath.getCurrentNode(); + return node.getDescriptor(lPath); } } diff --git a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java index 09df3b0f0b..2f50eb4921 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceImpl.java @@ -307,6 +307,22 @@ public class AVMServiceImpl implements AVMService fAVMRepository.createDirectory(path, name); } + /** + * Create a new directory, in an already copy on written node. + * This should only be used if you really know what you're doing. + * @param parent The parent node. + * @param name The name of the new directory. + * @return A descriptor for the newly created directory. + */ + public AVMNodeDescriptor createDirectory(AVMNodeDescriptor parent, String name) + { + if (parent == null || name == null) + { + throw new AVMBadArgumentException("Illegal null argument."); + } + return fAVMRepository.createDirectory(parent, name); + } + /** * Create a new layered file. It must not exist. * @param srcPath The src path. Ie the target for the layering. @@ -1106,12 +1122,12 @@ public class AVMServiceImpl implements AVMService * Force copy on write of a path. * @param path The path to force. */ - public void forceCopy(String path) + public AVMNodeDescriptor forceCopy(String path) { if (path == null) { throw new AVMBadArgumentException("Null Path."); } - fAVMRepository.forceCopy(path); + return fAVMRepository.forceCopy(path); } } diff --git a/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java b/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java index 21cad20548..863cf6d8c7 100644 --- a/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java @@ -29,6 +29,7 @@ import org.alfresco.service.cmr.avm.AVMWrongTypeException; import org.alfresco.service.cmr.avmsync.AVMDifference; import org.alfresco.service.cmr.avmsync.AVMSyncException; import org.alfresco.service.cmr.avmsync.AVMSyncService; +import org.apache.log4j.Logger; /** * This implements APIs that allow comparison and synchronization @@ -38,6 +39,8 @@ import org.alfresco.service.cmr.avmsync.AVMSyncService; */ public class AVMSyncServiceImpl implements AVMSyncService { + private static Logger fgLogger = Logger.getLogger(AVMSyncServiceImpl.class); + /** * The AVMService. */ @@ -419,12 +422,13 @@ public class AVMSyncServiceImpl implements AVMSyncService } // Otherwise make a directory in the target parent, and recursiveCopy all the source // children into it. - fAVMService.createDirectory(parent.getPath(), name); - AVMNodeDescriptor newParentDesc = fAVMService.lookup(parent, name); + AVMNodeDescriptor newParentDesc = fAVMService.createDirectory(parent, name); + fgLogger.error(newParentDesc); Map children = fAVMService.getDirectoryListing(toCopy, true); for (Map.Entry entry : children.entrySet()) { + fgLogger.error(entry.getKey()); recursiveCopy(newParentDesc, entry.getKey(), entry.getValue()); } } @@ -593,8 +597,7 @@ public class AVMSyncServiceImpl implements AVMSyncService { return true; } - fAVMService.forceCopy(layer.getPath()); - layer = fAVMService.lookup(-1, layer.getPath()); + layer = fAVMService.forceCopy(layer.getPath()); // Grab the listing Map underListing = fAVMService.getDirectoryListing(underlying, true); diff --git a/source/java/org/alfresco/service/cmr/avm/AVMService.java b/source/java/org/alfresco/service/cmr/avm/AVMService.java index ada6e1c808..dac0db83a1 100644 --- a/source/java/org/alfresco/service/cmr/avm/AVMService.java +++ b/source/java/org/alfresco/service/cmr/avm/AVMService.java @@ -192,6 +192,15 @@ public interface AVMService */ public void createDirectory(String path, String name); + /** + * Create a new directory, in an already copy on written node. + * This should only be used if you really know what you're doing. + * @param parent The parent node. + * @param name The name of the new directory. + * @return A descriptor for the newly created directory. + */ + public AVMNodeDescriptor createDirectory(AVMNodeDescriptor parent, String name); + /** * Create a new layered file. * @param targetPath The simple absolute path that the new file will point at. @@ -712,5 +721,5 @@ public interface AVMService * Force copy on write of a path. * @param path The path to force. */ - public void forceCopy(String path); + public AVMNodeDescriptor forceCopy(String path); }