Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » JGit DirCacheCheckout badly remove symlinks
JGit DirCacheCheckout badly remove symlinks [message #776847] Mon, 09 January 2012 11:26 Go to next message
Cedric Darloy is currently offline Cedric DarloyFriend
Messages: 2
Registered: January 2012
Junior Member
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
Re: JGit DirCacheCheckout badly remove symlinks [message #776910 is a reply to message #776847] Mon, 09 January 2012 14:06 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 274
Registered: July 2009
Senior Member
I am sure you found a bug but I am having trouble reproducing.

Let's differentiate between two cases:
1) Symbolic links which are inside the working tree (see http://stackoverflow.com/questions/954560/what-does-git-do-to-files-that-are-a-symbolic-link)
2) Symbolic links on top of the working tree

I think you have case 2). The problem you describe is worse then you describe. JGit tries to delete a folder which is outside of the working tree. This should never happen. The fix you suggest only fixes the cause - but we should find why at all we are trying to delete the folder on top of the working tree.
I think the bug is there since ages but he normally causes no harm. That is because the folder on top of the working tree is normally not deletable because it's not empty. In your special case the folder on top of the working tree is a symbolic link, therefore deletable.

The problem is in line 429 of DirCacheCheckout.java where we call removeEmptyParents(..., llast) without checking that 'last' contains something meaningful.

Thanks for finding this. I'll propose a fix and keep you up to date.





Ciao
Chris
Re: JGit DirCacheCheckout badly remove symlinks [message #776944 is a reply to message #776910] Mon, 09 January 2012 15:19 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 18
Registered: July 2009
Junior Member
I proposed the fix here: http://egit.eclipse.org/r/#change,4935
Re: JGit DirCacheCheckout badly remove symlinks [message #776970 is a reply to message #776944] Mon, 09 January 2012 15:49 Go to previous message
Cedric Darloy is currently offline Cedric DarloyFriend
Messages: 2
Registered: January 2012
Junior Member
Hi Christian,

Thanks
Previous Topic:Exception caught during execution of fetch command
Next Topic:Newer than newbie question!
Goto Forum:
  


Current Time: Fri Apr 19 22:54:14 GMT 2024

Powered by FUDForum. Page generated in 0.02826 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top