删除git存储库(Deletion of git repository)

编程入门 行业动态 更新时间:2024-10-26 11:16:38
删除git存储库(Deletion of git repository)

考虑以下计划:

var path = Path.Combine( Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName())); Directory.CreateDirectory(path); var testFile = Path.Combine(path, "test.txt"); File.WriteAllText(testFile, "Test file"); var source = Repository.Init(path); using (var repository = new Repository(source)) { repository.Index.Add("test.txt"); } Directory.Delete(path, true);

删除存储库文件夹后,我收到一个UnauthorizedAccessException - 拒绝访问其中一个内部git文件。 为了删除文件夹,还有什么我应该处理的吗?

Consider following program:

var path = Path.Combine( Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName())); Directory.CreateDirectory(path); var testFile = Path.Combine(path, "test.txt"); File.WriteAllText(testFile, "Test file"); var source = Repository.Init(path); using (var repository = new Repository(source)) { repository.Index.Add("test.txt"); } Directory.Delete(path, true);

On deletion of repository folder I get an UnauthorizedAccessException - access to one of internal git files is denied. Is there anything else I should dispose of in order to delete the folder?

最满意答案

为了删除文件夹,还有什么我应该处理的吗?

你的处理模式很好。 上述问题的起源不同。

文档中所述,当存在与权限相关的问题时,将引发UnauthorizedAccessException 。

实际上,Libgit2Sharp的行为类似于git,并将.git/objects层次结构下的文件标记为只读,因此在尝试删除它们时会抛出异常。

为了解决这个问题,并在运行测试时简化清理阶段,我们开发了一个辅助方法(即DirectoryHelper.DeleteDirectory() ),它以递归方式取消设置这些只读属性并删除文件和目录。

请参阅源代码 ,您是否愿意重复使用它。

Is there anything else I should dispose of in order to delete the folder?

Your disposing pattern is just fine. The mentioned issue has a different origin.

As stated in the documentation, UnauthorizedAccessException is raised when there's a permission related issue.

Indeed, Libgit2Sharp behaves similarly to git regarding this and marks files under the .git/objects hierarchy as read-only, thus the thrown exception when attempting to delete them.

In order to work around this, and ease the clean up phase when our tests are run, we've developed a helper method (ie. DirectoryHelper.DeleteDirectory()), which recursively unsets those read-only attributes and delete files and directories.

See the source code would you be willing to reuse it.

更多推荐

本文发布于:2023-07-30 01:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1321422.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:git   Deletion   repository

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!