}
// deliberately non recursive (so we avoid situations where the whole h/d is deleted)
public void deleteIndex(Volume volume) throws MessageSearchException {
if (volume == null)
throw new MessageSearchException("assertion failure: null volume",logger);
logger.debug("delete index {indexpath='"+volume.getIndexPath()+"'}");
// we need to stop indexing for a brief moment
shutdownIndexer();
VolumeIndex volumeIndex = getVolumeIndex(volume);
volumeIndex.closeIndex();
File indexDir = new File(volume.getIndexPath());
if (!indexDir.exists()) return;
if (indexDir.isDirectory()) {
String[] children = indexDir.list();
for (int i=0; i<children.length; i++) {
String filepath = volume.getIndexPath()+File.separatorChar+children[i];
logger.debug("deleting file {path='" + filepath +"'}");
File file = new File(filepath);
boolean success = file.delete();
if (!success) {
try {
File newFile = File.createTempFile("temp","idx");
file.renameTo(newFile);
} catch (Exception e) {
throw new MessageSearchException("failed to delete file in existing index {filepath='"+filepath+"'}",logger);
}
} else
logger.debug("deleted file successfully {filepath='" + filepath +"'}");
}
}