简体   繁体   English

JGit删除一个git仓库

[英]JGit Removing a git repository

I am using JGit to clone a remote git repo using the below code. 我正在使用JGit使用以下代码克隆远程git repo。

 localRepo = new FileRepository(path+"/.git");
 git = new Git(localRepo);
 clone = Git.cloneRepository().setURI(url).setBranch(branch)
                .setDirectory(new File(path)).call();
 clone.getRepository().close();
 clone.close();
 git.getRepository().close();

After cloning for the next repo, since I need to delete the directory, I use the below code. 克隆下一个存储库后,由于需要删除目录,因此使用以下代码。

 File tempGitDirectory;
        try {
            tempGitDirectory = new File(dirPath);
            if(tempGitDirectory.exists()){
                FileUtils.deleteDirectory(tempGitDirectory);
            }
        } catch (IOException e) {

        }

On my mac, everything works fine. 在我的Mac上,一切正常。 But while trying on the redhat linux box, I am not able to delete the repo completely. 但是在尝试在redhat linux机器上时,我无法完全删除该存储库。 Failing with the below error. 因以下错误而失败。

 rm: cannot remove `git//TestGit/.nfs000000000011f6d40000032a': Device or    resource busy

Any clue? 有什么线索吗?

Make sure your pwd is not in the path you are trying to remove. 确保您的密码不在您要删除的路径中。

From this thread : 这个线程

This occurs when a deleted file is still open by some process. 当删除的文件仍通过某些进程打开时,会发生这种情况。 It's an artifact of how NFS works behind the scenes. 这是NFS如何在后台工作的产物。
An NFS server cannot actually remove a file if something still has it open. 如果仍然打开某个文件,则NFS服务器实际上无法删除该文件。

The Linux kernel can easily do it with local disk files -- the inode still remains even after its unlinked from all directories, and the inode gets freed when the last process that has the file open terminates. Linux内核可以轻松地使用本地磁盘文件来完成操作-即使inode与所有目录取消链接后,inode仍然保留,并且当最后一个打开文件的进程终止时,inode将被释放。
However this does not work with NFS, so the NFS server keeps this fake directory entry that represents an open file, and it will be automatically removed when whatever process has this file open terminates. 但是,这不适用于NFS,因此NFS服务器会保留此伪造的目录条目,该条目代表一个打开的文件,并且在有打开该文件的任何进程终止时,它将被自动删除。

Check lsof in order to see what process is using the folder. 检查lsof,以查看正在使用该文件夹的进程。

The OP Upen confirms in the comments : OP Upen 在评论中确认:

I had opened a pom.xml reader for the cloned repo. 我已经为克隆的仓库打开了pom.xml阅读器。
The FileReader was not closed. FileReader未关闭。 Works fine now. 现在工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM