Search in sources :

Example 6 with QuotaManager

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

the class ContentDiskDriver2 method deleteFile2.

/**
 * Delete the specified file.
 *
 * @param session Server session
 * @param tree Tree connection
 * @param rootNode Root node
 * @param path NetworkFile
 * @exception java.io.IOException The exception description.
 * @return NodeRef of deletedFile
 */
public NodeRef deleteFile2(final SrvSession session, final TreeConnection tree, NodeRef rootNode, String path) throws IOException {
    // Get the device context
    final ContentContext ctx = (ContentContext) tree.getContext();
    if (logger.isDebugEnabled()) {
        logger.debug("deleteFile:" + path + ", session:" + session.getUniqueId());
    }
    try {
        // Check if there is a quota manager enabled, if so then we need to save the current file size
        final QuotaManager quotaMgr = ctx.getQuotaManager();
        // Get the node and delete it
        final NodeRef nodeRef = getNodeForPath(tree, path);
        if (fileFolderService.exists(nodeRef)) {
            lockKeeper.removeLock(nodeRef);
            // Get the size of the file being deleted
            final FileInfo fInfo = quotaMgr == null ? null : getFileInformation(session, tree, path);
            if (logger.isDebugEnabled()) {
                logger.debug("deleted file" + path);
            }
            fileFolderService.delete(nodeRef);
            // TODO Needs to be post-commit
            if (quotaMgr != null) {
                quotaMgr.releaseSpace(session, tree, fInfo.getFileId(), path, fInfo.getSize());
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Deleted file: " + path + ", nodeRef=" + nodeRef);
            }
            // void return
            return nodeRef;
        }
    } catch (NodeLockedException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Delete file - access denied (locked)", ex);
        }
        throw new AccessDeniedException("Unable to delete " + path);
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Delete file - access denied", ex);
        }
        // Convert to a filesystem access denied status
        throw new AccessDeniedException("Unable to delete " + path);
    } catch (IOException ex) {
        // Allow I/O Exceptions to pass through
        if (logger.isDebugEnabled()) {
            logger.debug("Delete file error - pass through IO Exception", ex);
        }
        throw ex;
    } catch (Exception ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Delete file error", ex);
        }
        // Convert to a general I/O exception
        IOException ioe = new IOException("Delete file " + path);
        ioe.initCause(ex);
        throw ioe;
    }
    return null;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) FileInfo(org.alfresco.jlan.server.filesys.FileInfo) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) QuotaManager(org.alfresco.jlan.server.filesys.quota.QuotaManager) DiskFullException(org.alfresco.jlan.server.filesys.DiskFullException) IOControlNotImplementedException(org.alfresco.jlan.server.filesys.IOControlNotImplementedException) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) FileNotFoundException(java.io.FileNotFoundException) QuotaManagerException(org.alfresco.jlan.server.filesys.quota.QuotaManagerException) PermissionDeniedException(org.alfresco.jlan.server.filesys.PermissionDeniedException) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DirectoryNotEmptyException(org.alfresco.jlan.server.filesys.DirectoryNotEmptyException) SMBException(org.alfresco.jlan.smb.SMBException)

Example 7 with QuotaManager

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

the class ContentDiskDriver method writeFile.

/**
 * Write a block of data to the file.
 *
 * @param sess Server session
 * @param tree Tree connection
 * @param file Network file details
 * @param buffer byte[] Data to be written
 * @param bufferOffset Offset within the buffer that the data starts
 * @param size int Data length
 * @param fileOffset Position within the file that the data is to be written.
 * @return Number of bytes actually written
 * @exception java.io.IOException The exception description.
 */
public int writeFile(SrvSession sess, TreeConnection tree, NetworkFile file, byte[] buffer, int bufferOffset, int size, long fileOffset) throws IOException {
    if (file instanceof ContentNetworkFile) {
        ContentNetworkFile contentFile = (ContentNetworkFile) file;
        if (contentFile.hasContent() == false)
            beginReadTransaction(sess);
    }
    // Check if there is a quota manager
    ContentContext ctx = (ContentContext) tree.getContext();
    QuotaManager quotaMgr = ctx.getQuotaManager();
    long curSize = file.getFileSize();
    if (quotaMgr != null) {
        // Check if the file requires extending
        long extendSize = 0L;
        long endOfWrite = fileOffset + size;
        if (endOfWrite > curSize) {
            // Calculate the amount the file must be extended
            extendSize = endOfWrite - file.getFileSize();
            // Allocate space for the file extend
            quotaMgr.allocateSpace(sess, tree, file, extendSize);
        }
    }
    // Write to the file
    file.writeFile(buffer, size, bufferOffset, fileOffset);
    if (quotaMgr != null) {
        if (file.getFileSize() < curSize) {
            // Release space that was freed by the write
            quotaMgr.releaseSpace(sess, tree, file.getFileId(), file.getFullName(), curSize - file.getFileSize());
        }
    }
    if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILEIO))
        logger.debug("Wrote bytes to file: network file=" + file + " buffer size=" + buffer.length + " size=" + size + " file offset=" + fileOffset);
    return size;
}
Also used : QuotaManager(org.alfresco.jlan.server.filesys.quota.QuotaManager)

Aggregations

QuotaManager (org.alfresco.jlan.server.filesys.quota.QuotaManager)7 IOException (java.io.IOException)5 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)5 FileState (org.alfresco.jlan.server.filesys.cache.FileState)4 FileNotFoundException (java.io.FileNotFoundException)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 DeviceContextException (org.alfresco.jlan.server.core.DeviceContextException)2 AccessDeniedException (org.alfresco.jlan.server.filesys.AccessDeniedException)2 DirectoryNotEmptyException (org.alfresco.jlan.server.filesys.DirectoryNotEmptyException)2 DiskFullException (org.alfresco.jlan.server.filesys.DiskFullException)2 FileInfo (org.alfresco.jlan.server.filesys.FileInfo)2 QuotaManagerException (org.alfresco.jlan.server.filesys.quota.QuotaManagerException)2 NodeLockedException (org.alfresco.service.cmr.lock.NodeLockedException)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 Callable (java.util.concurrent.Callable)1 FileExistsException (org.alfresco.jlan.server.filesys.FileExistsException)1 FileSharingException (org.alfresco.jlan.server.filesys.FileSharingException)1 IOControlNotImplementedException (org.alfresco.jlan.server.filesys.IOControlNotImplementedException)1 PermissionDeniedException (org.alfresco.jlan.server.filesys.PermissionDeniedException)1 SMBException (org.alfresco.jlan.smb.SMBException)1