2012-11-20 69 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