Search in sources :

Example 6 with FileInfo

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

the class ContentDiskDriver 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);
    }
    // Start a transaction
    beginReadTransaction(session);
    // Get the device root
    ContentContext ctx = (ContentContext) tree.getContext();
    NodeRef infoParentNodeRef = ctx.getRootNode();
    if (path == null || path.length() == 0)
        path = FileName.DOS_SEPERATOR_STR;
    String infoPath = path;
    try {
        // Check if the path is to a pseudo file
        FileInfo finfo = null;
        // Get the node ref for the path, chances are there is a file state in the cache
        NodeRef nodeRef = getNodeForPath(tree, infoPath);
        if (nodeRef != null) {
            // Get the file information for the node
            finfo = cifsHelper.getFileInformation(nodeRef, isReadOnly, isLockedFilesAsOffline);
            if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
                logger.debug("getInfo using cached noderef for path " + path);
        }
        if (finfo == null) {
            String[] paths = FileName.splitPath(path);
            if (paths[0] != null && paths[0].length() > 1) {
                // Find the node ref for the folder being searched
                nodeRef = getNodeForPath(tree, paths[0]);
                if (nodeRef != null) {
                    infoParentNodeRef = nodeRef;
                    infoPath = paths[1];
                    if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
                        logger.debug("getInfo using cached noderef for parent " + path);
                }
            }
            // Access the repository to get the file information
            finfo = cifsHelper.getFileInformation(infoParentNodeRef, infoPath, isReadOnly, isLockedFilesAsOffline);
            if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
                logger.debug("Getting file information: path=" + path + " file info: " + finfo);
        }
        if (finfo != null) {
            // Set the file id
            long id = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(nodeRef, ContentModel.PROP_NODE_DBID));
            finfo.setFileId((int) (id & 0xFFFFFFFFL));
            // Copy cached file details, if available
            FileState fstate = getStateForPath(tree, infoPath);
            if (fstate != null) {
                // finfo.setAccessDateTime(fstate.getAccessDateTime());
                if (fstate.hasChangeDateTime())
                    finfo.setChangeDateTime(fstate.getChangeDateTime());
                if (fstate.hasModifyDateTime())
                    finfo.setModifyDateTime(fstate.getModifyDateTime());
                if (fstate.hasAllocationSize() && fstate.getAllocationSize() > finfo.getSize())
                    finfo.setAllocationSize(fstate.getAllocationSize());
            } else {
                // Create a file state for the file/folder
                fstate = ctx.getStateCache().findFileState(path, true);
                if (finfo.isDirectory())
                    fstate.setFileStatus(DirectoryExists);
                else
                    fstate.setFileStatus(FileExists);
                fstate.setFilesystemObject(nodeRef);
            }
        }
        return finfo;
    } catch (FileNotFoundException e) {
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
            logger.debug("Get file info - file not found, " + path);
        throw e;
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
            logger.debug("Get file info - access denied, " + path);
        throw new AccessDeniedException("Get file information " + path);
    } catch (RuntimeException ex) {
        if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
            logger.debug("Get file info error", ex);
        throw new IOException("Get file information " + path);
    }
}
Also used : FileState(org.alfresco.jlan.server.filesys.cache.FileState) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FileInfo(org.alfresco.jlan.server.filesys.FileInfo)

Example 7 with FileInfo

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

the class ContentNetworkFile method createFile.

/**
 * Helper method to create a {@link NetworkFile network file} given a node reference.
 */
public static ContentNetworkFile createFile(NodeService nodeService, ContentService contentService, MimetypeService mimetypeService, CifsHelper cifsHelper, NodeRef nodeRef, String path, boolean readOnly, boolean attributesOnly, SrvSession sess) {
    // Create the file
    ContentNetworkFile netFile = null;
    if (isMSOfficeSpecialFile(path, sess, nodeService, nodeRef)) {
        // Create a file for special processing for Excel
        netFile = new MSOfficeContentNetworkFile(nodeService, contentService, mimetypeService, nodeRef, path);
    } else if (isOpenOfficeSpecialFile(path, sess, nodeService, nodeRef)) {
        // Create a file for special processing
        netFile = new OpenOfficeContentNetworkFile(nodeService, contentService, mimetypeService, nodeRef, path);
    } else {
        // Create a normal content file
        netFile = new ContentNetworkFile(nodeService, contentService, mimetypeService, nodeRef, path);
    }
    if (attributesOnly) {
        netFile.setGrantedAccess(NetworkFile.ATTRIBUTESONLY);
    } else if (readOnly) {
        netFile.setGrantedAccess(NetworkFile.READONLY);
    } else {
        netFile.setGrantedAccess(NetworkFile.READWRITE);
    }
    // Check the type
    FileInfo fileInfo;
    try {
        fileInfo = cifsHelper.getFileInformation(nodeRef, "", false, false);
    } catch (FileNotFoundException e) {
        throw new AlfrescoRuntimeException("File not found when creating network file: " + nodeRef, e);
    }
    if (fileInfo.isDirectory()) {
        netFile.setAttributes(FileAttribute.Directory);
    } else {
        // Set the current size
        netFile.setFileSize(fileInfo.getSize());
    }
    if (fileInfo.hasCreationDateTime())
        netFile.setCreationDate(fileInfo.getCreationDateTime());
    if (fileInfo.hasModifyDateTime() && fileInfo.getModifyDateTime() > 0L)
        netFile.setModifyDate(fileInfo.getModifyDateTime());
    else
        netFile.setModifyDate(fileInfo.getCreationDateTime());
    if (fileInfo.hasAccessDateTime() && fileInfo.getAccessDateTime() > 0L)
        netFile.setAccessDate(fileInfo.getAccessDateTime());
    else
        netFile.setAccessDate(fileInfo.getCreationDateTime());
    // Set the file attributes
    netFile.setAttributes(fileInfo.getFileAttributes());
    if (netFile.isReadOnly() && netFile.getGrantedAccess() == NetworkFile.READWRITE)
        netFile.setGrantedAccess(NetworkFile.READONLY);
    if (logger.isDebugEnabled())
        logger.debug("Create file node=" + nodeRef + ", path=" + path + ", netfile=" + netFile);
    return netFile;
}
Also used : FileInfo(org.alfresco.jlan.server.filesys.FileInfo) FileNotFoundException(java.io.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 8 with FileInfo

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

the class ContentSearchContext method nextFileName.

/**
 * Return the file name of the next file in the active search. Returns null is the search is
 * complete.
 *
 * @return String
 */
public String nextFileName() {
    if (!hasMoreFiles())
        return null;
    // Increment the index and resume id
    index++;
    resumeId++;
    // Get the next file info from the node search
    NodeRef nextNodeRef = results.get(index);
    try {
        // Get the file information and copy across to the callers file info
        FileInfo nextInfo = cifsHelper.getFileInformation(nextNodeRef, "", false, false);
        // Keep track of the last file name returned
        m_lastFileName = nextInfo.getFileName();
        return nextInfo.getFileName();
    } catch (FileNotFoundException e) {
    }
    return null;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.jlan.server.filesys.FileInfo) FileNotFoundException(java.io.FileNotFoundException)

Example 9 with FileInfo

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

the class BufferedContentDiskDriver method getFileInformationInternal.

private FileInfo getFileInformationInternal(SrvSession sess, TreeConnection tree, String path) throws IOException {
    // String userName = AuthenticationUtil.getFullyAuthenticatedUser();
    SharedDevice device = tree.getSharedDevice();
    String deviceName = device.getName();
    if (logger.isDebugEnabled()) {
        logger.debug("getFileInformation session:" + sess.getUniqueId() + ", deviceName:" + deviceName + ", path:" + path);
    }
    if (path == null) {
        throw new IllegalArgumentException("Path is null");
    }
    FileInfoKey key = new FileInfoKey(sess, path, tree);
    FileInfo fromCache = fileInfoCache.get(key);
    if (fromCache != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("returning FileInfo from cache");
        }
        return fromCache;
    }
    FileInfo info = diskInterface.getFileInformation(sess, tree, path);
    if (info != null) {
        /**
         * Don't cache directories since the modification date is important.
         */
        if (!info.isDirectory()) {
            fileInfoCache.put(key, info);
        }
    }
    /*
         * Dual Key the cache so it can be looked up by NodeRef or Path
         */
    if (info instanceof ContentFileInfo) {
        ContentFileInfo cinfo = (ContentFileInfo) info;
        fileInfoCache.put(cinfo.getNodeRef(), info);
    }
    return info;
}
Also used : FileInfo(org.alfresco.jlan.server.filesys.FileInfo) SharedDevice(org.alfresco.jlan.server.core.SharedDevice)

Example 10 with FileInfo

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

the class BufferedContentDiskDriver method fileExists.

@Override
public int fileExists(SrvSession sess, TreeConnection tree, String path) {
    String deviceName = tree.getSharedDevice().getName();
    if (logger.isDebugEnabled()) {
        logger.debug("fileExists session:" + sess.getUniqueId() + ", deviceName" + deviceName + ", path:" + path);
    }
    FileInfoKey key = new FileInfoKey(sess, path, tree);
    FileInfo fromCache = fileInfoCache.get(key);
    if (fromCache != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("fileExists found FileInfo in cache");
        }
        if (fromCache.isDirectory()) {
            return FileStatus.DirectoryExists;
        } else {
            return FileStatus.FileExists;
        }
    } else {
        try {
            FileInfo lookup = getFileInformationInternal(sess, tree, path);
            if (logger.isDebugEnabled()) {
                logger.debug("fileExists obtained file information");
            }
            if (lookup.isDirectory()) {
                return FileStatus.DirectoryExists;
            } else {
                return FileStatus.FileExists;
            }
        } catch (IOException ie) {
            return FileStatus.NotExist;
        }
    }
}
Also used : FileInfo(org.alfresco.jlan.server.filesys.FileInfo) IOException(java.io.IOException)

Aggregations

FileInfo (org.alfresco.jlan.server.filesys.FileInfo)22 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17 FileNotFoundException (java.io.FileNotFoundException)13 IOException (java.io.IOException)13 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)9 AccessDeniedException (org.alfresco.jlan.server.filesys.AccessDeniedException)8 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)8 SrvSession (org.alfresco.jlan.server.SrvSession)7 ServerConfiguration (org.alfresco.jlan.server.config.ServerConfiguration)7 DiskSharedDevice (org.alfresco.jlan.server.filesys.DiskSharedDevice)7 NetworkFile (org.alfresco.jlan.server.filesys.NetworkFile)7 TreeConnection (org.alfresco.jlan.server.filesys.TreeConnection)7 FileState (org.alfresco.jlan.server.filesys.cache.FileState)6 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)6 FileOpenParams (org.alfresco.jlan.server.filesys.FileOpenParams)5 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)5 Serializable (java.io.Serializable)4 DeviceContextException (org.alfresco.jlan.server.core.DeviceContextException)4 FileExistsException (org.alfresco.jlan.server.filesys.FileExistsException)4 Date (java.util.Date)3