From 1cf01544d8bed575829a170a9eaf0ee60f3814d7 Mon Sep 17 00:00:00 2001 From: Gary Spencer Date: Tue, 28 Apr 2009 15:46:56 +0000 Subject: [PATCH] Merge 3.1 to HEAD: 14099 Repository filesystem handles file sharing mode options on file create/open calls. ETHREEOH-1954 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14108 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../filesys/repo/ContentDiskDriver.java | 119 +++++++++++++----- .../org/alfresco/filesys/state/FileState.java | 5 +- 2 files changed, 93 insertions(+), 31 deletions(-) diff --git a/source/java/org/alfresco/filesys/repo/ContentDiskDriver.java b/source/java/org/alfresco/filesys/repo/ContentDiskDriver.java index 0528532da4..aeee7aa0a3 100644 --- a/source/java/org/alfresco/filesys/repo/ContentDiskDriver.java +++ b/source/java/org/alfresco/filesys/repo/ContentDiskDriver.java @@ -1360,11 +1360,44 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa if ( fstate.exists() == false) throw new FileNotFoundException(); - // Check if the open request shared access indicates exclusive file access + // Check the file sharing mode - if ( fstate != null && params.getSharedAccess() == SharingMode.NOSHARING && - fstate.getOpenCount() > 0) - throw new FileSharingException("File already open, " + params.getPath()); + if ( fstate != null) { + + // Check if the current file open allows the required shared access + + boolean nosharing = false; + + if ( fstate.getOpenCount() > 0) { + + // Check if the file has been opened for exclusive access + + if ( fstate.getSharedAccess() == SharingMode.NOSHARING) + nosharing = true; + + // Check if the required sharing mode is allowed by the current file open + + else if ( ( fstate.getSharedAccess() & params.getSharedAccess()) != params.getSharedAccess()) + nosharing = true; + + // Check if the caller wants exclusive access to the file + + else if ( params.getSharedAccess() == SharingMode.NOSHARING) + nosharing = true; + } + + // Check if the file allows shared access + + if ( nosharing == true) + { + if ( params.getPath().equals( "\\") == false) + throw new FileSharingException("File already open, " + params.getPath()); + } + + // Update the file sharing mode, if this is the first file open + + fstate.setSharedAccess( params.getSharedAccess()); + } } } @@ -1588,6 +1621,10 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa FileState fstate = ctx.getStateTable().findFileState(params.getPath(), false, true); if ( fstate != null) { + // Save the file sharing mode, needs to be done before the open count is incremented + + fstate.setSharedAccess( params.getSharedAccess()); + // Indicate that the file is open fstate.setFileStatus(FileStateStatus.FileExists); @@ -1869,8 +1906,13 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa if ( ctx.hasStateTable()) { FileState fstate = ctx.getStateTable().findFileState(file.getFullName()); - if ( fstate != null) - fstate.decrementOpenCount(); + if ( fstate != null) { + + // If the file open count is now zero then reset the stored sharing mode + + if ( fstate.decrementOpenCount() == 0) + fstate.setSharedAccess( SharingMode.READWRITE + SharingMode.DELETE); + } } // Defer to the network file to close the stream and remove the content @@ -2088,32 +2130,37 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa if ( renState.getFileStatus() == FileStateStatus.Renamed) { - // DEBUG - - if ( logger.isDebugEnabled()) - logger.debug(" Found rename state, relinking, " + renState); - - // Relink the new version of the file data to the previously renamed node so that it - // picks up version history and other settings. - - cifsHelper.relinkNode( renState.getNodeRef(), nodeToMoveRef, targetFolderRef, name); - relinked = true; - - // Link the node ref for the associated rename state - - if ( renState.hasRenameState()) - renState.getRenameState().setNodeRef(nodeToMoveRef); - - // Remove the file state for the old file name + // Check if the renamed node still exists + + if ( nodeService.exists( renState.getNodeRef())) + { + // DEBUG + + if ( logger.isDebugEnabled()) + logger.debug(" Found rename state, relinking, " + renState); + + // Relink the new version of the file data to the previously renamed node so that it + // picks up version history and other settings. + + cifsHelper.relinkNode( renState.getNodeRef(), nodeToMoveRef, targetFolderRef, name); + relinked = true; + + // Link the node ref for the associated rename state + + if ( renState.hasRenameState()) + renState.getRenameState().setNodeRef(nodeToMoveRef); + + // Get, or create, a file state for the new file path + + FileState fstate = ctx.getStateTable().findFileState(newName, false, true); + + fstate.setNodeRef(renState.getNodeRef()); + fstate.setFileStatus(FileStateStatus.FileExists); + } + + // Remove the file state for the old file name ctx.getStateTable().removeFileState(oldName); - - // Get, or create, a file state for the new file path - - FileState fstate = ctx.getStateTable().findFileState(newName, false, true); - - fstate.setNodeRef(renState.getNodeRef()); - fstate.setFileStatus(FileStateStatus.FileExists); } else if ( renState.getFileStatus() == FileStateStatus.DeleteOnClose) { @@ -2410,6 +2457,18 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa throw new AccessDeniedException("Node locked, cannot mark for delete"); } + // Check if a folder is being marked for delete + + // Get the node for the folder + + if (fileFolderService.exists(nodeRef)) + { + // Check if the folder is empty + + if ( cifsHelper.isFolderEmpty( nodeRef) == false) + throw new DirectoryNotEmptyException( name); + } + // Update the change date/time if ( fstate != null) diff --git a/source/java/org/alfresco/filesys/state/FileState.java b/source/java/org/alfresco/filesys/state/FileState.java index be759f5dd4..76facf3b61 100644 --- a/source/java/org/alfresco/filesys/state/FileState.java +++ b/source/java/org/alfresco/filesys/state/FileState.java @@ -77,7 +77,7 @@ public class FileState // Sharing mode - private int m_sharedAccess = SharingMode.READWRITE; + private int m_sharedAccess = SharingMode.READWRITE + SharingMode.DELETE; // File lock list, allocated once there are active locks on this file @@ -716,6 +716,9 @@ public class FileState else str.append("Null"); + str.append(",Shr=0x"); + str.append(Integer.toHexString(getSharedAccess())); + if ( isDirectory()) { str.append(",Pseudo=");