use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class BufferedContentDiskDriver method getFileInformation.
@Override
public FileInfo getFileInformation(SrvSession sess, TreeConnection tree, String path) throws IOException {
ContentContext tctx = (ContentContext) tree.getContext();
FileInfo info = getFileInformationInternal(sess, tree, path);
/*
* 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()) {
FileStateCache cache = tctx.getStateCache();
FileState fstate = cache.findFileState(path, false);
if (fstate != null) {
if (logger.isDebugEnabled()) {
logger.debug("state cache available - overwriting from state cache: isDirectory=" + info.isDirectory());
}
FileInfo finfo = new FileInfo();
finfo.copyFrom(info);
/**
* File state is probably stale for directories which is why we don't attempt to
* cache.
*/
if (!info.isDirectory()) {
/*
* What about stale file state values here?
*/
if (fstate.hasFileSize()) {
if (logger.isDebugEnabled()) {
logger.debug("replace file size " + info.getSize() + " with " + fstate.getFileSize());
}
finfo.setFileSize(fstate.getFileSize());
}
if (fstate.hasAccessDateTime()) {
if (logger.isDebugEnabled()) {
logger.debug("replace access date " + new Date(finfo.getAccessDateTime()) + " with " + new Date(fstate.getAccessDateTime()));
}
finfo.setAccessDateTime(fstate.getAccessDateTime());
}
if (fstate.hasChangeDateTime()) {
if (logger.isDebugEnabled()) {
logger.debug("replace change date " + new Date(finfo.getChangeDateTime()) + " with " + new Date(fstate.getChangeDateTime()));
}
finfo.setChangeDateTime(fstate.getChangeDateTime());
}
if (fstate.hasModifyDateTime()) {
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());
}
}
if (logger.isDebugEnabled()) {
logger.debug("Return getFileInformation, path: " + path + ", returning:" + finfo + ", readOnly:" + finfo.isReadOnly() + ", fileId:" + finfo.getFileId() + ", fileSize:" + finfo.getSize() + ", directoryId:" + finfo.getDirectoryId() + ", createdDate: " + new Date(finfo.getCreationDateTime()) + ", accessDate:" + new Date(finfo.getAccessDateTime()) + ", modifiedDate:" + new Date(finfo.getModifyDateTime()) + ", changeDate:" + new Date(finfo.getChangeDateTime()) + ", fileAttributes: 0x" + Integer.toHexString(info.getFileAttributes()) + ", mode: 0x" + Integer.toHexString(finfo.getMode()));
}
return finfo;
}
}
if (logger.isDebugEnabled()) {
logger.debug("getFileInformation Return:" + path + " returning" + info);
}
return info;
}
use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testWindows7Explorer.
// testGedit
/**
* Windows7 Explorer update
* 0) Existing file mark.jpg
* a) Create new file (~ark.tmp)
* b) Existing file rename out of the way. (mark.jpg~RF5bb356.TMP)
* c) New file rename into place. (~ark.tmp - mark.jpg)
* d) Old file opened attributes only
* e) set delete on close
* f) close
*/
public void testWindows7Explorer() throws Exception {
logger.debug("testWindows7Explorer");
final String FILE_NAME = "mark.jpg";
final String FILE_OLD_TEMP = "mark.jpg~RF5bb356.TMP";
final String FILE_NEW_TEMP = "~ark.tmp";
class TestContext {
NodeRef testNodeRef;
NetworkFile firstFileHandle;
NetworkFile secondFileHandle;
}
;
final TestContext testContext = new TestContext();
final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testWindows7Explorer";
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
final TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
/**
* Clean up just in case garbage is left from a previous run
*/
RetryingTransactionCallback<Void> deleteGarbageFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
try {
tran.doInTransaction(deleteGarbageFileCB);
} catch (Exception e) {
// expect to go here
}
logger.debug("0) create new file");
RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
/**
* Create the test directory we are going to use
*/
FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
driver.createDirectory(testSession, testConnection, createRootDirParams);
driver.createDirectory(testSession, testConnection, createDirParams);
/**
* Create the file we are going to test
*/
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
assertNotNull(testContext.firstFileHandle);
ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTestMark.jpg");
assertNotNull("unable to find test resource filesys/ContentDiskDriverTestMark.jpg", fileResource);
writeResourceToNetworkFile(fileResource, testContext.firstFileHandle);
driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
testContext.testNodeRef = file1NodeRef;
nodeService.addAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
return null;
}
};
tran.doInTransaction(createFileCB, false, true);
/**
* a) Save the new file
*/
logger.debug("a) save new file");
RetryingTransactionCallback<Void> writeFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NEW_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
testContext.secondFileHandle = driver.createFile(testSession, testConnection, createFileParams);
ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTestMark2.jpg");
assertNotNull("unable to find test resource filesys/ContentDiskDriverTestMark2.jpg", fileResource);
writeResourceToNetworkFile(fileResource, testContext.secondFileHandle);
driver.closeFile(testSession, testConnection, testContext.secondFileHandle);
return null;
}
};
tran.doInTransaction(writeFileCB, false, true);
/**
* b) rename the old file
*/
logger.debug("c) rename old file");
RetryingTransactionCallback<Void> renameOldFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_OLD_TEMP);
return null;
}
};
tran.doInTransaction(renameOldFileCB, false, true);
/**
* c) Move the new file into place, stuff should get shuffled
*/
logger.debug("d) move new file into place");
RetryingTransactionCallback<Void> moveNewFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NAME);
return null;
}
};
tran.doInTransaction(moveNewFileCB, false, true);
/**
* d) Delete the old file
*/
logger.debug("d) delete on close the old file");
RetryingTransactionCallback<Void> deleteOldFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
FileOpenParams openFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_OLD_TEMP, 0, AccessMode.NTReadAttributesOnly, FileAttribute.NTNormal, 0);
testContext.secondFileHandle = driver.openFile(testSession, testConnection, openFileParams);
assertNotNull(testContext.secondFileHandle);
FileInfo info = new FileInfo();
info.setFileInformationFlags(FileInfo.SetDeleteOnClose);
driver.setFileInformation(testSession, testConnection, TEST_DIR + "\\" + FILE_OLD_TEMP, info);
testContext.secondFileHandle.setDeleteOnClose(true);
driver.closeFile(testSession, testConnection, testContext.secondFileHandle);
return null;
}
};
tran.doInTransaction(deleteOldFileCB, false, true);
logger.debug("e) validate results");
/**
* Now validate everything is correct
*/
RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
assertTrue("file has lost versionable aspect", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
assertEquals("node ref has changed", shuffledNodeRef, testContext.testNodeRef);
Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
assertNotNull("data is null", data);
assertEquals("size is wrong", 10407, data.getSize());
assertEquals("mimeType is wrong", "image/jpeg", data.getMimetype());
return null;
}
};
tran.doInTransaction(validateCB, true, true);
}
use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testGetFileInformation.
/**
* Test Get File Information
*/
public void testGetFileInformation() throws Exception {
logger.debug("testGetFileInformation");
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
final TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
class TestContext {
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
/**
* Test 1 : Get the root info
*/
FileInfo finfo = driver.getFileInformation(testSession, testConnection, "");
assertNotNull("root info is null", finfo);
assertEquals("root has a unexpected file name", "", finfo.getFileName());
}
use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testSetFileScenario.
// Test Word Save Locked File
/**
* ALF-10686
* This scenario is executed by windows explorer.
*
* A file is created and the file handle kept open.
* stuff is written
* Then the modified date is set
* Then the file is closed.
* @throws Exception
*/
public void testSetFileScenario() throws Exception {
logger.debug("testSetFileInfo");
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
final TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
Date now = new Date();
// CREATE 6 hours ago
final Date CREATED = new Date(now.getTime() - 1000 * 60 * 60 * 6);
// Modify one hour ago
final Date MODIFIED = new Date(now.getTime() - 1000 * 60 * 60 * 1);
class TestContext {
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
/**
* Step 1 : Create a new file in read/write mode and add some content.
* Call SetInfo to set the creation date
*/
int openAction = FileAction.CreateNotExist;
final String FILE_NAME = "testSetFileScenario.txt";
final String FILE_PATH = "\\" + FILE_NAME;
// Clean up junk if it exists
try {
driver.deleteFile(testSession, testConnection, FILE_PATH);
} catch (IOException ie) {
// expect to go here
}
final FileOpenParams params = new FileOpenParams(FILE_PATH, openAction, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
final NetworkFile file = driver.createFile(testSession, testConnection, params);
assertNotNull("file is null", file);
assertFalse("file is read only, should be read-write", file.isReadOnly());
RetryingTransactionCallback<Void> writeStuffCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
byte[] stuff = "Hello World".getBytes();
driver.writeFile(testSession, testConnection, file, stuff, 0, stuff.length, 0);
FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
info.setFileInformationFlags(FileInfo.SetModifyDate);
info.setModifyDateTime(MODIFIED.getTime());
info.setNetworkFile(file);
driver.setFileInformation(testSession, testConnection, FILE_PATH, info);
return null;
}
};
tran.doInTransaction(writeStuffCB);
RetryingTransactionCallback<Void> closeFileCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
// This close is in a different position to the simple setFileInformation scenarios above.
driver.closeFile(testSession, testConnection, file);
return null;
}
};
tran.doInTransaction(closeFileCB);
RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef companyHome = repositoryHelper.getCompanyHome();
NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
testContext.testNodeRef = newNode;
assertNotNull("can't find new node", newNode);
Serializable content = nodeService.getProperty(newNode, ContentModel.PROP_CONTENT);
assertNotNull("content is null", content);
Date modified = (Date) nodeService.getProperty(newNode, ContentModel.PROP_MODIFIED);
assertEquals("modified time not set correctly", MODIFIED, modified);
return null;
}
};
tran.doInTransaction(validateCB);
// clean up so we could run the test again
RetryingTransactionCallback<Void> deleteFile = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
driver.deleteFile(testSession, testConnection, FILE_PATH);
return null;
}
};
tran.doInTransaction(deleteFile, false, true);
}
use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class ContentDiskDriverTest method testSetFileInfo.
/**
* Test Set Info
*
* Three flags set
* <ol>
* <li>SetDeleteOnClose</li>
* <li>SetCreationDate</li>
* <li>SetModifyDate</li>
* </ol>
*/
public void testSetFileInfo() throws Exception {
logger.debug("testSetFileInfo");
ServerConfiguration scfg = new ServerConfiguration("testServer");
TestServer testServer = new TestServer("testServer", scfg);
final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
DiskSharedDevice share = getDiskSharedDevice();
final TreeConnection testConnection = testServer.getTreeConnection(share);
final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
Date now = new Date();
// CREATE 6 hours ago
final Date CREATED = new Date(now.getTime() - 1000 * 60 * 60 * 6);
// Modify one hour ago
final Date MODIFIED = new Date(now.getTime() - 1000 * 60 * 60 * 1);
class TestContext {
NodeRef testNodeRef;
}
;
final TestContext testContext = new TestContext();
/**
* Step 1 : Create a new file in read/write mode and add some content.
* Call SetInfo to set the creation date
*/
int openAction = FileAction.CreateNotExist;
final String FILE_NAME = "testSetFileInfo.txt";
final String FILE_PATH = "\\" + FILE_NAME;
// Clean up junk if it exists
try {
driver.deleteFile(testSession, testConnection, FILE_PATH);
} catch (IOException ie) {
// expect to go here
}
final FileOpenParams params = new FileOpenParams(FILE_PATH, openAction, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
final NetworkFile file = driver.createFile(testSession, testConnection, params);
assertNotNull("file is null", file);
assertFalse("file is read only, should be read-write", file.isReadOnly());
RetryingTransactionCallback<Void> writeStuffCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
byte[] stuff = "Hello World".getBytes();
driver.writeFile(testSession, testConnection, file, stuff, 0, stuff.length, 0);
driver.closeFile(testSession, testConnection, file);
FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
info.setFileInformationFlags(FileInfo.SetModifyDate);
info.setModifyDateTime(MODIFIED.getTime());
driver.setFileInformation(testSession, testConnection, FILE_PATH, info);
return null;
}
};
tran.doInTransaction(writeStuffCB);
RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef companyHome = repositoryHelper.getCompanyHome();
NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
testContext.testNodeRef = newNode;
assertNotNull("can't find new node", newNode);
Serializable content = nodeService.getProperty(newNode, ContentModel.PROP_CONTENT);
assertNotNull("content is null", content);
Date modified = (Date) nodeService.getProperty(newNode, ContentModel.PROP_MODIFIED);
assertEquals("modified time not set correctly", MODIFIED, modified);
return null;
}
};
tran.doInTransaction(validateCB);
/**
* Step 2: Change the created date
*/
logger.debug("Step 2: Change the created date");
RetryingTransactionCallback<Void> changeCreatedCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
info.setFileInformationFlags(FileInfo.SetCreationDate);
info.setCreationDateTime(CREATED.getTime());
driver.setFileInformation(testSession, testConnection, FILE_PATH, info);
return null;
}
};
tran.doInTransaction(changeCreatedCB);
RetryingTransactionCallback<Void> validateCreatedCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef companyHome = repositoryHelper.getCompanyHome();
NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
testContext.testNodeRef = newNode;
assertNotNull("can't find new node", newNode);
Serializable content = nodeService.getProperty(newNode, ContentModel.PROP_CONTENT);
assertNotNull("content is null", content);
Date created = (Date) nodeService.getProperty(newNode, ContentModel.PROP_CREATED);
assertEquals("created time not set correctly", CREATED, created);
return null;
}
};
tran.doInTransaction(validateCreatedCB);
/**
* Step 3: Test
*/
logger.debug("Step 3: test deleteOnClose");
RetryingTransactionCallback<Void> deleteOnCloseCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NetworkFile f2 = driver.openFile(testSession, testConnection, params);
FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
info.setFileInformationFlags(FileInfo.SetDeleteOnClose);
driver.setFileInformation(testSession, testConnection, FILE_PATH, info);
file.setDeleteOnClose(true);
byte[] stuff = "Update".getBytes();
driver.writeFile(testSession, testConnection, file, stuff, 0, stuff.length, 0);
driver.closeFile(testSession, testConnection, file);
return null;
}
};
tran.doInTransaction(deleteOnCloseCB);
RetryingTransactionCallback<Void> validateDeleteOnCloseCB = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
NodeRef companyHome = repositoryHelper.getCompanyHome();
NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
assertNull("can still find new node", newNode);
return null;
}
};
tran.doInTransaction(validateDeleteOnCloseCB);
// clean up so we could run the test again
// driver.deleteFile(testSession, testConnection, FILE_PATH);
}
Aggregations