JGit DirCacheCheckout badly remove symlinks [message #776847] |
Mon, 09 January 2012 06:26  |
Eclipse User |
|
|
|
Hi,
Using DirCacheCheckout in Jgit, I encountered this issue:
My repository working tree (/home/user/git/repo) in under a symlink :
ls /home/user :
drwxr-xr-x git1
drwxr-xr-x git2
lrwxrwxrwx git -> git1
When using DirCacheCheckout.checkout() and when a file is removed,
the symlink git is deleted.
Looking through sources, it seems that the DirCacheCheckout.removeEmptyParents is responsible :
When iterating in removed files in checkout(),
it compares prefixes at first removed file (e.g /home/user/git/repo/test/test.txt) to blank path ""
Seems it detects prefix is not the same, removeEmptyParents is called on file
/home/user/git/repo (the working tree)
The removeEmptyParents then compares its parent /home/user/git to working tree
/home/user/git/repo and since it is not the same calls
new File("/home/user/git).delete()
But since /home/user/git is a link, it is deleted despite not empty.
A simple update would be to verify before deleting a directory that it is actually empty to not delete symbolic links:
if (parentFile.list().length == 0 && !parentFile.delete())
Regards
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.29792 seconds