@Override public void closeFile(SrvSession sess, TreeConnection tree, NetworkFile param) throws IOException { ContentContext tctx = (ContentContext) tree.getContext(); try { diskInterface.closeFile(sess, tree, param); if (tctx.hasStateCache()) { FileStateCache cache = tctx.getStateCache(); FileState fstate = cache.findFileState(param.getFullName(), true); if (fstate != null && param.getAccessToken() != null) { FileAccessToken token = param.getAccessToken(); if (logger.isDebugEnabled() && token != null) { logger.debug("close file release lock token:" + token); } cache.releaseFileAccess(fstate, token); } } } catch (IOException ie) { if (logger.isDebugEnabled()) { logger.debug("close file exception caught", ie); } throw ie; } }
@Override public long seekFile(SrvSession sess, TreeConnection tree, NetworkFile file, long pos, int typ) throws IOException { long ret = diskInterface.seekFile(sess, tree, file, pos, typ); return ret; }
@Override public void deleteDirectory(SrvSession sess, TreeConnection tree, String dir) throws IOException { try { diskInterface.deleteDirectory(sess, tree, dir); } catch (org.alfresco.repo.security.permissions.AccessDeniedException ade) { throw new AccessDeniedException("Unable to delete directory " + dir, ade); } }
@Override public int writeFile( SrvSession sess, TreeConnection tree, NetworkFile file, byte[] buf, int bufoff, int siz, long fileoff) throws IOException { return diskInterface.writeFile(sess, tree, file, buf, bufoff, siz, fileoff); }
@Override public SearchContext startSearch( SrvSession sess, TreeConnection tree, String searchPath, int attrib) throws FileNotFoundException { FileFilterMode.setClient(ClientHelper.getClient(sess)); try { SearchContext context = diskInterface.startSearch(sess, tree, searchPath, attrib); return context; } finally { FileFilterMode.clearClient(); } }
@Override public int readFile( SrvSession sess, TreeConnection tree, NetworkFile file, byte[] buf, int bufPos, int siz, long filePos) throws IOException { return diskInterface.readFile(sess, tree, file, buf, bufPos, siz, filePos); }
@Override public void createDirectory(SrvSession sess, TreeConnection tree, FileOpenParams params) throws IOException { try { FileFilterMode.setClient(ClientHelper.getClient(sess)); try { diskInterface.createDirectory(sess, tree, params); } finally { FileFilterMode.clearClient(); } } catch (org.alfresco.repo.security.permissions.AccessDeniedException ade) { throw new AccessDeniedException("Unable to create directory " + params.getPath(), ade); } }
@Override public FileInfo getFileInformation(SrvSession sess, TreeConnection tree, String path) throws IOException { if (logger.isDebugEnabled()) { logger.debug("getFileInformation:" + path); } FileFilterMode.setClient(ClientHelper.getClient(sess)); try { FileInfo info = diskInterface.getFileInformation(sess, tree, path); return info; } finally { FileFilterMode.clearClient(); } }
@Override public FileInfo getFileInformation(SrvSession sess, TreeConnection tree, String name) throws IOException { return diskInterface.getFileInformation(sess, tree, name); }
@Override public void flushFile(SrvSession sess, TreeConnection tree, NetworkFile file) throws IOException { diskInterface.flushFile(sess, tree, file); }
@Override public void treeClosed(SrvSession sess, TreeConnection tree) { diskInterface.treeClosed(sess, tree); }
@Override public SearchContext startSearch( SrvSession sess, TreeConnection tree, String searchPath, int attrib) throws FileNotFoundException { return diskInterface.startSearch(sess, tree, searchPath, attrib); }
@Override public void renameFile(SrvSession sess, TreeConnection tree, String oldName, String newName) throws IOException { diskInterface.renameFile(sess, tree, oldName, newName); }
@Override public NetworkFile openFile(SrvSession sess, TreeConnection tree, FileOpenParams params) throws IOException { ContentContext tctx = (ContentContext) tree.getContext(); String path = params.getPath(); FileAccessToken token = null; if (tctx.hasStateCache()) { if (!params.isDirectory()) { FileStateCache cache = tctx.getStateCache(); FileState fstate = tctx.getStateCache().findFileState(params.getPath(), true); token = cache.grantFileAccess(params, fstate, FileStatus.Unknown); if (logger.isDebugEnabled()) { logger.debug("open file created lock token:" + token); } } } try { NetworkFile openFile = diskInterface.openFile(sess, tree, params); if (openFile instanceof ContentNetworkFile) { ContentNetworkFile x = (ContentNetworkFile) openFile; x.setProcessId(params.getProcessId()); x.setAccessToken(token); if (tctx.hasStateCache()) { FileState fstate = tctx.getStateCache().findFileState(path, true); x.setFileState(fstate); fstate.setProcessId(params.getProcessId()); fstate.setSharedAccess(params.getSharedAccess()); fstate.setFileStatus(FileStatus.FileExists); } } if (openFile instanceof TempNetworkFile) { TempNetworkFile x = (TempNetworkFile) openFile; x.setAccessToken(token); // x.setProcessId( params.getProcessId()); if (tctx.hasStateCache()) { FileState fstate = tctx.getStateCache().findFileState(path, true); x.setFileState(fstate); fstate.setFileStatus(FileStatus.FileExists); fstate.setProcessId(params.getProcessId()); fstate.setSharedAccess(params.getSharedAccess()); } } if (openFile instanceof AlfrescoFolder) { AlfrescoFolder x = (AlfrescoFolder) openFile; // x.setProcessId( param.getProcessId()); if (tctx.hasStateCache()) { FileState fstate = tctx.getStateCache().findFileState(path, true); x.setFileState(fstate); fstate.setFileStatus(FileStatus.DirectoryExists); fstate.setProcessId(params.getProcessId()); fstate.setSharedAccess(params.getSharedAccess()); } } return openFile; } catch (IOException ie) { if (logger.isDebugEnabled()) { logger.debug("open file exception caught", ie); } if (tctx.hasStateCache() && token != null) { FileStateCache cache = tctx.getStateCache(); FileState fstate = tctx.getStateCache().findFileState(params.getPath(), false); if (fstate != null) { if (logger.isDebugEnabled()) { logger.debug("open file release lock token:" + token); } cache.releaseFileAccess(fstate, token); } } throw ie; } }
@Override public boolean isReadOnly(SrvSession sess, DeviceContext ctx) throws IOException { return diskInterface.isReadOnly(sess, ctx); }
@Override public void registerContext(DeviceContext ctx) throws DeviceContextException { diskInterface.registerContext(ctx); }
@Override public void createDirectory(SrvSession sess, TreeConnection tree, FileOpenParams params) throws IOException { diskInterface.createDirectory(sess, tree, params); }
@Override public void setFileInformation(SrvSession sess, TreeConnection tree, String name, FileInfo info) throws IOException { diskInterface.setFileInformation(sess, tree, name, info); }
@Override public void deleteDirectory(SrvSession sess, TreeConnection tree, String dir) throws IOException { diskInterface.deleteDirectory(sess, tree, dir); }
@Override public void truncateFile(SrvSession sess, TreeConnection tree, NetworkFile file, long siz) throws IOException { diskInterface.truncateFile(sess, tree, file, siz); }
@Override public void deleteFile(SrvSession sess, TreeConnection tree, String name) throws IOException { diskInterface.deleteFile(sess, tree, name); }
@Override public DeviceContext createContext(String shareName, ConfigElement args) throws DeviceContextException { return diskInterface.createContext(shareName, args); }
@Override public int fileExists(SrvSession sess, TreeConnection tree, String name) { return diskInterface.fileExists(sess, tree, name); }
@Override public NetworkFile createFile(SrvSession sess, TreeConnection tree, FileOpenParams params) throws IOException { ContentContext tctx = (ContentContext) tree.getContext(); FileAccessToken token = null; if (tctx.hasStateCache()) { FileStateCache cache = tctx.getStateCache(); FileState fstate = tctx.getStateCache().findFileState(params.getPath(), true); token = cache.grantFileAccess(params, fstate, FileStatus.NotExist); if (logger.isDebugEnabled()) { logger.debug("create file created lock token:" + token); } } try { NetworkFile newFile = diskInterface.createFile(sess, tree, params); if (tctx.hasStateCache()) { FileState fstate = tctx.getStateCache().findFileState(params.getPath(), true); fstate.setProcessId(params.getProcessId()); fstate.setSharedAccess(params.getSharedAccess()); // Indicate that the file is open fstate.setFileStatus( newFile.isDirectory() ? FileStatus.DirectoryExists : FileStatus.FileExists); fstate.setAllocationSize(params.getAllocationSize()); if (newFile instanceof NodeRefNetworkFile) { NodeRefNetworkFile x = (NodeRefNetworkFile) newFile; x.setFileState(fstate); } if (newFile instanceof TempNetworkFile) { TempNetworkFile x = (TempNetworkFile) newFile; x.setFileState(fstate); } } if (newFile instanceof NodeRefNetworkFile) { NodeRefNetworkFile x = (NodeRefNetworkFile) newFile; x.setProcessId(params.getProcessId()); x.setAccessToken(token); } if (newFile instanceof TempNetworkFile) { TempNetworkFile x = (TempNetworkFile) newFile; x.setAccessToken(token); } return newFile; } catch (IOException ie) { if (logger.isDebugEnabled()) { logger.debug("create file exception caught", ie); } if (tctx.hasStateCache() && token != null) { FileStateCache cache = tctx.getStateCache(); FileState fstate = tctx.getStateCache().findFileState(params.getPath(), false); if (fstate != null && token != null) { if (logger.isDebugEnabled()) { logger.debug("create file release lock token:" + token); } cache.releaseFileAccess(fstate, token); } } throw ie; } }
@Override public int fileExists(SrvSession sess, TreeConnection tree, String path) { int fileExists = diskInterface.fileExists(sess, tree, path); return fileExists; }