use of org.alfresco.jlan.server.filesys.DiskFullException in project alfresco-repository by Alfresco.
the class ContentNetworkFile method truncateFile.
/**
* Truncate or extend the file to the specified length
*
* @param size long
* @exception IOException
*/
public void truncateFile(long size) throws IOException {
logger.debug("truncate file");
try {
if (hasContent() == false && size == 0L) {
// Open content for overwrite, no need to copy existing content data
openContent(true, true);
} else {
// Normal open for write
openContent(true, false);
// Truncate or extend the channel
channel.truncate(size);
}
} catch (ContentIOException ex) {
if (logger.isDebugEnabled())
logger.debug("Error opening file " + getFullName() + " for write", ex);
throw new DiskFullException("Failed to open " + getFullName() + " for write");
}
// Set modification flag
modified = true;
incrementWriteCount();
// Set the new file size
setFileSize(size);
if (getFileState() != null) {
getFileState().updateModifyDateTime();
getFileState().setFileSize(size);
getFileState().setAllocationSize(size);
}
if (logger.isDebugEnabled())
logger.debug("Truncate file=" + this + ", size=" + size);
}
use of org.alfresco.jlan.server.filesys.DiskFullException in project alfresco-repository by Alfresco.
the class ContentNetworkFile method closeFile.
/**
* Close the file
*
* @exception IOException
*/
public void closeFile() throws IOException {
// Check if this is a directory
if (logger.isDebugEnabled()) {
logger.debug("closeFile");
}
if (isDirectory()) {
// Nothing to do
if (logger.isDebugEnabled()) {
logger.debug("file is a directory - nothing to do");
}
setClosed(true);
return;
} else if (!hasContent()) {
// File was not read/written so content was not opened
if (logger.isDebugEnabled()) {
logger.debug("no content to write - nothing to do");
}
setClosed(true);
return;
}
// update of channel and content member variables need to be serialized
synchronized (this) {
if (modified) {
if (logger.isDebugEnabled()) {
logger.debug("content has been modified");
}
NodeRef contentNodeRef = getNodeRef();
ContentWriter writer = (ContentWriter) content;
// We may be in a retry block, in which case this section will already have executed and channel will be null
if (channel != null) {
// Close the channel
channel.close();
channel = null;
}
// Do we need the mimetype guessing for us when we're done?
if (content.getMimetype() == null || content.getMimetype().equals(MimetypeMap.MIMETYPE_BINARY)) {
String filename = (String) nodeService.getProperty(contentNodeRef, ContentModel.PROP_NAME);
writer.guessMimetype(filename);
}
// We always want the encoding guessing
writer.guessEncoding();
// Retrieve the content data and stop the content URL from being 'eagerly deleted', in case we need to
// retry the transaction
final ContentData contentData = content.getContentData();
// Update node properties
nodeService.removeAspect(contentNodeRef, ContentModel.ASPECT_NO_CONTENT);
try {
nodeService.setProperty(contentNodeRef, ContentModel.PROP_CONTENT, contentData);
} catch (ContentQuotaException qe) {
content = null;
setClosed(true);
throw new DiskFullException(qe.getMessage());
}
// Tidy up after ourselves after a successful commit. Otherwise leave things to allow a retry.
AlfrescoTransactionSupport.bindListener(new TransactionListenerAdapter() {
@Override
public void afterCommit() {
synchronized (this) {
if (channel == null) {
content = null;
setClosed(true);
}
}
}
});
} else if (channel != null) {
// Close it - it was not modified
if (logger.isDebugEnabled()) {
logger.debug("content not modified - simply close the channel");
}
channel.close();
channel = null;
content = null;
setClosed(true);
}
}
}
use of org.alfresco.jlan.server.filesys.DiskFullException in project alfresco-repository by Alfresco.
the class ContentDiskDriver2 method createFile.
@Override
public NetworkFile createFile(NodeRef rootNode, String path, long allocationSize, boolean isHidden) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("createFile :" + path);
}
try {
NodeRef dirNodeRef;
String folderName;
String[] paths = FileName.splitPath(path);
if (paths[0] != null && paths[0].length() > 1) {
// lookup parent directory
dirNodeRef = getNodeForPath(rootNode, paths[0]);
folderName = paths[1];
} else {
dirNodeRef = rootNode;
folderName = path;
}
boolean soft = false;
NodeRef existing = fileFolderService.searchSimple(dirNodeRef, folderName);
if (existing != null) {
if (nodeService.hasAspect(existing, ContentModel.ASPECT_SOFT_DELETE)) {
logger.debug("existing node has soft delete aspect");
soft = true;
}
}
NodeRef nodeRef = null;
if (soft) {
nodeRef = existing;
} else {
nodeRef = cifsHelper.createNode(dirNodeRef, folderName, ContentModel.TYPE_CONTENT);
nodeService.addAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT, null);
lockKeeper.addLock(nodeRef);
}
if (isHidden) {
// yes is hidden
if (logger.isDebugEnabled()) {
logger.debug("Set hidden aspect, nodeRef:" + nodeRef);
}
hiddenAspect.hideNodeExplicit(nodeRef);
}
File file = TempFileProvider.createTempFile("cifs", ".bin");
TempNetworkFile netFile = new TempNetworkFile(file, path);
netFile.setChanged(true);
Serializable created = nodeService.getProperty(nodeRef, ContentModel.PROP_CREATED);
if (created != null && created instanceof Date) {
Date d = (Date) created;
if (logger.isDebugEnabled()) {
logger.debug("replacing create date to date:" + d);
}
netFile.setCreationDate(d.getTime());
netFile.setModifyDate(d.getTime());
}
// Always allow write access to a newly created file
netFile.setGrantedAccess(NetworkFile.READWRITE);
netFile.setAllowedAccess(NetworkFile.READWRITE);
if (netFile != null) {
long id = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(nodeRef, ContentModel.PROP_NODE_DBID));
netFile.setFileId((int) (id & 0xFFFFFFFFL));
}
if (logger.isDebugEnabled()) {
logger.debug("Created file: path=" + path + " node=" + nodeRef + " network file=" + netFile);
}
return netFile;
} catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Create file - access denied, " + path);
}
throw new AccessDeniedException("Unable to create file " + path);
} catch (IOException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Create file - content I/O error, " + path);
}
throw ex;
} catch (ContentIOException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Create file - content I/O error, " + path);
}
throw new DiskFullException("Unable to create file " + path);
} catch (AlfrescoRuntimeException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Create file error", ex);
}
throw new IOException("Unable to create file " + path, ex);
}
}
use of org.alfresco.jlan.server.filesys.DiskFullException in project alfresco-repository by Alfresco.
the class ContentDiskDriver method createFile.
/**
* Create a new file on the file system.
*
* <p>
* WARNING : side effect - closes current transaction context.
*
* @param sess Server session
* @param tree Tree connection
* @param params File create parameters
* @return NetworkFile
* @exception java.io.IOException If an error occurs.
*/
public NetworkFile createFile(SrvSession sess, final TreeConnection tree, final FileOpenParams params) throws IOException {
final ContentContext ctx = (ContentContext) tree.getContext();
try {
// Access the repository in a retryable write transaction
Pair<String, NodeRef> result = doInWriteTransaction(sess, new CallableIO<Pair<String, NodeRef>>() {
public Pair<String, NodeRef> call() throws IOException {
// Get the device root
NodeRef deviceRootNodeRef = ctx.getRootNode();
String path = params.getPath();
String parentPath = null;
if (ctx.hasStateCache()) {
// See if the parent folder has a file state, we can avoid having to walk the path
String[] paths = FileName.splitPath(path);
if (paths[0] != null && paths[0].length() > 1) {
// Find the node ref for the folder being searched
NodeRef nodeRef = getNodeForPath(tree, paths[0]);
if (nodeRef != null) {
deviceRootNodeRef = nodeRef;
path = paths[1];
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
logger.debug("Create file using cached noderef for path " + paths[0]);
}
parentPath = paths[0];
}
}
// Create it - the path will be created, if necessary
if (logger.isDebugEnabled()) {
logger.debug("create new file" + path);
}
NodeRef nodeRef = null;
try {
nodeRef = cifsHelper.createNode(deviceRootNodeRef, path, ContentModel.TYPE_CONTENT);
nodeService.addAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT, null);
} catch (FileExistsException ex) {
nodeRef = cifsHelper.getNodeRef(deviceRootNodeRef, path);
if (!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_SOFT_DELETE)) {
throw ex;
}
}
return new Pair<String, NodeRef>(parentPath, nodeRef);
}
});
// Get or create the file state for the parent folder
FileState parentState = null;
String parentPath = result.getFirst();
if (parentPath != null) {
parentState = getStateForPath(tree, parentPath);
if (parentState == null && ctx.hasStateCache())
parentState = ctx.getStateCache().findFileState(parentPath, true);
}
NodeRef nodeRef = result.getSecond();
if (nodeRef != null && nodeService.hasAspect(nodeRef, ContentModel.ASPECT_SOFT_DELETE)) {
nodeService.removeAspect(nodeRef, ContentModel.ASPECT_SOFT_DELETE);
}
// Create the network file
ContentNetworkFile netFile = ContentNetworkFile.createFile(nodeService, contentService, mimetypeService, cifsHelper, result.getSecond(), params.getPath(), params.isReadOnlyAccess(), params.isAttributesOnlyAccess(), sess);
// Always allow write access to a newly created file
netFile.setGrantedAccess(NetworkFile.READWRITE);
// Set the owner process id for this open file
netFile.setProcessId(params.getProcessId());
// Truncate the file so that the content stream is created
netFile.truncateFile(0L);
// Indicate the file is open
netFile.setClosed(false);
if (netFile != null) {
long id = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(netFile.getNodeRef(), ContentModel.PROP_NODE_DBID));
netFile.setFileId((int) (id & 0xFFFFFFFFL));
}
if (ctx.hasStateCache()) {
FileState fstate = ctx.getStateCache().findFileState(params.getPath(), true);
if (fstate != null) {
// Save the file sharing mode, needs to be done before the open count is incremented
fstate.setSharedAccess(params.getSharedAccess());
fstate.setProcessId(params.getProcessId());
// Indicate that the file is open
fstate.setFileStatus(FileExists);
fstate.incrementOpenCount();
fstate.setFilesystemObject(result.getSecond());
// Track the intial allocation size
fstate.setAllocationSize(params.getAllocationSize());
// Store the file state with the file
netFile.setFileState(fstate);
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
logger.debug("Create file, state=" + fstate);
}
if (parentState != null)
parentState.updateModifyDateTime();
}
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
logger.debug("Created file: path=" + params.getPath() + " file open parameters=" + params + " node=" + result.getSecond() + " network file=" + netFile);
return netFile;
} catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
logger.debug("Create file - access denied, " + params.getFullPath());
throw new AccessDeniedException("Create file " + params.getFullPath());
} catch (ContentIOException ex) {
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
logger.debug("Create file - content I/O error, " + params.getFullPath());
throw new DiskFullException("Create file " + params.getFullPath());
} catch (RuntimeException ex) {
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
logger.debug("Create file error", ex);
throw new IOException("Create file " + params.getFullPath(), ex);
}
}
use of org.alfresco.jlan.server.filesys.DiskFullException in project alfresco-repository by Alfresco.
the class ContentNetworkFile method writeFile.
/**
* Write a block of data to the file.
*
* @param buffer byte[]
* @param length int
* @param position int
* @param fileOffset long
* @exception IOException
*/
public void writeFile(byte[] buffer, int length, int position, long fileOffset) throws IOException {
try {
// Open the channel for writing
openContent(true, false);
} catch (ContentIOException ex) {
if (logger.isDebugEnabled())
logger.debug("Error opening file " + getFullName() + " for write", ex);
throw new DiskFullException("Failed to open " + getFullName() + " for write");
}
// Write to the channel
ByteBuffer byteBuffer = ByteBuffer.wrap(buffer, position, length);
int count = channel.write(byteBuffer, fileOffset);
// Set modification flag
modified = true;
incrementWriteCount();
// Update the current file size
setFileSize(channel.size());
if (getFileState() != null) {
getFileState().updateModifyDateTime();
getFileState().setFileSize(getFileSize());
}
if (logger.isDebugEnabled())
logger.debug("Write file=" + this + ", size=" + count);
}
Aggregations