Quite often we need have last access time for File share content. Google File System connector 3.x does not support it out of the box. Since Google engineers already added retrieving the information to JCIFS code base to reset last access time for SMB content (yes, Google connector is using a modified version of JCIFS), it makes adding last access time support for SMB content much simpler.
Here are the steps to get it done:
- Download latest File System connector from Google site.
- Locate the file FileDocument.java.
-
Add the following section in bold to method, fetchProperties() in FileDocument.java (the rest code provided just as marker):
private void fetchProperties() throws RepositoryException {
… …
try {
long lastModified = file.getLastModified();
if (lastModified > 0L) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(lastModified);
addProperty(SpiConstants.PROPNAME_LASTMODIFIED, Value.getDateValue(calendar));
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to get last-modified time for " + file.getPath(), e);
}
//// Added to support last access time
long lastAccess = getLastAccess(file);
if (lastAccess > 0L) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(lastAccess);
addProperty(“perficient:lastaccess”, Value.getDateValue(calendar));
}
////
fetchAcl(file);
… …
}
- Add the following new method to FileDocument.java:
//// Added to support last access time
public static long getLastAccess(ReadonlyFile<?> file)
{
long lastAccess = 0L;
try {
if (file instanceof SmbReadonlyFile) {
SmbReadonlyFile smbfile = (SmbReadonlyFile) file;
SmbFileDelegate delegate = smbfile.delegate;
lastAccess = delegate.lastAccess();
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to get last-access time for " + file.getPath(), e);
}
return lastAccess;
}
-
Compile the File System connector package, then you will have support of last access time for SMB content with File System connector.
The newly added method, getLastAccess(ReadonlyFile<?> file) can be further generalized to check instance of AccessTimePreservingReadonlyFile so that other types of File Share content can be supported.