2012-11-20 67 views

回答

0

得到了這個工作。 DfsGarbageCollector基本上相當於repack -d。要獲得repack -a行爲,使用DfsPackCompactor

void repack(DfsRepository repo) throws IOException { 
    DfsGarbageCollector gc = new DfsGarbageCollector(repo); 
    gc.pack(null); 

    // update the list of packs for getPacks() below 
    // otherwise not all packs are compacted 
    repo.scanForRepoChanges(); 

    // only compact if there are multiple pack files 
    DfsPackFile[] packs = repo.getObjectDatabase().getPacks(); 

    if (packs.length > 1) { 
     DfsPackCompactor compactor = new DfsPackCompactor(repo); 

     for (DfsPackFile pack : packs) { 
      compactor.add(pack); 
     } 

     compactor.compact(null); 
    } 
} 

這不是很全,但。

DfsGarbageCollector爲垃圾創建單獨的包文件。

我發現「刪除」最簡單的方法垃圾打包文件是從我的DfsObjDatabase.writePackFile()實現,簡單地扔掉數據,如果包文件的來源是PackSource.UNREACHABLE_GARBAGE返回DfsOutputStream