JGit 删除 git 存储库
JGit Removing a git repository
我正在使用 JGit 使用以下代码克隆远程 git 存储库。
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();
为下一个 repo 克隆后,由于我需要删除目录,我使用以下代码。
File tempGitDirectory;
try {
tempGitDirectory = new File(dirPath);
if(tempGitDirectory.exists()){
FileUtils.deleteDirectory(tempGitDirectory);
}
} catch (IOException e) {
}
在我的 mac 上,一切正常。但是在 redhat linux 框上尝试时,我无法完全删除回购协议。因以下错误而失败。
rm: cannot remove `git//TestGit/.nfs000000000011f6d40000032a': Device or resource busy
有线索吗?
确保您的密码不在您要删除的路径中。
来自 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.
An NFS server cannot actually remove a file if something still has it open.
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.
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.
检查 lsof 以查看正在使用该文件夹的进程。
OP Upen confirms :
I had opened a pom.xml
reader for the cloned repo.
The FileReader
was not closed. Works fine now.
我正在使用 JGit 使用以下代码克隆远程 git 存储库。
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();
为下一个 repo 克隆后,由于我需要删除目录,我使用以下代码。
File tempGitDirectory;
try {
tempGitDirectory = new File(dirPath);
if(tempGitDirectory.exists()){
FileUtils.deleteDirectory(tempGitDirectory);
}
} catch (IOException e) {
}
在我的 mac 上,一切正常。但是在 redhat linux 框上尝试时,我无法完全删除回购协议。因以下错误而失败。
rm: cannot remove `git//TestGit/.nfs000000000011f6d40000032a': Device or resource busy
有线索吗?
确保您的密码不在您要删除的路径中。
来自 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.
An NFS server cannot actually remove a file if something still has it open.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.
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.
检查 lsof 以查看正在使用该文件夹的进程。
OP Upen confirms
I had opened a
pom.xml
reader for the cloned repo.
TheFileReader
was not closed. Works fine now.