Reputation: 1438
I am using JGit to clone a remote git repo using the below code.
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. But while trying on the redhat linux box, I am not able to delete the repo completely. Failing with the below error.
rm: cannot remove `git//TestGit/.nfs000000000011f6d40000032a': Device or resource busy
Any clue?
Upvotes: 1
Views: 1422
Reputation: 1324505
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.
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.
Check lsof in order to see what process is using the folder.
The OP Upen confirms in the comments:
I had opened a
pom.xml
reader for the cloned repo.
TheFileReader
was not closed. Works fine now.
Upvotes: 1