long startFetchTime = System.currentTimeMillis();
String fileName = getFileCanonicalPath(file);
if (fileName != null && !file.isHidden())
{
// Initialize repository document with common stuff, and find the URI
RepositoryDocument rd = new RepositoryDocument();
String uri = prepareForIndexing(rd,file,version);
if (activities.checkURLIndexable(uri))
{
// 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
{
rd.setBinary(inputStream, tempFile.length());
activities.ingestDocument(documentIdentifier, version, uri, 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
{
rd.setBinary(inputStream, fileLength(file));
activities.ingestDocument(documentIdentifier, version, uri, rd);
}
finally
{