throw new IllegalStateException("Server not running.");
}
logger.debug("setNewIndex: " + descriptor.toString() + " - " + descriptor.getRemotePath());
try {
String location = descriptor.getRemotePath();
Index currentIndex = library.getCurrentIndex();
File workingDir = new File(this.indexDir);
if (location.endsWith("/")) location = location.substring(0,location.length() - 1);
String newIndexName = location.substring(location.lastIndexOf("/"));
// Make index copy, in case there is a current index.
// otherwise, just create the directory
if (null != currentIndex) {
Index newIndex = currentIndex.copyIndex(new File(workingDir,newIndexName));
newIndex.close();
} else {
new File(workingDir,newIndexName).mkdirs();
}
int exitValue;
// So, we can now copy the index via rsync
logger.info("executing rsync");
exitValue = CommandUtil.execute("rsync -r -v -t -W --delete " + location + " " + workingDir.getCanonicalPath(), null, logger).first();
logger.info("rsync finished with exit value = " + exitValue);
if ( 0 != exitValue) {
// already logged in Execute
// TODO check what we want to do .. disk is probably full ..
String msg="Could not make rsync. The disk might be full or may be we are " +
"having ssh permission problems. Make sure no SSH_* variables are" +
"defined in the environment. Here is the environment: " + System.getenv() ;
throw new RuntimeException(msg);
}
// now, verify that the index did not shrink more than 10%
File newIndexDir = new File(workingDir,newIndexName);
if ((null != currentIndex) && (float)(currentIndex.length() * (0.1)) > (float)FileUtil.sizeOf(newIndexDir)) {
String warning = "Trying to copy an index that shrinked more ";
warning += "than 10%. It will not be erased nor used by the ";
warning += "Searcher, and should be checked by a person. It is ";
warning += " located at " + newIndexDir.getAbsolutePath();
logger.warn(warning);
return false;
}
// So, size constraints are fine .. Lets try check the index.
// Read it
Index index ;
try {
index = new Index(newIndexDir);
} catch (Exception e) {
logger.error(e,e);
// Clean corrupted index
logger.info("deleting directory: " + newIndexDir.getAbsolutePath());
FileUtil.deleteDir(newIndexDir);