use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class ContentDiskDriver2 method startSearch.
/**
* Start a new search on the filesystem using the specified searchPath that may contain
* wildcards.
*
* @param session Server session
* @param tree Tree connection
* @param searchPath File(s) to search for, may include wildcards.
* @param attributes Attributes of the file(s) to search for, see class SMBFileAttribute.
* @return SearchContext
* @exception java.io.FileNotFoundException If the search could not be started.
*/
public SearchContext startSearch(SrvSession session, TreeConnection tree, String searchPath, int attributes) throws FileNotFoundException {
if (logger.isDebugEnabled()) {
logger.debug("startSearch: " + searchPath + ", session:" + session.getUniqueId());
}
// Access the device context
ContentContext ctx = (ContentContext) tree.getContext();
try {
String searchFileSpec = searchPath;
NodeRef searchRootNodeRef = ctx.getRootNode();
String[] paths = FileName.splitPath(searchPath);
String dotPath = paths[0];
// lookup parent directory
NodeRef dirNodeRef = getNodeForPath(tree, dotPath);
if (dirNodeRef != null) {
searchRootNodeRef = dirNodeRef;
searchFileSpec = paths[1];
}
// Convert the all files wildcard
if (searchFileSpec.equals("*.*")) {
searchFileSpec = "*";
}
// Debug
long startTime = 0L;
if (logger.isDebugEnabled()) {
startTime = System.currentTimeMillis();
}
// Perform the search
logger.debug("Call repo to do search");
List<NodeRef> results = getCifsHelper().getNodeRefs(searchRootNodeRef, searchFileSpec);
// Debug
if (logger.isDebugEnabled()) {
long endTime = System.currentTimeMillis();
if ((endTime - startTime) > 500) {
logger.debug("Search for searchPath=" + searchPath + ", searchSpec=" + searchFileSpec + ", searchRootNode=" + searchRootNodeRef + " took " + (endTime - startTime) + "ms results=" + results.size());
}
}
DotDotContentSearchContext searchCtx = new DotDotContentSearchContext(getCifsHelper(), results, searchFileSpec, paths[0], isLockedFilesAsOffline);
FileInfo dotInfo = getCifsHelper().getFileInformation(searchRootNodeRef, false, isLockedFilesAsOffline);
if (searchPath.equals(FileName.DOS_SEPERATOR_STR)) {
// Searching the root folder, re-use the search folder file information for the '..' pseudo entry
FileInfo dotDotInfo = new FileInfo();
dotDotInfo.copyFrom(dotInfo);
searchCtx.setDotInfo(dotInfo);
searchCtx.setDotDotInfo(dotDotInfo);
} else {
String[] parent = FileName.splitPath(dotPath);
NodeRef parentNodeRef = getNodeForPath(tree, parent[0]);
if (parentNodeRef != null) {
FileInfo dotDotInfo = getCifsHelper().getFileInformation(parentNodeRef, false, isLockedFilesAsOffline);
searchCtx.setDotDotInfo(dotDotInfo);
}
// Searching a normal, non root, folder
// Need to set dot and dotdot
searchCtx.setDotInfo(dotInfo);
}
// Debug
if (logger.isDebugEnabled()) {
logger.debug("Started search: search path=" + searchPath + " attributes=" + attributes + ", ctx=" + searchCtx);
}
return searchCtx;
} catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Start search - access denied, " + searchPath);
}
throw new FileNotFoundException("Start search " + searchPath);
} catch (AlfrescoRuntimeException ex) {
if (logger.isErrorEnabled()) {
logger.error("Exception in Start search", ex);
}
throw new FileNotFoundException("Start search " + searchPath);
}
}
use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class ContentDiskDriver2 method fileExists.
/**
* Check if the specified file exists, and whether it is a file or directory.
*
* @param session Server session
* @param tree Tree connection
* @param name the path of the file
* @return FileStatus (0: NotExist, 1 : FileExist, 2: DirectoryExists)
* @see FileStatus
*/
public int fileExists(SrvSession session, TreeConnection tree, String name) {
if (logger.isDebugEnabled()) {
logger.debug("fileExists:" + name + ", session:" + session.getUniqueId());
}
ContentContext ctx = (ContentContext) tree.getContext();
int status = FileStatus.Unknown;
try {
// Get the file information to check if the file/folder exists
FileInfo info = getFileInformation(session, tree, name);
if (info.isDirectory()) {
if (logger.isDebugEnabled()) {
logger.debug("is directory");
}
status = FileStatus.DirectoryExists;
} else {
if (logger.isDebugEnabled()) {
logger.debug("is file");
}
status = FileStatus.FileExists;
}
if (logger.isDebugEnabled()) {
logger.debug("File status determined: name=" + name + " status=" + status);
}
return status;
} catch (FileNotFoundException e) {
if (logger.isDebugEnabled()) {
logger.debug("file does not exist");
}
status = FileStatus.NotExist;
return status;
} catch (IOException e) {
if (logger.isDebugEnabled()) {
logger.debug("File exists error, " + name, e);
}
status = FileStatus.NotExist;
return status;
}
}
use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class ContentDiskDriver2 method getFileInformation.
/**
* Get the file information for the specified file.
*
* @param session Server session
* @param tree Tree connection
* @param path File name/path that information is required for.
* @return File information if valid, else null
* @exception java.io.IOException The exception description.
*/
public FileInfo getFileInformation(SrvSession session, TreeConnection tree, String path) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("getFileInformation:" + path + ", session:" + session.getUniqueId());
}
ContentContext ctx = (ContentContext) tree.getContext();
boolean readOnly = !m_transactionService.getAllowWrite();
if (path == null || path.length() == 0) {
path = FileName.DOS_SEPERATOR_STR;
}
String infoPath = path;
try {
FileInfo finfo = null;
NodeRef nodeRef = getNodeForPath(tree, infoPath);
if (nodeRef != null) {
// Get the file information for the node
finfo = getCifsHelper().getFileInformation(nodeRef, readOnly, isLockedFilesAsOffline);
/**
* Special processing for root node
*/
if (path.equals(FileName.DOS_SEPERATOR_STR)) {
finfo.setFileName("");
}
// DEBUG
if (logger.isDebugEnabled()) {
logger.debug("getFileInformation found nodeRef for nodeRef :" + nodeRef + ", path: " + path);
}
// Moved to CIFS Helper
// // Set the file id from the node's DBID
// long id = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(nodeRef, ContentModel.PROP_NODE_DBID));
// finfo.setFileId((int) (id & 0xFFFFFFFFL));
}
// Return the file information or null if the node ref does not exist
return finfo;
} catch (FileNotFoundException e) {
if (logger.isDebugEnabled()) {
// exception not logged - cifs does lots of these
logger.debug("Get file info - file not found, " + path);
}
throw e;
} catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Get file info - access denied, " + path, ex);
}
// Convert to a filesystem access denied status
throw new AccessDeniedException("Get file information " + path);
} catch (AlfrescoRuntimeException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Get file info error" + path, ex);
}
// Convert to a general I/O exception
throw new IOException("Get file information " + path, ex);
}
}
use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class ContentDiskDriver2 method openFile.
/**
* Open the file - Repo Specific implementation
*/
public NetworkFile openFile(SrvSession session, TreeConnection tree, NodeRef rootNode, String path, OpenFileMode mode, boolean truncate) throws IOException {
ContentContext ctx = (ContentContext) tree.getContext();
if (logger.isDebugEnabled()) {
logger.debug("openFile :" + path + ", mode:" + mode);
}
try {
String name = path;
NodeRef nodeRef = getNodeForPath(rootNode, path);
boolean readOnly = false;
// Check permissions on the file/folder
switch(mode) {
case READ_ONLY:
// follow through
case ATTRIBUTES_ONLY:
if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED) {
if (logger.isDebugEnabled()) {
logger.debug("about to throw an no read access denied exception path:" + path);
}
throw new AccessDeniedException("No read access to " + path);
}
readOnly = true;
break;
case READ_WRITE:
case WRITE_ONLY:
if (!m_transactionService.getAllowWrite()) {
throw new AccessDeniedException("Repo is write only, No write access to " + path);
}
if (permissionService.hasPermission(nodeRef, PermissionService.WRITE) == AccessStatus.DENIED) {
if (logger.isDebugEnabled()) {
logger.debug("about to throw an no write access denied exception path:" + path);
}
throw new AccessDeniedException("No write access to " + path);
}
lockService.checkForLock(nodeRef);
readOnly = false;
break;
case DELETE:
if (!m_transactionService.getAllowWrite()) {
throw new AccessDeniedException("Repo is write only, No write access to " + path);
}
lockService.checkForLock(nodeRef);
}
// Check if the node is a link node
NodeRef linkRef = (NodeRef) nodeService.getProperty(nodeRef, ContentModel.PROP_LINK_DESTINATION);
NetworkFile netFile = null;
if (linkRef == null) {
// A normal node, not a link node
// TODO MER REWRITE HERE
FileInfo fileInfo = cifsHelper.getFileInformation(nodeRef, "", false, false);
// TODO this is wasteful - the isDirectory is in the params. We should split off an openDirectory method.
if (fileInfo.isDirectory()) {
logger.debug("open file - is a directory!");
netFile = new AlfrescoFolder(path, fileInfo, readOnly);
} else {
// A normal file
switch(mode) {
case READ_ONLY:
logger.debug("open file for read only");
netFile = ContentNetworkFile.createFile(nodeService, contentService, mimetypeService, getCifsHelper(), nodeRef, path, true, false, session);
netFile.setGrantedAccess(NetworkFile.READONLY);
break;
case READ_WRITE:
{
logger.debug("open file for read write");
File file = TempFileProvider.createTempFile("cifs", ".bin");
lockKeeper.addLock(nodeRef);
if (!truncate) {
// Need to open a temp file with a copy of the content.
ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
if (reader != null) {
reader.getContent(file);
}
}
netFile = new TempNetworkFile(file, name);
netFile.setCreationDate(fileInfo.getCreationDateTime());
netFile.setModifyDate(fileInfo.getModifyDateTime());
netFile.setGrantedAccess(NetworkFile.READWRITE);
if (truncate) {
netFile.truncateFile(0);
}
if (logger.isDebugEnabled()) {
logger.debug("Created file: path=" + name + " node=" + nodeRef + " network file=" + netFile);
}
}
break;
case ATTRIBUTES_ONLY:
logger.debug("open file for attributes only");
netFile = ContentNetworkFile.createFile(nodeService, contentService, mimetypeService, getCifsHelper(), nodeRef, path, true, true, session);
netFile.setGrantedAccess(NetworkFile.READONLY);
break;
case DELETE:
// TODO Not sure about this one.
logger.debug("open file for delete");
netFile = ContentNetworkFile.createFile(nodeService, contentService, mimetypeService, getCifsHelper(), nodeRef, path, true, false, session);
netFile.setGrantedAccess(NetworkFile.READONLY);
break;
case WRITE_ONLY:
{
// consider this as open read/write/truncate)
logger.debug("open file write only");
File file = TempFileProvider.createTempFile("cifs", ".bin");
netFile = new TempNetworkFile(file, name);
// Needs to be READWRITE for JavaNetworkFile - there's no such thing as WRITEONLY!
netFile.setGrantedAccess(NetworkFile.READWRITE);
if (logger.isDebugEnabled()) {
logger.debug("Created temporary file: path=" + name + " node=" + nodeRef + " network file=" + netFile);
}
}
}
}
// end of a normal file
} else {
// This is a link node
// TODO - This server name stuff should be replaced In particular the
// See PseudoFileOverlayImp
// Get the CIFS server name
String srvName = null;
SMBServer cifsServer = (SMBServer) session.getServer().getConfiguration().findServer("CIFS");
if (session instanceof SMBSrvSession) {
SMBSrvSession smbSess = (SMBSrvSession) session;
srvName = smbSess.getShareHostName();
} else if (cifsServer != null) {
// Use the CIFS server name in the URL
srvName = cifsServer.getServerName();
} else {
// Use the local server name in the URL
srvName = InetAddress.getLocalHost().getHostName();
}
// Convert the target node to a path, convert to URL format
String pathl = getPathForNode(rootNode, linkRef);
path = pathl.replace(FileName.DOS_SEPERATOR, '/');
String lnkForWinPath = convertStringToUnicode(path);
// Build the URL file data
StringBuilder urlStr = new StringBuilder();
urlStr.append("[InternetShortcut]\r\n");
urlStr.append("URL=file://");
urlStr.append(srvName);
urlStr.append("/");
urlStr.append(tree.getSharedDevice().getName());
urlStr.append(lnkForWinPath);
urlStr.append("\r\n");
// Create the in memory pseudo file for the URL link
byte[] urlData = urlStr.toString().getBytes();
// Get the file information for the link node
FileInfo fInfo = getCifsHelper().getFileInformation(nodeRef, false, isLockedFilesAsOffline);
// Set the file size to the actual data length
fInfo.setFileSize(urlData.length);
// Create the network file using the in-memory file data
netFile = new LinkMemoryNetworkFile(fInfo.getFileName(), urlData, fInfo, nodeRef);
netFile.setFullName(pathl);
}
if (netFile != null) {
long id = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(nodeRef, ContentModel.PROP_NODE_DBID));
netFile.setFileId((int) (id & 0xFFFFFFFFL));
// Indicate the file is open
netFile.setClosed(false);
}
if (logger.isDebugEnabled()) {
logger.debug("Opened network file: path=" + path + " network file=" + netFile);
}
return netFile;
} catch (NodeLockedException nle) {
if (logger.isDebugEnabled()) {
logger.debug("Open file - node is locked, " + path);
}
throw new AccessDeniedException("File is locked, no write access to " + path);
} catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Open file - access denied, " + path);
}
throw new AccessDeniedException("Open file " + path);
} catch (AlfrescoRuntimeException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Open file error", ex);
}
throw new IOException("Open file " + path, ex);
}
}
use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class ContentDiskDriver method deleteFile.
/**
* Delete the specified file.
*
* @param sess Server session
* @param tree Tree connection
* @param name NetworkFile
* @exception java.io.IOException The exception description.
*/
public void deleteFile(final SrvSession sess, final TreeConnection tree, final String name) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("Delete file - " + name);
}
final ContentContext ctx = (ContentContext) tree.getContext();
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();
// Perform repository updates in a retryable write transaction
Callable<Void> postTxn = doInWriteTransaction(sess, new CallableIO<Callable<Void>>() {
public Callable<Void> call() throws IOException {
// Get the node and delete it
final NodeRef nodeRef = getNodeForPath(tree, name);
Callable<Void> result = null;
if (fileFolderService.exists(nodeRef)) {
// Get the size of the file being deleted
final FileInfo fInfo = quotaMgr == null ? null : getFileInformation(sess, tree, name);
// Check if the node is versionable
final boolean isVersionable = nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE);
if (logger.isDebugEnabled()) {
logger.debug("deleted file" + name);
}
fileFolderService.delete(nodeRef);
// Return the operations to perform when the transaction succeeds
result = new Callable<Void>() {
public Void call() throws Exception {
if (ctx.hasStateCache()) {
if (isVersionable == true) {
// Make sure the file state is cached for a short while, a new file may be
// renamed to the same name
// in which case we can connect the file to the previous version history
FileState delState = ctx.getStateCache().findFileState(name, true);
if (logger.isDebugEnabled()) {
logger.debug("set delete on close" + name);
}
delState.setExpiryTime(System.currentTimeMillis() + FileState.DeleteTimeout);
delState.setFileStatus(DeleteOnClose);
delState.setFilesystemObject(nodeRef);
} else {
// Remove the file state
ctx.getStateCache().removeFileState(name);
}
// Update, or create, a parent folder file state
String[] paths = FileName.splitPath(name);
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 (quotaMgr != null)
quotaMgr.releaseSpace(sess, tree, fInfo.getFileId(), name, fInfo.getSize());
return null;
}
};
}
if (logger.isDebugEnabled() && (ctx.hasDebug(AlfrescoContext.DBG_FILE) || ctx.hasDebug(AlfrescoContext.DBG_RENAME)))
logger.debug("Deleted file: " + name + ", node=" + nodeRef);
return result;
}
});
// Perform state updates after the transaction succeeds
postTxn.call();
} catch (NodeLockedException ex) {
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
logger.debug("Delete file - access denied (locked)");
throw new AccessDeniedException("Delete " + name);
} catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
logger.debug("Delete file - access denied");
throw new AccessDeniedException("Delete " + name);
} catch (IOException ex) {
// Allow I/O Exceptions to pass through
throw ex;
} catch (Exception ex) {
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_FILE))
logger.debug("Delete file error", ex);
// Convert to a general I/O exception
IOException ioe = new IOException("Delete file " + name);
ioe.initCause(ex);
throw ioe;
}
}
Aggregations