if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("JCIFS: Processing '"+documentIdentifier+"'");
try
{
SmbFile file = new SmbFile(documentIdentifier,pa);
if (fileExists(file))
{
if (fileIsDirectory(file))
{
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("JCIFS: '"+documentIdentifier+"' is a directory");
// Queue up stuff for directory
// DFS special support no longer needed, because JCifs now does the right thing.
// This is the string we replace in the child canonical paths.
// String matchPrefix = "";
// This is what we replace it with, to get back to a DFS path.
// String matchReplace = "";
// DFS resolved.
// Use a filter to actually do the work here. This prevents large arrays from being
// created when there are big directories.
ProcessDocumentsFilter filter = new ProcessDocumentsFilter(activities,spec);
fileListFiles(file,filter);
filter.checkAndThrow();
}
else
{
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("JCIFS: '"+documentIdentifier+"' is a file");
if (!scanOnly[i])
{
// We've already avoided queuing documents that we
// don't want, based on file specifications.
// We still need to check based on file data.
// DFS support is now implicit in JCifs.
long startFetchTime = System.currentTimeMillis();
String fileName = getFileCanonicalPath(file);
if (fileName != null)
{
// manipulate path to include the DFS alias, not the literal path
// String newPath = matchPrefix + fileName.substring(matchReplace.length());
String newPath = fileName;
if (checkNeedFileData(newPath, spec))
{
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("JCIFS: Local file data needed for '"+documentIdentifier+"'");
// Create a temporary file, and use that for the check and then the ingest
File tempFile = File.createTempFile("_sdc_",null);
try
{
FileOutputStream os = new FileOutputStream(tempFile);
try
{
// Now, make a local copy so we can fingerprint
InputStream inputStream = getFileInputStream(file);
try
{
// Copy!
if (transferBuffer == null)
transferBuffer = new byte[65536];
while (true)
{
int amt = inputStream.read(transferBuffer,0,transferBuffer.length);
if (amt == -1)
break;
os.write(transferBuffer,0,amt);
}
}
finally
{
inputStream.close();
}
}
finally
{
os.close();
}
if (checkIngest(tempFile, newPath, spec, activities))
{
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("JCIFS: Decided to ingest '"+documentIdentifier+"'");
// OK, do ingestion itself!
InputStream inputStream = new FileInputStream(tempFile);
try
{
RepositoryDocument rd = new RepositoryDocument();
rd.setBinary(inputStream, tempFile.length());
rd.setFileName(file.getName());
int index = 0;
index = setDocumentSecurity(rd,version,index);
index = setPathMetadata(rd,version,index);
StringBuilder ingestURI = new StringBuilder();
index = unpack(ingestURI,version,index,'+');
activities.ingestDocument(documentIdentifier, version, ingestURI.toString(), rd);
}
finally
{
inputStream.close();
}
// I put this record here deliberately for two reasons:
// (1) the other path includes ingestion time, and
// (2) if anything fails up to and during ingestion, I want THAT failure record to be written, not this one.
// So, really, ACTIVITY_ACCESS is a bit more than just fetch for JCIFS...
activities.recordActivity(new Long(startFetchTime),ACTIVITY_ACCESS,
new Long(tempFile.length()),documentIdentifier,"Success",null,null);
}
else
{
// We must actively remove the document here, because the getDocumentVersions()
// method has no way of signalling this, since it does not do the fingerprinting.
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("JCIFS: Decided to remove '"+documentIdentifier+"'");
activities.deleteDocument(documentIdentifier, version);
// We should record the access here as well, since this is a non-exception way through the code path.
// (I noticed that this was not being recorded in the history while fixing 25477.)
activities.recordActivity(new Long(startFetchTime),ACTIVITY_ACCESS,
new Long(tempFile.length()),documentIdentifier,"Success",null,null);
}
}
finally
{
tempFile.delete();
}
}
else
{
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("JCIFS: Local file data not needed for '"+documentIdentifier+"'");
// Presume that since the file was queued that it fulfilled the needed criteria.
// Go off and ingest the fast way.
// Ingest the document.
InputStream inputStream = getFileInputStream(file);
try
{
RepositoryDocument rd = new RepositoryDocument();
rd.setBinary(inputStream, fileLength(file));
rd.setFileName(file.getName());
int index = 0;
index = setDocumentSecurity(rd,version,index);
index = setPathMetadata(rd,version,index);
StringBuilder ingestURI = new StringBuilder();
index = unpack(ingestURI,version,index,'+');