问题
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