Programmatically delete directory of cloned repository

夙愿已清 提交于 2019-12-11 10:53:43

问题


I am using LibGit2Sharp to clone a remote repository into the windows temp folder. After my script has completed, I want to clean up. However, I always get the following error:

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

where pack-efcef325f8dc897099271fd0f3db6cf4d9f12393.idx is a file in $local_git_clone_path\objects\pack.

How can I completely delete all local leftovers of the git repo I cloned using LibGit2Sharp ?


回答1:


I remember having faced a similar situation.

And, as advised by @nulltoken, you would have to Dispose() the Repository before trying to delete the files that are being held by it.

using should be the best option.

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

//Code to Delete your local temp dir

Reference: Clone Fixture from LibGit2Sharp



来源:https://stackoverflow.com/questions/16444339/programmatically-delete-directory-of-cloned-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!