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;
}
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;
}
Aggregations