From 8bdaffcfe219a6e96c4da7df9d59f6ffa2383a0a Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Mon, 15 Aug 2011 09:49:14 +0000 Subject: [PATCH] Update the file size in the file state cache. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29745 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/BufferedContentDiskDriver.java | 19 ++++++++++-- .../filesys/repo/LegacyFileStateDriver.java | 5 +++ .../filesys/repo/TempNetworkFile.java | 31 ++++++++++++------- .../repo/rules/ScenarioOpenFileInstance.java | 30 +++++++++++------- 4 files changed, 60 insertions(+), 25 deletions(-) diff --git a/source/java/org/alfresco/filesys/repo/BufferedContentDiskDriver.java b/source/java/org/alfresco/filesys/repo/BufferedContentDiskDriver.java index 002655bba5..5035c8f32f 100644 --- a/source/java/org/alfresco/filesys/repo/BufferedContentDiskDriver.java +++ b/source/java/org/alfresco/filesys/repo/BufferedContentDiskDriver.java @@ -226,12 +226,13 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface, if(tctx.hasStateCache()) { FileStateCache cache = tctx.getStateCache(); - FileState fstate = tctx.getStateCache().findFileState(path, false); + FileState fstate = cache.findFileState(path, false); if(fstate != null) { FileInfo finfo = new FileInfo(); finfo.copyFrom(info); - + + // TODO what if file state cache is stale or wrong? We are over-writing the "real" value. if(fstate.hasFileSize()) { finfo.setFileSize(fstate.getFileSize()); @@ -253,9 +254,23 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface, finfo.setAllocationSize( fstate.getAllocationSize()); } + if(logger.isDebugEnabled()) + { + logger.debug("getFileInformation path" + path + ", returning:" + finfo + + ", readOnly:"+info.isReadOnly() + + ", fileId:"+info.getFileId() + + ", directoryId:" + info.getDirectoryId() + + ", mode" + info.getMode()); + } + return finfo; } } + + if(logger.isDebugEnabled()) + { + logger.debug("getFileInformation returning:" + path + " returning" + info); + } return info; diff --git a/source/java/org/alfresco/filesys/repo/LegacyFileStateDriver.java b/source/java/org/alfresco/filesys/repo/LegacyFileStateDriver.java index f7a8997d6d..70ae43eba7 100644 --- a/source/java/org/alfresco/filesys/repo/LegacyFileStateDriver.java +++ b/source/java/org/alfresco/filesys/repo/LegacyFileStateDriver.java @@ -198,6 +198,7 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface FileState fstate = tctx.getStateCache().findFileState( path, true); x.setFileState(fstate); fstate.setProcessId(params.getProcessId()); + fstate.setSharedAccess( params.getSharedAccess()); fstate.setFileStatus(FileStatus.FileExists); } } @@ -212,6 +213,8 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface FileState fstate = tctx.getStateCache().findFileState( path, true); x.setFileState(fstate); fstate.setFileStatus(FileStatus.FileExists); + fstate.setProcessId(params.getProcessId()); + fstate.setSharedAccess( params.getSharedAccess()); } } @@ -224,6 +227,8 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface FileState fstate = tctx.getStateCache().findFileState( path, true); x.setFileState(fstate); fstate.setFileStatus(FileStatus.DirectoryExists); + fstate.setProcessId(params.getProcessId()); + fstate.setSharedAccess( params.getSharedAccess()); } } diff --git a/source/java/org/alfresco/filesys/repo/TempNetworkFile.java b/source/java/org/alfresco/filesys/repo/TempNetworkFile.java index 69bfed41d9..df1d7274bb 100644 --- a/source/java/org/alfresco/filesys/repo/TempNetworkFile.java +++ b/source/java/org/alfresco/filesys/repo/TempNetworkFile.java @@ -67,39 +67,46 @@ public class TempNetworkFile extends JavaNetworkFile implements NetworkFileState @Override public void writeFile(byte[] buf, int len, int pos) throws IOException { + + super.writeFile(buf, len, pos); + + long size = m_io.length(); + + setFileSize(size); if(fileState != null) { fileState.updateModifyDateTime(); + fileState.setFileSize(size); } - super.writeFile(buf, len, pos); - - setFileSize(m_io.length()); } @Override public void writeFile(byte[] buffer, int length, int position, long fileOffset) throws IOException { - if(fileState != null) - { - fileState.updateModifyDateTime(); - } super.writeFile(buffer, length, position, fileOffset); - setFileSize(m_io.length()); + long size = m_io.length(); + setFileSize(size); + if(fileState != null) + { + fileState.updateModifyDateTime(); + fileState.setFileSize(size); + } } @Override public void truncateFile(long size) throws IOException { - if(fileState != null) - { - fileState.updateModifyDateTime(); - } super.truncateFile(size); setFileSize(size); + if(fileState != null) + { + fileState.updateModifyDateTime(); + fileState.setFileSize(size); + } } // For JLAN file state lock manager diff --git a/source/java/org/alfresco/filesys/repo/rules/ScenarioOpenFileInstance.java b/source/java/org/alfresco/filesys/repo/rules/ScenarioOpenFileInstance.java index 89faa0c3b8..4132ee5fdf 100644 --- a/source/java/org/alfresco/filesys/repo/rules/ScenarioOpenFileInstance.java +++ b/source/java/org/alfresco/filesys/repo/rules/ScenarioOpenFileInstance.java @@ -150,21 +150,28 @@ class ScenarioOpenFileInstance implements ScenarioInstance { CreateFileOperation c = (CreateFileOperation)operation; name = c.getName(); - ArrayList commands = new ArrayList(); - ArrayList postCommitCommands = new ArrayList(); - commands.add(new CreateFileCommand(c.getName(), c.getRootNodeRef(), c.getPath())); - postCommitCommands.add(newOpenFileCallbackCommand()); - return new CompoundCommand(commands, postCommitCommands); + + if(name != null) + { + ArrayList commands = new ArrayList(); + ArrayList postCommitCommands = new ArrayList(); + commands.add(new CreateFileCommand(c.getName(), c.getRootNodeRef(), c.getPath())); + postCommitCommands.add(newOpenFileCallbackCommand()); + return new CompoundCommand(commands, postCommitCommands); + } } else if(operation instanceof OpenFileOperation) { OpenFileOperation o = (OpenFileOperation)operation; name = o.getName(); - ArrayList commands = new ArrayList(); - commands.add(new OpenFileCommand(o.getName(), o.getMode(), o.isTruncate(), o.getRootNodeRef(), o.getPath())); - ArrayList postCommitCommands = new ArrayList(); - postCommitCommands.add(newOpenFileCallbackCommand()); - return new CompoundCommand(commands, postCommitCommands); + if(name != null) + { + ArrayList commands = new ArrayList(); + commands.add(new OpenFileCommand(o.getName(), o.getMode(), o.isTruncate(), o.getRootNodeRef(), o.getPath())); + ArrayList postCommitCommands = new ArrayList(); + postCommitCommands.add(newOpenFileCallbackCommand()); + return new CompoundCommand(commands, postCommitCommands); + } } // Scenario Not Started @@ -297,7 +304,7 @@ class ScenarioOpenFileInstance implements ScenarioInstance return null; } - if(name.equalsIgnoreCase(o.getName())) + if(name != null && name.equalsIgnoreCase(o.getName())) { if(o.getMode() == OpenFileMode.WRITE) { @@ -313,6 +320,7 @@ class ScenarioOpenFileInstance implements ScenarioInstance } else { + // TODO Need a permission check here and increment post check openReadWriteCount++; logger.debug("Return already open read/write file handle from scenario:" + this); return new ReturnValueCommand(fileHandleReadWrite);