ALF-10941 - CIFS Open file from excel

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32068 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2011-11-17 17:32:37 +00:00
parent 9a49808cf8
commit 2c4b046ba6
11 changed files with 116 additions and 186 deletions

View File

@@ -48,9 +48,10 @@ public interface RepositoryDiskInterface
* @param rootNode * @param rootNode
* @param fromPath - the source node * @param fromPath - the source node
* @param toPath - the target node * @param toPath - the target node
* @param allocationSize size to allocate for new file
* @throws FileNotFoundException * @throws FileNotFoundException
*/ */
public NetworkFile createFile(NodeRef rootNode, String Path) throws IOException; public NetworkFile createFile(NodeRef rootNode, String Path, long allocationSize) throws IOException;
/** /**
* CloseFile. * CloseFile.

View File

@@ -236,7 +236,8 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface,
FileInfo info = getFileInformationInternal(sess, tree, path); FileInfo info = getFileInformationInternal(sess, tree, path);
/* /*
* Some information is not maintained by the repo * Some information is not maintained by the repo and represents an in-progress update.
* For example as a file is being written the modification and access dates change.
*/ */
if(tctx.hasStateCache()) if(tctx.hasStateCache())
{ {
@@ -246,64 +247,75 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface,
{ {
if(logger.isDebugEnabled()) if(logger.isDebugEnabled())
{ {
logger.debug("state cache available - overwriting from state cache"); logger.debug("state cache available - overwriting from state cache: isDirectory=" +info.isDirectory());
} }
FileInfo finfo = new FileInfo(); FileInfo finfo = new FileInfo();
finfo.copyFrom(info); finfo.copyFrom(info);
/* /**
* TODO what if file state cache is stale? * File state is probably stale for directories which is why we don't attempt to
* We are over-writing the "real" value here. * cache.
*/ */
if(fstate.hasFileSize()) if(!info.isDirectory())
{ {
if(logger.isDebugEnabled()) /*
* What about stale file state values here?
*/
if(fstate.hasFileSize())
{ {
logger.debug("replace file size " + info.getSize() + " with " + fstate.getFileSize()); if(logger.isDebugEnabled())
{
logger.debug("replace file size " + info.getSize() + " with " + fstate.getFileSize());
}
finfo.setFileSize(fstate.getFileSize());
} }
finfo.setFileSize(fstate.getFileSize()); if ( fstate.hasAccessDateTime())
}
if ( fstate.hasAccessDateTime())
{
if(logger.isDebugEnabled())
{ {
logger.debug("replace access date " + new Date(finfo.getAccessDateTime()) + " with " + new Date(fstate.getAccessDateTime())); if(logger.isDebugEnabled())
{
logger.debug("replace access date " + new Date(finfo.getAccessDateTime()) + " with " + new Date(fstate.getAccessDateTime()));
}
finfo.setAccessDateTime(fstate.getAccessDateTime());
} }
finfo.setAccessDateTime(fstate.getAccessDateTime()); if ( fstate.hasChangeDateTime())
}
if ( fstate.hasChangeDateTime())
{
if(logger.isDebugEnabled())
{ {
logger.debug("replace change date " + new Date(finfo.getChangeDateTime()) + " with " + new Date(fstate.getChangeDateTime())); if(logger.isDebugEnabled())
{
logger.debug("replace change date " + new Date(finfo.getChangeDateTime()) + " with " + new Date(fstate.getChangeDateTime()));
}
finfo.setChangeDateTime(fstate.getChangeDateTime());
} }
finfo.setChangeDateTime(fstate.getChangeDateTime()); if ( fstate.hasModifyDateTime())
}
if ( fstate.hasModifyDateTime())
{
if(logger.isDebugEnabled())
{ {
logger.debug("replace modified date " + new Date(finfo.getModifyDateTime()) + " with " + new Date(fstate.getModifyDateTime())); if(logger.isDebugEnabled())
{
logger.debug("replace modified date " + new Date(finfo.getModifyDateTime()) + " with " + new Date(fstate.getModifyDateTime()));
}
finfo.setModifyDateTime(fstate.getModifyDateTime());
}
if ( fstate.hasAllocationSize())
{
if(logger.isDebugEnabled())
{
logger.debug("replace allocation size" + finfo.getAllocationSize() + " with " + fstate.getAllocationSize());
}
finfo.setAllocationSize(fstate.getAllocationSize());
} }
finfo.setModifyDateTime(fstate.getModifyDateTime());
} }
// if ( fstate.hasAllocationSize() && fstate.getAllocationSize() > info.getAllocationSize())
// {
// finfo.setAllocationSize( fstate.getAllocationSize());
// }
if(logger.isDebugEnabled()) if(logger.isDebugEnabled())
{ {
logger.debug("getFileInformation path" + path + ", returning:" + finfo + logger.debug("getFileInformation path" + path + ", returning:" + finfo +
", readOnly:" +finfo.isReadOnly() + ", readOnly:" +finfo.isReadOnly() +
", fileId:" +finfo.getFileId() + ", fileId:" +finfo.getFileId() +
", fileSize:" +finfo.getSize() +
", directoryId:" + finfo.getDirectoryId() + ", directoryId:" + finfo.getDirectoryId() +
", createdDate: " + finfo.getCreationDateTime() + ", createdDate: " + finfo.getCreationDateTime() +
", accessDate:" + new Date(finfo.getAccessDateTime()) + ", accessDate:" + new Date(finfo.getAccessDateTime()) +
", modifiedDate:" + new Date(finfo.getModifyDateTime()) + ", modifiedDate:" + new Date(finfo.getModifyDateTime()) +
", changeDate:" + new Date(finfo.getChangeDateTime()) + ", changeDate:" + new Date(finfo.getChangeDateTime()) +
", mode" + finfo.getMode()); ", fileAttributes: 0x"+ Integer.toHexString(info.getFileAttributes()) +
", mode: 0x" + Integer.toHexString(finfo.getMode()));
} }
return finfo; return finfo;
@@ -414,6 +426,14 @@ public class BufferedContentDiskDriver implements ExtendedDiskInterface,
NetworkFile param) throws IOException NetworkFile param) throws IOException
{ {
diskInterface.closeFile(sess, tree, param); diskInterface.closeFile(sess, tree, param);
/**
* If the fileInfo cache may have just had some content updated.
*/
if(!param.isDirectory() && !param.isReadOnly())
{
fileInfoCache.clear();
}
} }
@Override @Override

View File

@@ -33,6 +33,7 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.jlan.server.filesys.FileAttribute; import org.alfresco.jlan.server.filesys.FileAttribute;
import org.alfresco.jlan.server.filesys.FileExistsException; import org.alfresco.jlan.server.filesys.FileExistsException;
import org.alfresco.jlan.server.filesys.FileName; import org.alfresco.jlan.server.filesys.FileName;
import org.alfresco.jlan.server.filesys.FileType;
import org.alfresco.jlan.util.WildCard; import org.alfresco.jlan.util.WildCard;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.model.filefolder.FileFolderServiceImpl; import org.alfresco.repo.model.filefolder.FileFolderServiceImpl;
@@ -212,6 +213,7 @@ public class CifsHelper
// add directory attribute // add directory attribute
fileAttributes |= FileAttribute.Directory; fileAttributes |= FileAttribute.Directory;
fileInfo.setFileAttributes(fileAttributes); fileInfo.setFileAttributes(fileAttributes);
fileInfo.setFileType(FileType.Directory);
} }
else else
{ {

View File

@@ -196,7 +196,7 @@ public class CommandExecutorImpl implements CommandExecutor
{ {
logger.debug("create file command"); logger.debug("create file command");
CreateFileCommand create = (CreateFileCommand)command; CreateFileCommand create = (CreateFileCommand)command;
return repositoryDiskInterface.createFile(create.getRootNode(), create.getPath()); return repositoryDiskInterface.createFile(create.getRootNode(), create.getPath(), create.getAllocationSize());
} }
else if(command instanceof DeleteFileCommand) else if(command instanceof DeleteFileCommand)
{ {

View File

@@ -1035,14 +1035,6 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
logger.debug("open file for read only"); logger.debug("open file for read only");
netFile = ContentNetworkFile.createFile(nodeService, contentService, mimetypeService, getCifsHelper(), nodeRef, params, session); netFile = ContentNetworkFile.createFile(nodeService, contentService, mimetypeService, getCifsHelper(), nodeRef, params, session);
if(!netFile.isReadOnly())
{
logger.debug("work around");
// Bug work around fix for read only stuff
int attrib = netFile.getFileAttributes();
attrib = attrib + FileAttribute.ReadOnly;
netFile.setAttributes(attrib);
}
} }
else if(params.isReadWriteAccess()) else if(params.isReadWriteAccess())
{ {
@@ -1237,7 +1229,6 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
/** /**
* Create a new file on the file system. * Create a new file on the file system.
* *
*
* @param sess Server session * @param sess Server session
* @param tree Tree connection * @param tree Tree connection
* @param params File create parameters * @param params File create parameters
@@ -1246,130 +1237,8 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
*/ */
public NetworkFile createFile(SrvSession sess, final TreeConnection tree, final FileOpenParams params) throws IOException public NetworkFile createFile(SrvSession sess, final TreeConnection tree, final FileOpenParams params) throws IOException
{ {
// Obsolete
return null; return null;
// final ContentContext ctx = (ContentContext) tree.getContext();
//
// if (logger.isDebugEnabled())
// {
// logger.debug("createFile :" + params);
// }
//
// try
// {
// // Get the device root
//
// NodeRef deviceRootNodeRef = ctx.getRootNode();
//
// String path = params.getPath();
// //String parentPath = path;
//
// // MER NEW CODE BELOW
// //NodeRef parentNodeRef = cifsHelper.getNodeRef(deviceRootNodeRef, parentPath);
//
// // TODO Check whether node already exists
//
// // TODO Check permissions to create new node
// //ContentWriter writer = contentService.getTempWriter();
//
// //File file = TempFileProvider.createTempFile("cifs", ".bin");
//
// //TempNetworkFile netFile = new TempNetworkFile(file, path);
//
// //netFile.setFileId(12345);
//
// //tempFiles.put(path, netFile);
//
// //if(logger.isDebugEnabled())
// //{
// // logger.debug("temp network file created:" + file);
// //}
// // MER NEW CODE ABOVE
//
// NodeRef nodeRef = cifsHelper.createNode(deviceRootNodeRef, path, ContentModel.TYPE_CONTENT);
//
// nodeService.addAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT, null);
//
// // Create the network file
//
// ContentNetworkFile netFile = ContentNetworkFile.createFile(nodeService, contentService, mimetypeService, getCifsHelper(), nodeRef, params, sess);
//
// // Always allow write access to a newly created file
//
// netFile.setGrantedAccess(NetworkFile.READWRITE);
//
// // Set the owner process id for this open file
//
// netFile.setProcessId( params.getProcessId());
//
// // Truncate the file so that the content stream is created
// netFile.truncateFile( 0L);
//
// // Generate a file id for the file
//
// if ( netFile != null)
// {
// long id = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(netFile.getNodeRef(), ContentModel.PROP_NODE_DBID));
// netFile.setFileId((int) (id & 0xFFFFFFFFL));
// }
//
// if (logger.isDebugEnabled())
// {
// logger.debug("Created file: path=" + params.getPath() + " file open parameters=" + params + " node=" + nodeRef + " network file=" + netFile);
// }
//
// // Return the new network file
//
// return netFile;
// }
// catch (org.alfresco.repo.security.permissions.AccessDeniedException ex)
// {
// // Debug
//
// if ( logger.isDebugEnabled())
// {
// logger.debug("Create file - access denied, " + params.getFullPath());
// }
//
// // Convert to a filesystem access denied status
//
// throw new AccessDeniedException("Unable to create file " + params.getFullPath());
// }
// catch (IOException ex)
// {
// // Debug
//
// if ( logger.isDebugEnabled())
// {
// logger.debug("Create file - content I/O error, " + params.getFullPath());
// }
//
// throw ex;
// }
// catch (ContentIOException ex)
// {
// // Debug
//
// if ( logger.isDebugEnabled())
// {
// logger.debug("Create file - content I/O error, " + params.getFullPath());
// }
// // Convert to a filesystem disk full status
//
// throw new DiskFullException("Unable to create file " + params.getFullPath());
// }
// catch (AlfrescoRuntimeException ex)
// {
// // Debug
//
// if ( logger.isDebugEnabled())
// {
// logger.debug("Create file error", ex);
// }
//
// // Convert to a general I/O exception
//
// throw new IOException("Unable to create file " + params.getFullPath(), ex);
// }
} }
/** /**
@@ -2699,7 +2568,7 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
} }
@Override @Override
public NetworkFile createFile(NodeRef rootNode, String path) public NetworkFile createFile(NodeRef rootNode, String path, long allocationSize)
throws IOException throws IOException
{ {
@@ -2742,9 +2611,8 @@ public class ContentDiskDriver2 extends AlfrescoDiskDriver implements ExtendedD
// Always allow write access to a newly created file // Always allow write access to a newly created file
netFile.setGrantedAccess(NetworkFile.READWRITE); netFile.setGrantedAccess(NetworkFile.READWRITE);
netFile.setAllowedAccess(NetworkFile.READWRITE); netFile.setAllowedAccess(NetworkFile.READWRITE);
// Truncate the file so that the content stream is created
//netFile.truncateFile( 0L);
// Generate a file id for the file // Generate a file id for the file

View File

@@ -108,7 +108,13 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface
// Indicate that the file is open // Indicate that the file is open
fstate.setFileStatus(newFile.isDirectory()? FileStatus.DirectoryExists : FileStatus.FileExists); fstate.setFileStatus(newFile.isDirectory()? FileStatus.DirectoryExists : FileStatus.FileExists);
fstate.setAllocationSize( params.getAllocationSize());
long allocationSize = params.getAllocationSize();
if(allocationSize > 0)
{
fstate.setAllocationSize(allocationSize);
fstate.setFileSize(allocationSize);
}
if (newFile instanceof NodeRefNetworkFile) if (newFile instanceof NodeRefNetworkFile)
{ {
@@ -201,7 +207,8 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface
fstate.setProcessId(params.getProcessId()); fstate.setProcessId(params.getProcessId());
fstate.setSharedAccess( params.getSharedAccess()); fstate.setSharedAccess( params.getSharedAccess());
fstate.setFileStatus(FileStatus.FileExists); fstate.setFileStatus(FileStatus.FileExists);
fstate.updateAccessDateTime(); // Access date time is read/write time not open time
// fstate.updateAccessDateTime();
fstate.setFileSize(x.getFileSize()); fstate.setFileSize(x.getFileSize());
fstate.updateChangeDateTime(x.getModifyDate()); fstate.updateChangeDateTime(x.getModifyDate());
@@ -221,7 +228,8 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface
fstate.setFileStatus(FileStatus.FileExists); fstate.setFileStatus(FileStatus.FileExists);
fstate.setProcessId(params.getProcessId()); fstate.setProcessId(params.getProcessId());
fstate.setSharedAccess( params.getSharedAccess()); fstate.setSharedAccess( params.getSharedAccess());
fstate.updateAccessDateTime(); // access date time is read/write time not open time
//fstate.updateAccessDateTime();
fstate.setFileSize(x.getFileSize()); fstate.setFileSize(x.getFileSize());
fstate.updateChangeDateTime(x.getModifyDate()); fstate.updateChangeDateTime(x.getModifyDate());
@@ -240,7 +248,8 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface
fstate.setFileStatus(FileStatus.DirectoryExists); fstate.setFileStatus(FileStatus.DirectoryExists);
fstate.setProcessId(params.getProcessId()); fstate.setProcessId(params.getProcessId());
fstate.setSharedAccess( params.getSharedAccess()); fstate.setSharedAccess( params.getSharedAccess());
fstate.updateAccessDateTime(); // Access date time is read/write time not open time
//fstate.updateAccessDateTime();
fstate.setFileSize(x.getFileSize()); fstate.setFileSize(x.getFileSize());
fstate.updateChangeDateTime(x.getModifyDate()); fstate.updateChangeDateTime(x.getModifyDate());
@@ -289,11 +298,15 @@ public class LegacyFileStateDriver implements ExtendedDiskInterface
FileStateCache cache = tctx.getStateCache(); FileStateCache cache = tctx.getStateCache();
FileState fstate = cache.findFileState( param.getFullName(), true); FileState fstate = cache.findFileState( param.getFullName(), true);
// MER Experiment Need to reset shared access
if(fstate.getOpenCount() ==0 ) if(fstate.getOpenCount() ==0 )
{ {
logger.debug("reset shared access to READWRITEDELETE"); logger.debug("reset shared access to READWRITEDELETE");
fstate.setSharedAccess( SharingMode.READWRITE + SharingMode.DELETE); fstate.setSharedAccess( SharingMode.READWRITE + SharingMode.DELETE);
fstate.setAllocationSize(-1);
fstate.setFileSize(-1);
fstate.updateChangeDateTime(0);
fstate.updateModifyDateTime(0);
} }
if(fstate != null && param.getAccessToken() != null) if(fstate != null && param.getAccessToken() != null)

View File

@@ -194,7 +194,7 @@ public class NonTransactionalRuleContentDiskDriver implements ExtendedDiskInterf
+ ", requestExclusiveOpLock:" +params.requestExclusiveOpLock() + ", requestExclusiveOpLock:" +params.requestExclusiveOpLock()
+ ", isDeleteOnClose:" +params.isDeleteOnClose() + ", isDeleteOnClose:" +params.isDeleteOnClose()
+ ", sharedAccess: " + strSharedAccess + ", sharedAccess: " + strSharedAccess
+ " allocationSize: " + params.getAllocationSize()); + ", allocationSize: " + params.getAllocationSize());
} }
long creationDateTime = params.getCreationDateTime(); long creationDateTime = params.getCreationDateTime();
@@ -213,7 +213,7 @@ public class NonTransactionalRuleContentDiskDriver implements ExtendedDiskInterf
DriverState driverState = getDriverState(sess); DriverState driverState = getDriverState(sess);
EvaluatorContext ctx = getEvaluatorContext(driverState, folder); EvaluatorContext ctx = getEvaluatorContext(driverState, folder);
Operation o = new CreateFileOperation(file, rootNode, params.getPath()); Operation o = new CreateFileOperation(file, rootNode, params.getPath(), params.getAllocationSize());
Command c = ruleEvaluator.evaluate(ctx, o); Command c = ruleEvaluator.evaluate(ctx, o);
Object ret = commandExecutor.execute(sess, tree, c); Object ret = commandExecutor.execute(sess, tree, c);

View File

@@ -155,7 +155,7 @@ class ScenarioOpenFileInstance implements ScenarioInstance
{ {
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(), c.getAllocationSize()));
postCommitCommands.add(newOpenFileCallbackCommand()); postCommitCommands.add(newOpenFileCallbackCommand());
return new CompoundCommand(commands, postCommitCommands); return new CompoundCommand(commands, postCommitCommands);
} }
@@ -410,7 +410,9 @@ class ScenarioOpenFileInstance implements ScenarioInstance
state = InternalState.OPEN; state = InternalState.OPEN;
if(fileHandle.isReadOnly()) //
if(fileHandle.getGrantedAccess() == NetworkFile.READONLY)
//if(fileHandle.isReadOnly())
{ {
openReadOnlyCount++; openReadOnlyCount++;
fileHandleReadOnly=fileHandle; fileHandleReadOnly=fileHandle;

View File

@@ -56,7 +56,7 @@ public class ScenarioSimpleNonBufferedInstance implements ScenarioInstance
if(operation instanceof CreateFileOperation) if(operation instanceof CreateFileOperation)
{ {
CreateFileOperation c = (CreateFileOperation)operation; CreateFileOperation c = (CreateFileOperation)operation;
return new CreateFileCommand(c.getName(), c.getRootNodeRef(), c.getPath()); return new CreateFileCommand(c.getName(), c.getRootNodeRef(), c.getPath(), c.getAllocationSize());
} }
else if(operation instanceof DeleteFileOperation) else if(operation instanceof DeleteFileOperation)
{ {

View File

@@ -32,12 +32,14 @@ public class CreateFileCommand implements Command
private String name; private String name;
private NodeRef rootNode; private NodeRef rootNode;
private String path; private String path;
private long allocationSize;
public CreateFileCommand(String name, NodeRef rootNode, String path) public CreateFileCommand(String name, NodeRef rootNode, String path, long allocationSize)
{ {
this.name = name; this.name = name;
this.path = path; this.path = path;
this.rootNode = rootNode; this.rootNode = rootNode;
this.allocationSize = allocationSize;
} }
public String getName() public String getName()
@@ -61,5 +63,15 @@ public class CreateFileCommand implements Command
{ {
return TxnReadState.TXN_READ_WRITE; return TxnReadState.TXN_READ_WRITE;
} }
public void setAllocationSize(long allocationSize)
{
this.allocationSize = allocationSize;
}
public long getAllocationSize()
{
return allocationSize;
}
} }

View File

@@ -31,12 +31,14 @@ public class CreateFileOperation implements Operation
private String name; private String name;
private NodeRef rootNodeRef; private NodeRef rootNodeRef;
private String path; private String path;
private long allocationSize;
public CreateFileOperation(String name, NodeRef rootNodeRef, String path) public CreateFileOperation(String name, NodeRef rootNodeRef, String path, long allocationSize)
{ {
this.name = name; this.name = name;
this.rootNodeRef = rootNodeRef; this.rootNodeRef = rootNodeRef;
this.path = path; this.path = path;
this.allocationSize = allocationSize;
} }
public String getName() public String getName()
@@ -76,4 +78,14 @@ public class CreateFileOperation implements Operation
} }
return false; return false;
} }
public void setAllocationSize(long allocationSize)
{
this.allocationSize = allocationSize;
}
public long getAllocationSize()
{
return allocationSize;
}
} }