diff --git a/source/java/org/alfresco/filesys/FTPServerTest.java b/source/java/org/alfresco/filesys/FTPServerTest.java index 667073a74f..3790634259 100644 --- a/source/java/org/alfresco/filesys/FTPServerTest.java +++ b/source/java/org/alfresco/filesys/FTPServerTest.java @@ -317,7 +317,7 @@ public class FTPServerTest extends TestCase * * @throws Exception */ - public void DISABLED_testCRUD() throws Exception + public void testCRUD() throws Exception { final String PATH1 = "FTPServerTest"; final String PATH2 = "Second part"; @@ -413,7 +413,7 @@ public class FTPServerTest extends TestCase * * So we need to check how high characters and problematic are encoded */ - public void DISABLED_testPathNames() throws Exception + public void testPathNames() throws Exception { logger.debug("Start testPathNames"); @@ -491,7 +491,7 @@ public class FTPServerTest extends TestCase * * @throws Exception */ - public void DISABLED_testTwoUserUpdate() throws Exception + public void testTwoUserUpdate() throws Exception { logger.debug("Start testFTPConnect"); diff --git a/source/java/org/alfresco/filesys/repo/BufferedContentDiskDriver.java b/source/java/org/alfresco/filesys/repo/BufferedContentDiskDriver.java index 8827140416..264fbeb07b 100644 --- a/source/java/org/alfresco/filesys/repo/BufferedContentDiskDriver.java +++ b/source/java/org/alfresco/filesys/repo/BufferedContentDiskDriver.java @@ -47,10 +47,8 @@ import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.node.NodeServicePolicies; import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.PolicyComponent; +import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; import org.alfresco.util.PropertyCheck; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -160,8 +158,9 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface, public FileInfo getFileInformation(SrvSession sess, TreeConnection tree, String path) throws IOException { - String userName = sess.getClientInformation().getUserName(); - + + String userName = AuthenticationUtil.getFullyAuthenticatedUser(); + if(logger.isDebugEnabled()) { logger.debug("getFileInformation userName:" + userName + ", path:" + path); @@ -208,8 +207,9 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface, @Override public int fileExists(SrvSession sess, TreeConnection tree, String path) { - String userName = sess.getClientInformation().getUserName(); - + + String userName = AuthenticationUtil.getFullyAuthenticatedUser(); + if(logger.isDebugEnabled()) { logger.debug("fileExists userName:" + userName + ", path:" + path); diff --git a/source/java/org/alfresco/filesys/repo/CifsHelper.java b/source/java/org/alfresco/filesys/repo/CifsHelper.java index 041d35f1d4..e130023e49 100644 --- a/source/java/org/alfresco/filesys/repo/CifsHelper.java +++ b/source/java/org/alfresco/filesys/repo/CifsHelper.java @@ -515,6 +515,9 @@ public class CifsHelper /** * Attempts to fetch a specific single node at the given path. + *
+ * The path may contain wild cards + *
* * @throws FileNotFoundException if the path can't be resolved to a node * diff --git a/source/java/org/alfresco/filesys/repo/ContentDiskDriver2.java b/source/java/org/alfresco/filesys/repo/ContentDiskDriver2.java index 2d39e6a499..373d0ff6c3 100644 --- a/source/java/org/alfresco/filesys/repo/ContentDiskDriver2.java +++ b/source/java/org/alfresco/filesys/repo/ContentDiskDriver2.java @@ -1336,17 +1336,32 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD try { - // get the device root - - NodeRef deviceRootNodeRef = ctx.getRootNode(); - + NodeRef dirNodeRef; + String folderName; + String path = params.getPath(); - String parentPath = null; - // If the state table is available then try to find the parent folder node for the new folder - // to save having to walk the path + String[] paths = FileName.splitPath(path); + + if (paths[0] != null && paths[0].length() > 1) + { + // lookup parent directory + dirNodeRef = getNodeForPath(tree, paths[0]); + folderName = paths[1]; + } + else + { + dirNodeRef = ctx.getRootNode(); + folderName = path; + } + + if(dirNodeRef == null) + { + throw new IOException("Create directory parent folder not found" + params.getFullPath()); + } + + NodeRef nodeRef = getCifsHelper().createNode(dirNodeRef, folderName, ContentModel.TYPE_FOLDER); - NodeRef nodeRef = getCifsHelper().createNode(deviceRootNodeRef, path, ContentModel.TYPE_FOLDER); if (logger.isDebugEnabled()) { @@ -2037,14 +2052,13 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD if (logger.isDebugEnabled()) { - logger.debug("truncateFile file=" + file); + logger.debug("truncateFile file:" + file + ", size: "+ size); } long allocSize = 0L; long releaseSize = 0L; // Check if there is a quota manager - QuotaManager quotaMgr = ctx.getQuotaManager(); if ( ctx.hasQuotaManager()) { @@ -2058,6 +2072,10 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD { contentFile.openContent( false, false); } + } + else if( file instanceof TempNetworkFile) + { + } else { @@ -2079,10 +2097,9 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD else { - // Calculate the space to be released as the file is to be truncated, release the space if - // the file truncation is successful - - releaseSize = file.getFileSize() - size; + // Calculate the space to be released as the file is to be truncated, release the space if + // the file truncation is successful + releaseSize = file.getFileSize() - size; } } @@ -2091,11 +2108,22 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD if ( file instanceof ContentNetworkFile) { // Get the cached state for the file - ContentNetworkFile contentFile = (ContentNetworkFile) file; FileState fstate = contentFile.getFileState(); if ( fstate != null && size > fstate.getAllocationSize()) - fstate.setAllocationSize( size); + { + fstate.setAllocationSize(size); + } + } + + if( file instanceof TempNetworkFile) + { + TempNetworkFile contentFile = (TempNetworkFile) file; + FileState fstate = contentFile.getFileState(); + if ( fstate != null && size > fstate.getAllocationSize()) + { + fstate.setAllocationSize(size); + } } // Set the file length @@ -2106,14 +2134,14 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD } catch (IOException ex) { - // Check if we allocated space to the file if ( allocSize > 0 && quotaMgr != null) + { quotaMgr.releaseSpace(sess, tree, file.getFileId(), null, allocSize); + } - // Rethrow the exception - + // Rethrow the exception throw ex; } @@ -2303,14 +2331,8 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD */ private NodeRef getNodeForPath(TreeConnection tree, String path) throws FileNotFoundException - { - if(logger.isDebugEnabled()) - { - logger.debug("getNodeRefForPath:" + path); - } - - ContentContext ctx = (ContentContext) tree.getContext(); - + { + ContentContext ctx = (ContentContext) tree.getContext(); return getCifsHelper().getNodeRef(ctx.getRootNode(), path); } @@ -3156,11 +3178,24 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD try { - // Get the device root - - NodeRef deviceRootNodeRef = rootNode; - - NodeRef nodeRef = cifsHelper.createNode(deviceRootNodeRef, path, ContentModel.TYPE_CONTENT); + 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; + } + + NodeRef nodeRef = cifsHelper.createNode(dirNodeRef, folderName, ContentModel.TYPE_CONTENT); nodeService.addAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT, null); @@ -3302,44 +3337,48 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD TempNetworkFile tempFile =(TempNetworkFile)file; - tempFile.flushFile(); - tempFile.close(); - - // Take an initial guess at the mimetype (if it has not been set by something already) - String mimetype = mimetypeService.guessMimetype(tempFile.getFullName(), new FileContentReader(tempFile.getFile())); - logger.debug("guesssed mimetype:" + mimetype); - - String encoding; - // Take a guess at the locale - InputStream is = new BufferedInputStream(new FileInputStream(tempFile.getFile())); - try + if(tempFile.getWriteCount() > 0) { - ContentCharsetFinder charsetFinder = mimetypeService.getContentCharsetFinder(); - Charset charset = charsetFinder.getCharset(is, mimetype); - encoding = charset.name(); - } - finally - { - if(is != null) + // Some content was written to the temp file. + tempFile.flushFile(); + tempFile.close(); + + // Take an initial guess at the mimetype (if it has not been set by something already) + String mimetype = mimetypeService.guessMimetype(tempFile.getFullName(), new FileContentReader(tempFile.getFile())); + logger.debug("guesssed mimetype:" + mimetype); + + String encoding; + // Take a guess at the locale + InputStream is = new BufferedInputStream(new FileInputStream(tempFile.getFile())); + try { - is.close(); + ContentCharsetFinder charsetFinder = mimetypeService.getContentCharsetFinder(); + Charset charset = charsetFinder.getCharset(is, mimetype); + encoding = charset.name(); + } + finally + { + if(is != null) + { + is.close(); + } } - } - NodeRef target = getCifsHelper().getNodeRef(rootNode, tempFile.getFullName()); - ContentWriter writer = contentService.getWriter(target, ContentModel.PROP_CONTENT, true); - writer.setMimetype(mimetype); - writer.setEncoding(encoding); - writer.putContent(tempFile.getFile()); + NodeRef target = getCifsHelper().getNodeRef(rootNode, tempFile.getFullName()); + ContentWriter writer = contentService.getWriter(target, ContentModel.PROP_CONTENT, true); + writer.setMimetype(mimetype); + writer.setEncoding(encoding); + writer.putContent(tempFile.getFile()); - long size = writer.getSize(); - if(nodeService.hasAspect(target, ContentModel.ASPECT_NO_CONTENT) && size > 0) - { - if(logger.isDebugEnabled()) + long size = writer.getSize(); + if(nodeService.hasAspect(target, ContentModel.ASPECT_NO_CONTENT) && size > 0) { - logger.debug("removed no content aspect"); + if(logger.isDebugEnabled()) + { + logger.debug("removed no content aspect"); + } + nodeService.removeAspect(target, ContentModel.ASPECT_NO_CONTENT); } - nodeService.removeAspect(target, ContentModel.ASPECT_NO_CONTENT); } } @@ -3362,20 +3401,19 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD } } } - // Make sure we clean up before propagating exceptions catch (IOException e) { if ( logger.isDebugEnabled()) { - logger.debug("Exception in closeFile - ", e); + logger.debug("Exception in closeFile - path:" + path, e); } - throw e; + throw new IOException("Unable to closeFile :" + path + e.toString(), e); } catch (Error e) { if ( logger.isDebugEnabled()) { - logger.debug("Exception in closeFile - ", e); + logger.debug("Exception in closeFile - path:" + path, e); } throw e; diff --git a/source/java/org/alfresco/filesys/repo/ContentDiskDriverTest.java b/source/java/org/alfresco/filesys/repo/ContentDiskDriverTest.java index 82cfd44bb8..826d54f900 100644 --- a/source/java/org/alfresco/filesys/repo/ContentDiskDriverTest.java +++ b/source/java/org/alfresco/filesys/repo/ContentDiskDriverTest.java @@ -233,7 +233,7 @@ public class ContentDiskDriverTest extends TestCase int openAction = FileAction.CreateNotExist; - final String FILE_NAME="testCreateFile.new"; + final String FILE_NAME="testCreateFileA.new"; final String FILE_PATH="\\"+FILE_NAME; FileOpenParams params = new FileOpenParams(FILE_PATH, openAction, AccessMode.ReadWrite, FileAttribute.NTNormal, 0); @@ -248,7 +248,7 @@ public class ContentDiskDriverTest extends TestCase public Void execute() throws Throwable { byte[] stuff = "Hello World".getBytes(); - driver.writeFile(testSession, testConnection, file, stuff, stuff.length, 0, 0); + driver.writeFile(testSession, testConnection, file, stuff, 0, stuff.length, 0); driver.closeFile(testSession, testConnection, file); return null; } @@ -3013,6 +3013,127 @@ public class ContentDiskDriverTest extends TestCase } // testOpenCloseFileScenario + + /** + * Unit test of open read/write close versionable file - should not do anything. + *
+ * This is done with a CIFS shuffle from word. Basically Word holds the file open with a read/write lock while the + * shuffle is going on. + *
+ * Create a file.
+ * Apply versionable aspect
+ * Open the file ReadWrite + OpLocks
+ * Close the file
+ * Check Version has not incremented.
+ */
+ public void testOpenCloseVersionableFile() throws Exception
+ {
+ logger.debug("testOpenCloseVersionableFile");
+
+ ServerConfiguration scfg = new ServerConfiguration("testServer");
+ TestServer testServer = new TestServer("testServer", scfg);
+ SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
+ DiskSharedDevice share = getDiskSharedDevice();
+ final TreeConnection testConnection = testServer.getTreeConnection(share);
+
+ final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
+
+ final String FILE_PATH1=TEST_ROOT_DOS_PATH + "\\OpenCloseFile.new";
+
+ class TestContext
+ {
+ };
+
+ final TestContext testContext = new TestContext();
+
+ FileOpenParams dirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadOnly, FileAttribute.NTDirectory, 0);
+ driver.createDirectory(testSession, testConnection, dirParams);
+
+ FileOpenParams params1 = new FileOpenParams(FILE_PATH1, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
+ NetworkFile file1 = driver.createFile(testSession, testConnection, params1);
+ driver.closeFile(testSession, testConnection, file1);
+
+ /**
+ * Make Node 1 versionable
+ */
+ RetryingTransactionCallback