[英]Programmatically delete directory of cloned repository
I am using LibGit2Sharp
to clone a remote repository into the windows temp folder. 我正在使用
LibGit2Sharp
将远程存储库克隆到windows temp文件夹中。 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.
SystemError:拒绝访问路径'pack-efcef325f8dc897099271fd0f3db6cf4d9f12393.idx'。
where pack-efcef325f8dc897099271fd0f3db6cf4d9f12393.idx
is a file in $local_git_clone_path\\objects\\pack.
其中
pack-efcef325f8dc897099271fd0f3db6cf4d9f12393.idx
是$local_git_clone_path\\objects\\pack.
How can I completely delete all local leftovers of the git repo I cloned using LibGit2Sharp ? 如何完全删除我使用LibGit2Sharp克隆的git repo的所有本地剩余部分?
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. 并且,正如@nulltoken所建议的那样,在尝试删除由它保存的文件之前,您必须先
Dispose()
Repository
。
using
should be the best option. using
应该是最好的选择。
using (var repo = new Repository(repositoryPath))
{
//Your repo specific implementation.
}
//Code to Delete your local temp dir
Reference: Clone Fixture from LibGit2Sharp 参考:从LibGit2Sharp 克隆夹具
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.