使用File delete()方法不能删除git repo中的.pack文件 [英] .pack file from git repo can't be deleted using File delete() method

查看:796
本文介绍了使用File delete()方法不能删除git repo中的.pack文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我写的这种方法,我使用jgit库克隆了一个git repo,然后用这些文件做了一些东西,最后我想删除回购。
我遇到的问题是,当我调用.pack文件(位于.git \objects \pack)中的delete()方法时,它不能被删除。所有其他文件可以删除。为什么会发生这种情况?

解决方案

您可以看到,基于JGit的Java应用程序默认情况下具有disd ddd的倾向。 >
请参阅配置文件 Gitblit 例如:

 #如果为true, JGit将使用mmap()而不是malloc()+ read()从
#pack文件加载数据。在某些JVM上使用mmap可能会产生问题,因为垃圾
#收集器必须推断出内存映射段在
#之前不再被使用,而调用munmap()可由JVM native码。

#在需要访问许多包文件的服务器应用程序(例如Gitblit)中,将
#设置为true可能会导致人为地耗尽虚拟地址空间,
#as垃圾收集器无法快速回收未使用的映射空间。

#JGit的默认值为false。虽然可能较慢,但它可以产生更多的
#可预测行为。
#文件由Gerrit项目提供。

#SINCE 1.0.0
#重新启用
git.packedGitMmap = false






这与



我碰到另一个无法在Windows中删除克隆存储库的实例。

这个显示的链接使用 PackedGitMMAP

这是尝试使用虚拟内存映射的已知问题吗?

是的。

问题是JVM不会释放内存映射,直到映射被Java GC垃圾回收。

这可能会在将来的任何时候发生,如果内存不足,可能永远不会发生
压力GC真的寻找垃圾并回收。

这就是为什么我们默认禁用该功能,我们不能predi ct当JVM最终会释放文件。

lockquote
<


$ b

是的。这就是为什么这是默认设置。



For this method I am writing, I am cloning a git repo using the jgit library, then doing some stuff with those files, then finally I want to delete the repo. The problem I'm having is that when I call the delete() method on a .pack file (located in .git\objects\pack), it can't be deleted. All other files can be deleted though. Why does this happen?

You can see that Java apps based on JGit have a tendency to disble ddd by default.
See this
config file for Gitblit for instance:

# When true, JGit will use mmap() rather than malloc()+read() to load data from
# pack files. The use of mmap can be problematic on some JVMs as the garbage
# collector must deduce that a memory mapped segment is no longer in use before
# a call to munmap() can be made by the JVM native code.
#
# In server applications (such as Gitblit) that need to access many pack files,
# setting this to true risks artificially running out of virtual address space,
# as the garbage collector cannot reclaim unused mapped spaces fast enough.
#
# Default on JGit is false. Although potentially slower, it yields much more
# predictable behavior.
# Documentation courtesy of the Gerrit project.
#
# SINCE 1.0.0
# RESTART REQUIRED
git.packedGitMmap = false


This is consistent with the JGit thread you found:

I ran into another instance of not being able to delete a cloned repository in windows.
This one appears linked to the use of "PackedGitMMAP".
Is this a known problem with trying to use virtual memory mapping?

Yes.
The problem is the JVM does not release the memory mapping until the mapping is garbage collected by the Java GC.
This can happen at any time in the future, possibly never if there is insufficient memory pressure to force the GC to really look for garbage and reclaim.
This is why we disable the feature by default, we can't predict when the JVM will finally release the file.

In this test case if I "setPackedGitMMAP=false" then the repository is deleted successfully.

Yes. This is why this is the default.

这篇关于使用File delete()方法不能删除git repo中的.pack文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆