Search in sources :

Example 1 with DirectoryNotEmptyException

use of org.alfresco.jlan.server.filesys.DirectoryNotEmptyException in project alfresco-repository by Alfresco.

the class ContentDiskDriver2 method deleteDirectory.

/**
 * Delete the directory from the filesystem.
 * <p>
 * The directory must be empty in order to be able to delete ity
 *
 * @param session Server session
 * @param tree Tree connection
 * @param dir Directory name.
 * @exception java.io.IOException The exception description.
 */
public void deleteDirectory(SrvSession session, TreeConnection tree, final String dir) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("deleteDirectory: " + dir + ", session:" + session.getUniqueId());
    }
    ContentContext ctx = (ContentContext) tree.getContext();
    final NodeRef deviceRootNodeRef = ctx.getRootNode();
    try {
        // Get the node for the folder
        NodeRef nodeRef = getCifsHelper().getNodeRef(deviceRootNodeRef, dir);
        if (fileFolderService.exists(nodeRef)) {
            // Check if the folder is empty
            if (getCifsHelper().isFolderEmpty(nodeRef)) {
                // Delete the folder node
                fileFolderService.delete(nodeRef);
            } else {
                throw new DirectoryNotEmptyException(dir);
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Deleted directory: directory=" + dir + " node=" + nodeRef);
        }
    // void return
    } catch (FileNotFoundException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Delete directory - file not found, " + dir);
        }
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Delete directory - access denied, " + dir);
        }
        throw new AccessDeniedException("Delete directory, access denied :" + dir);
    } catch (AlfrescoRuntimeException ex) {
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
            logger.debug("Delete directory", ex);
        throw new IOException("Delete directory " + dir, ex);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DirectoryNotEmptyException(org.alfresco.jlan.server.filesys.DirectoryNotEmptyException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException)

Example 2 with DirectoryNotEmptyException

use of org.alfresco.jlan.server.filesys.DirectoryNotEmptyException in project alfresco-repository by Alfresco.

the class ContentDiskDriver method deleteDirectory.

/**
 * Delete the directory from the filesystem.
 *
 * @param sess Server session
 * @param tree Tree connection
 * @param dir Directory name.
 * @exception java.io.IOException The exception description.
 */
public void deleteDirectory(SrvSession sess, TreeConnection tree, final String dir) throws IOException {
    // get the device root
    ContentContext ctx = (ContentContext) tree.getContext();
    final NodeRef deviceRootNodeRef = ctx.getRootNode();
    try {
        NodeRef nodeRef = doInWriteTransaction(sess, new CallableIO<NodeRef>() {

            public NodeRef call() throws IOException {
                // Get the node for the folder
                NodeRef nodeRef = cifsHelper.getNodeRef(deviceRootNodeRef, dir);
                if (fileFolderService.exists(nodeRef)) {
                    if (cifsHelper.isFolderEmpty(nodeRef)) {
                        // Delete the folder node
                        fileFolderService.delete(nodeRef);
                        return nodeRef;
                    } else {
                        throw new DirectoryNotEmptyException(dir);
                    }
                }
                return null;
            }
        });
        if (nodeRef != null && ctx.hasStateCache()) {
            // Remove the file state
            ctx.getStateCache().removeFileState(dir);
            // Update, or create, a parent folder file state
            String[] paths = FileName.splitPath(dir);
            if (paths[0] != null && paths[0].length() > 1) {
                // Get the file state for the parent folder
                FileState parentState = getStateForPath(tree, paths[0]);
                if (parentState == null && ctx.hasStateCache())
                    parentState = ctx.getStateCache().findFileState(paths[0], true);
                // Update the modification timestamp
                parentState.updateModifyDateTime();
            }
        }
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
            logger.debug("Deleted directory: directory=" + dir + " node=" + nodeRef);
    } catch (FileNotFoundException e) {
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
            logger.debug("Delete directory - file not found, " + dir);
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
            logger.debug("Delete directory - access denied, " + dir);
        throw new AccessDeniedException("Delete directory " + dir);
    } catch (RuntimeException ex) {
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
            logger.debug("Delete directory", ex);
        throw new IOException("Delete directory " + dir);
    }
}
Also used : FileState(org.alfresco.jlan.server.filesys.cache.FileState) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) DirectoryNotEmptyException(org.alfresco.jlan.server.filesys.DirectoryNotEmptyException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 3 with DirectoryNotEmptyException

use of org.alfresco.jlan.server.filesys.DirectoryNotEmptyException in project alfresco-repository by Alfresco.

the class ContentDiskDriver2 method setFileInformation.

/**
 * Set file information
 *
 * @param sess SrvSession
 * @param tree TreeConnection
 * @param name String
 * @param info FileInfo
 * @exception IOException
 */
public void setFileInformation(SrvSession sess, final TreeConnection tree, final String name, final FileInfo info) throws IOException {
    // Get the device context
    final ContentContext ctx = (ContentContext) tree.getContext();
    if (logger.isDebugEnabled()) {
        logger.debug("setFileInformation name=" + name + ", info=" + info);
    }
    NetworkFile networkFile = info.getNetworkFile();
    try {
        // Get the file/folder node
        NodeRef nodeRef = getNodeForPath(tree, name);
        if (permissionService.hasPermission(nodeRef, PermissionService.WRITE) == AccessStatus.DENIED) {
            if (logger.isDebugEnabled()) {
                logger.debug("write access denied to :" + name);
            }
            throw new AccessDeniedException("No write access to " + name);
        }
        // Inhibit versioning for this transaction
        getPolicyFilter().disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
        /* 
            * Which DeleteOnClose flag has priority?
            * SetDeleteOnClose is not set or used in this method.   
            * The NTProtocolHandler sets the deleteOnClose in both
            * info and the NetworkFile - it's the one in NetworkFile that results in the file being deleted.
            */
        if (info.hasSetFlag(FileInfo.SetDeleteOnClose) && info.hasDeleteOnClose()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Set Delete On Close for :" + name);
            }
            // Check for delete permission
            if (permissionService.hasPermission(nodeRef, PermissionService.DELETE) == AccessStatus.DENIED) {
                throw new PermissionDeniedException("No delete access to :" + name);
            }
            // Check if the node is locked
            lockService.checkForLock(nodeRef);
            if (fileFolderService.exists(nodeRef)) {
                // Check if it is a folder that is being deleted, make sure it is empty
                boolean isFolder = true;
                ContentFileInfo cInfo = getCifsHelper().getFileInformation(nodeRef, false, isLockedFilesAsOffline);
                if (cInfo != null && cInfo.isDirectory() == false) {
                    isFolder = false;
                }
                // Check if the folder is empty
                if (isFolder == true && getCifsHelper().isFolderEmpty(nodeRef) == false) {
                    throw new DirectoryNotEmptyException(name);
                }
            }
        }
        if (info.hasSetFlag(FileInfo.SetAttributes)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Set attributes" + name + ", file attrs = " + info.getFileAttributes());
            }
            // TODO MER Think we may need to implement, Temporary, Hidden, System, Archive
            if (info.isSystem()) {
                logger.debug("Set system aspect (not yet implemented)" + name);
            }
            if (info.isTemporary()) {
                logger.debug("Set temporary aspect (not yet implemented)" + name);
            }
            if (info.isHidden()) {
                // yes is hidden
                if (logger.isDebugEnabled()) {
                    logger.debug("Set hidden aspect" + name);
                }
                hiddenAspect.hideNodeExplicit(nodeRef);
            } else {
                // not hidden
                if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_HIDDEN)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Reset hidden aspect" + name);
                    }
                    hiddenAspect.unhideExplicit(nodeRef);
                }
            }
        }
        if (info.hasSetFlag(FileInfo.SetAllocationSize)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Set allocation size" + name + info.getAllocationSize());
            }
        // Not yet implemented
        }
        if (info.hasSetFlag(FileInfo.SetFileSize)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Set file size" + name + info.getSize());
            }
        // Not yet implemented
        }
        if (info.hasSetFlag(FileInfo.SetMode)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Set Mode" + name + info.getMode());
            }
        // Not yet implemented - set the unix mode e.g. 777
        }
        // Set the creation and modified date/time
        Map<QName, Serializable> auditableProps = new HashMap<QName, Serializable>(5);
        if (info.hasSetFlag(FileInfo.SetCreationDate) && info.hasCreationDateTime()) {
            // Set the creation date on the file/folder node
            Date createDate = new Date(info.getCreationDateTime());
            auditableProps.put(ContentModel.PROP_CREATED, createDate);
            if (logger.isDebugEnabled()) {
                logger.debug("Set creation date" + name + ", " + createDate);
            }
        }
        if (info.hasSetFlag(FileInfo.SetModifyDate) && info.hasModifyDateTime()) {
            // Set the modification date on the file/folder node
            Date modifyDate = new Date(info.getModifyDateTime());
            auditableProps.put(ContentModel.PROP_MODIFIED, modifyDate);
            // Set the network file so we don't reverse this change in close file.
            if (networkFile != null && !networkFile.isReadOnly()) {
                networkFile.setModifyDate(info.getModifyDateTime());
                if (networkFile instanceof TempNetworkFile) {
                    TempNetworkFile tnf = (TempNetworkFile) networkFile;
                    tnf.setModificationDateSetDirectly(true);
                }
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Set modification date" + name + ", " + modifyDate);
            }
        }
        // Change Date is last write ?
        if (info.hasSetFlag(FileInfo.SetChangeDate) && info.hasChangeDateTime()) {
            Date changeDate = new Date(info.getChangeDateTime());
            if (logger.isDebugEnabled()) {
                logger.debug("Set change date (Not implemented)" + name + ", " + changeDate);
            }
        }
        if (info.hasSetFlag(FileInfo.SetAccessDate) && info.hasAccessDateTime()) {
            Date accessDate = new Date(info.getAccessDateTime());
            if (logger.isDebugEnabled()) {
                logger.debug("Set access date (Not implemented)" + name + ", " + accessDate);
            }
        }
        // Did we have any cm:auditable properties?
        if (auditableProps.size() > 0) {
            getPolicyFilter().disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
            nodeService.addProperties(nodeRef, auditableProps);
            // DEBUG
            if (logger.isDebugEnabled()) {
                logger.debug("Set auditable props: " + auditableProps + " file=" + name);
            }
        }
        return;
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Set file information - access denied, " + name);
        }
        // Convert to a filesystem access denied status
        throw new AccessDeniedException("Set file information " + name);
    } catch (AlfrescoRuntimeException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Open file error", ex);
        }
        throw new IOException("Set file information " + name, ex);
    }
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) DirectoryNotEmptyException(org.alfresco.jlan.server.filesys.DirectoryNotEmptyException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) PermissionDeniedException(org.alfresco.jlan.server.filesys.PermissionDeniedException) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile)

Example 4 with DirectoryNotEmptyException

use of org.alfresco.jlan.server.filesys.DirectoryNotEmptyException in project alfresco-repository by Alfresco.

the class ContentDiskDriver method setFileInformation.

/**
 * Set file information
 *
 * @param sess SrvSession
 * @param tree TreeConnection
 * @param name String
 * @param info FileInfo
 * @exception IOException
 */
public void setFileInformation(SrvSession sess, final TreeConnection tree, final String name, final FileInfo info) throws IOException {
    // Get the device context
    final ContentContext ctx = (ContentContext) tree.getContext();
    try {
        final FileState fstate = getStateForPath(tree, name);
        doInWriteTransaction(sess, new CallableIO<Pair<Boolean, Boolean>>() {

            public Pair<Boolean, Boolean> call() throws IOException {
                // Get the file/folder node
                NodeRef nodeRef = getNodeForPath(tree, name);
                if (permissionService.hasPermission(nodeRef, PermissionService.WRITE) == AccessStatus.DENIED) {
                    throw new AccessDeniedException("No write access to " + name);
                }
                // Inhibit versioning for this transaction
                getPolicyFilter().disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
                if (info.hasSetFlag(FileInfo.SetDeleteOnClose) && info.hasDeleteOnClose()) {
                    // Check deleting permissions on the node if action of deleting was configured only
                    if ((AccessStatus.DENIED == permissionService.hasPermission(nodeRef, PermissionService.DELETE)) && ((null == fstate) || (null == fstate.findAttribute(CanDeleteWithoutPerms)))) {
                        throw new org.alfresco.repo.security.permissions.AccessDeniedException("No delete access to " + name);
                    }
                    if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE)) {
                        // Get the lock type, if any
                        String lockTypeStr = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCK_TYPE);
                        if (lockTypeStr != null)
                            throw new org.alfresco.repo.security.permissions.AccessDeniedException("Node locked, cannot mark for delete");
                    }
                    if (fileFolderService.exists(nodeRef)) {
                        // Check if it is a folder that is being deleted, make sure it is empty
                        boolean isFolder = true;
                        if (fstate != null)
                            isFolder = fstate.isDirectory();
                        else {
                            ContentFileInfo cInfo = cifsHelper.getFileInformation(nodeRef, isReadOnly, isLockedFilesAsOffline);
                            if (cInfo != null && cInfo.isDirectory() == false)
                                isFolder = false;
                        }
                        if (isFolder == true && cifsHelper.isFolderEmpty(nodeRef) == false)
                            throw new DirectoryNotEmptyException(name);
                    }
                    if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
                        logger.debug("Set deleteOnClose=true file=" + name);
                }
                // Set the creation and modified date/time
                Map<QName, Serializable> auditableProps = new HashMap<QName, Serializable>(5);
                if (info.hasSetFlag(FileInfo.SetCreationDate)) {
                    // Set the creation date on the file/folder node
                    Date createDate = new Date(info.getCreationDateTime());
                    auditableProps.put(ContentModel.PROP_CREATED, createDate);
                }
                if (info.hasSetFlag(FileInfo.SetModifyDate)) {
                    // Set the modification date on the file/folder node
                    Date modifyDate = new Date(info.getModifyDateTime());
                    auditableProps.put(ContentModel.PROP_MODIFIED, modifyDate);
                }
                // Did we have any cm:auditable properties?
                if (auditableProps.size() > 0) {
                    getPolicyFilter().disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
                    nodeService.addProperties(nodeRef, auditableProps);
                    // DEBUG
                    if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
                        logger.debug("Set auditable props: " + auditableProps + " file=" + name);
                }
                return null;
            }
        });
        // Update the change date/time
        if (fstate != null) {
            if (info.hasSetFlag(FileInfo.SetDeleteOnClose) && info.hasDeleteOnClose() || info.hasSetFlag(FileInfo.SetCreationDate)) {
                fstate.updateChangeDateTime();
            }
            if (info.hasSetFlag(FileInfo.SetModifyDate)) {
                // Update the change date/time, clear the cached modification date/time
                fstate.updateChangeDateTime();
                Date modifyDate = new Date(info.getModifyDateTime());
                fstate.updateModifyDateTime(modifyDate.getTime());
            }
        }
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
            logger.debug("Set file information - access denied, " + name, ex);
        throw new AccessDeniedException("Set file information " + name);
    } catch (RuntimeException ex) {
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
            logger.debug("Open file error", ex);
        throw new IOException("Set file information " + name);
    }
}
Also used : FileState(org.alfresco.jlan.server.filesys.cache.FileState) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) DirectoryNotEmptyException(org.alfresco.jlan.server.filesys.DirectoryNotEmptyException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) Pair(org.alfresco.util.Pair)

Aggregations

IOException (java.io.IOException)4 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)4 AccessDeniedException (org.alfresco.jlan.server.filesys.AccessDeniedException)4 DirectoryNotEmptyException (org.alfresco.jlan.server.filesys.DirectoryNotEmptyException)4 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 FileNotFoundException (java.io.FileNotFoundException)2 Serializable (java.io.Serializable)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 FileState (org.alfresco.jlan.server.filesys.cache.FileState)2 QName (org.alfresco.service.namespace.QName)2 Map (java.util.Map)1 NetworkFile (org.alfresco.jlan.server.filesys.NetworkFile)1 PermissionDeniedException (org.alfresco.jlan.server.filesys.PermissionDeniedException)1 MimetypeMap (org.alfresco.repo.content.MimetypeMap)1 Pair (org.alfresco.util.Pair)1