2013-05-08 29 views
1

我正在使用LibGit2Sharp將遠程存儲庫克隆到Windows臨時文件夾中。我的腳本完成後,我想清理。不過,我總是得到以下錯誤:以編程方式刪除克隆存儲庫的目錄

SystemError: Access to the path 'pack-efcef325f8dc897099271fd0f3db6cf4d9f12393.idx' is denied.

其中pack-efcef325f8dc897099271fd0f3db6cf4d9f12393.idx$local_git_clone_path\objects\pack.

我怎樣才能完全刪除使用LibGit2Sharp git的回購我克隆的所有本地剩菜文件?

+2

你試圖刪除文件之前處置庫? – nulltoken 2013-05-08 16:19:54

回答

4

我記得遇到過類似的情況。

而且,正如@nulltoken所建議的那樣,在嘗試刪除它所擁有的文件之前,您必須先Dispose()Repository

using應該是最好的選擇。

using (var repo = new Repository(repositoryPath)) 
{ 
    //Your repo specific implementation. 
} 

//Code to Delete your local temp dir 

參考:Clone Fixture從LibGit2Sharp