/**
* Prunes this directory.
*/
void prune() {
InventoryMgr mgr = null;
if ((_root == null) || (!_root.exists())
|| (_trash == null) || (_crList == null)) {
return;
}
try {
mgr = new InventoryMgr(_root);
if (_crList.size() == 0) {
_logger.log(Level.FINE,
"Found empty inventory list from central repository for: "
+ _root.getPath());
}
// converts the inventories to sorted array
String[] cr = InventoryMgr.transformInventory(_crList);
// inventory of the cache directory
List inventory = mgr.getInventory();
Iterator iter = inventory.iterator();
while (iter.hasNext()) {
String f = (String) iter.next();
// file is not present in central repository
if (isACandidate(f, cr)) {
File file = new File(_root, f);
FileHandler handler = new FileHandler(file, _trash);
handler.remove();
// remove empty directory
File parent = file.getParentFile();
String[] children = parent.list();
if (children.length == 0) {
FileHandler dHandler = new FileHandler(parent, _trash);
dHandler.remove();
}
}
}
} catch (Exception e) {
// ignore
} finally {
if (mgr != null) {
try {
mgr.removeInventoryFile();
mgr.removeGCTargetFile();
} catch (Exception e) { }
}
}
}