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
This commit is contained in:
Mark Rogers
2011-08-15 09:49:14 +00:00
parent 5ddbcc938d
commit 8bdaffcfe2
4 changed files with 60 additions and 25 deletions

View File

@@ -226,12 +226,13 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface,
if(tctx.hasStateCache()) if(tctx.hasStateCache())
{ {
FileStateCache cache = tctx.getStateCache(); FileStateCache cache = tctx.getStateCache();
FileState fstate = tctx.getStateCache().findFileState(path, false); FileState fstate = cache.findFileState(path, false);
if(fstate != null) if(fstate != null)
{ {
FileInfo finfo = new FileInfo(); FileInfo finfo = new FileInfo();
finfo.copyFrom(info); finfo.copyFrom(info);
// TODO what if file state cache is stale or wrong? We are over-writing the "real" value.
if(fstate.hasFileSize()) if(fstate.hasFileSize())
{ {
finfo.setFileSize(fstate.getFileSize()); finfo.setFileSize(fstate.getFileSize());
@@ -253,10 +254,24 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface,
finfo.setAllocationSize( fstate.getAllocationSize()); 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; return finfo;
} }
} }
if(logger.isDebugEnabled())
{
logger.debug("getFileInformation returning:" + path + " returning" + info);
}
return info; return info;
} }

View File

@@ -198,6 +198,7 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface
FileState fstate = tctx.getStateCache().findFileState( path, true); FileState fstate = tctx.getStateCache().findFileState( path, true);
x.setFileState(fstate); x.setFileState(fstate);
fstate.setProcessId(params.getProcessId()); fstate.setProcessId(params.getProcessId());
fstate.setSharedAccess( params.getSharedAccess());
fstate.setFileStatus(FileStatus.FileExists); fstate.setFileStatus(FileStatus.FileExists);
} }
} }
@@ -212,6 +213,8 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface
FileState fstate = tctx.getStateCache().findFileState( path, true); FileState fstate = tctx.getStateCache().findFileState( path, true);
x.setFileState(fstate); x.setFileState(fstate);
fstate.setFileStatus(FileStatus.FileExists); 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); FileState fstate = tctx.getStateCache().findFileState( path, true);
x.setFileState(fstate); x.setFileState(fstate);
fstate.setFileStatus(FileStatus.DirectoryExists); fstate.setFileStatus(FileStatus.DirectoryExists);
fstate.setProcessId(params.getProcessId());
fstate.setSharedAccess( params.getSharedAccess());
} }
} }

View File

@@ -67,39 +67,46 @@ public class TempNetworkFile extends JavaNetworkFile implements NetworkFileState
@Override @Override
public void writeFile(byte[] buf, int len, int pos) throws IOException 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) if(fileState != null)
{ {
fileState.updateModifyDateTime(); fileState.updateModifyDateTime();
fileState.setFileSize(size);
} }
super.writeFile(buf, len, pos);
setFileSize(m_io.length());
} }
@Override @Override
public void writeFile(byte[] buffer, int length, int position, long fileOffset) public void writeFile(byte[] buffer, int length, int position, long fileOffset)
throws IOException throws IOException
{ {
if(fileState != null)
{
fileState.updateModifyDateTime();
}
super.writeFile(buffer, length, position, fileOffset); 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 @Override
public void truncateFile(long size) throws IOException public void truncateFile(long size) throws IOException
{ {
if(fileState != null)
{
fileState.updateModifyDateTime();
}
super.truncateFile(size); super.truncateFile(size);
setFileSize(size); setFileSize(size);
if(fileState != null)
{
fileState.updateModifyDateTime();
fileState.setFileSize(size);
}
} }
// For JLAN file state lock manager // For JLAN file state lock manager

View File

@@ -150,22 +150,29 @@ class ScenarioOpenFileInstance implements ScenarioInstance
{ {
CreateFileOperation c = (CreateFileOperation)operation; CreateFileOperation c = (CreateFileOperation)operation;
name = c.getName(); name = c.getName();
if(name != null)
{
ArrayList<Command> commands = new ArrayList<Command>(); ArrayList<Command> commands = new ArrayList<Command>();
ArrayList<Command> postCommitCommands = new ArrayList<Command>(); ArrayList<Command> postCommitCommands = new ArrayList<Command>();
commands.add(new CreateFileCommand(c.getName(), c.getRootNodeRef(), c.getPath())); commands.add(new CreateFileCommand(c.getName(), c.getRootNodeRef(), c.getPath()));
postCommitCommands.add(newOpenFileCallbackCommand()); postCommitCommands.add(newOpenFileCallbackCommand());
return new CompoundCommand(commands, postCommitCommands); return new CompoundCommand(commands, postCommitCommands);
} }
}
else if(operation instanceof OpenFileOperation) else if(operation instanceof OpenFileOperation)
{ {
OpenFileOperation o = (OpenFileOperation)operation; OpenFileOperation o = (OpenFileOperation)operation;
name = o.getName(); name = o.getName();
if(name != null)
{
ArrayList<Command> commands = new ArrayList<Command>(); ArrayList<Command> commands = new ArrayList<Command>();
commands.add(new OpenFileCommand(o.getName(), o.getMode(), o.isTruncate(), o.getRootNodeRef(), o.getPath())); commands.add(new OpenFileCommand(o.getName(), o.getMode(), o.isTruncate(), o.getRootNodeRef(), o.getPath()));
ArrayList<Command> postCommitCommands = new ArrayList<Command>(); ArrayList<Command> postCommitCommands = new ArrayList<Command>();
postCommitCommands.add(newOpenFileCallbackCommand()); postCommitCommands.add(newOpenFileCallbackCommand());
return new CompoundCommand(commands, postCommitCommands); return new CompoundCommand(commands, postCommitCommands);
} }
}
// Scenario Not Started // Scenario Not Started
isComplete = true; isComplete = true;
@@ -297,7 +304,7 @@ class ScenarioOpenFileInstance implements ScenarioInstance
return null; return null;
} }
if(name.equalsIgnoreCase(o.getName())) if(name != null && name.equalsIgnoreCase(o.getName()))
{ {
if(o.getMode() == OpenFileMode.WRITE) if(o.getMode() == OpenFileMode.WRITE)
{ {
@@ -313,6 +320,7 @@ class ScenarioOpenFileInstance implements ScenarioInstance
} }
else else
{ {
// TODO Need a permission check here and increment post check
openReadWriteCount++; openReadWriteCount++;
logger.debug("Return already open read/write file handle from scenario:" + this); logger.debug("Return already open read/write file handle from scenario:" + this);
return new ReturnValueCommand(fileHandleReadWrite); return new ReturnValueCommand(fileHandleReadWrite);