After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 545768 - Symlinks are not followed when scanning collections
Symlinks are not followed when scanning collections
Status: RESOLVED FIXED
Product: banshee
Classification: Other
Component: general
1.2.0
Other Linux
: Normal enhancement
: 1.x
Assigned To: Banshee Maintainers
Banshee Maintainers
: 612838 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-07-31 22:44 UTC by bjwebb67
Modified: 2010-03-14 01:32 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to allow following symbolic links (2.29 KB, patch)
2008-11-09 06:03 UTC, Michael Marner
needs-work Details | Review
updated version (2.17 KB, patch)
2009-02-22 09:01 UTC, Alexander Kojevnikov
none Details | Review
Do not follow symlinks that go up the tree (2.30 KB, patch)
2009-02-22 23:06 UTC, Bertrand Lorentz
needs-work Details | Review
Updated to comment #8 (4.67 KB, patch)
2009-05-01 02:12 UTC, Alexander Kojevnikov
none Details | Review

Description bjwebb67 2008-07-31 22:44:33 UTC
Symlinks are not followed when scanning collections - if this feature could it added, it would be much appreciated.
Comment 1 Michael Marner 2008-11-09 06:03:36 UTC
Created attachment 122251 [details] [review]
patch to allow following symbolic links

patch that allows symbolic links to be followed when getting directories/files

For getting directories:
 o Checks whether an entry is actually a link
 o Traverses the link to see where it ends up
 o If the link points to a directory, add it to the directory list like normal

Same process is done for files as well.
Comment 2 Michael Marner 2008-11-09 06:09:09 UTC
Hey

Yes, I needed this as well. Basic idea is this:

 o User has media library directory of ~/Music
 o Inside this folder are symlinks to other directories on the file system. eg:

   ~/Music/music      -> /media/disk1/music
   ~/Music/moremusic  -> /media/disk2/music
   ~/Music/videoclips -> /media/disk1/video

 o Scanning the media directory doesn't do anything because symbolic links aren't followed

The file I attached is a patch that modifies how directories are parsed in Banshee.IO.Unix.

A new method looks through a link to the file it points to, and returns the FileSystemInfo entry for that file. The new method is needed to deal with multiple level links (links pointing to links).

This method is used in Directory.getDirectories and Directory.getFiles to see whether a link points to a directory/file. eg. If a link points to a directory, the link is added to the list of directories just like the regular directories are.

Works the same way as for files.

The main issue with traversing through symbolic links is that circular links will cause an endless loop when doing the scan of the collection. My patch doesn't consider this at all - It doesn't deal with the scanning logic, it only makes it so symbolic links aren't completely ignored.

Cheers
Michael
Comment 3 Bertrand Lorentz 2008-11-09 14:43:48 UTC
Thanks for the patch !
Please follow the code formatting conventions described in the HACKING file : indent with spaces, etc.

I also think circular links should be handled. We don't want a scan to last forever ! ;)
Comment 4 Michael Marner 2008-11-09 23:36:04 UTC
Hey

Yeah I had my tab settings all messed up in vim, sorry about that.

I agree that the circular links need to be handled, I'm not entirely sure of the best way to go about it. A possible way is to keep track of a list/map of any symlinks we traverse into:

Inside Library Scan
 > On entering directory
 > if directory is a symlink
 >> if directory is in list, return
 > add link to list/map
 > scan directory like normal

Now since we are only adding symlinks to the list, the data structure shouldn't get too large. Obviously this needs some more thought and I don't have any code in front of me until I get home tonight. But yeah I'm curious to know what other people think about this, and I'll have a hack on it later.

Cheers
Michael
Comment 5 lcid-fire 2009-02-20 21:48:50 UTC
I'd rather have the patch in as it is since frankly a one time submitter is very unlikely to fix all possible pitfalls there are - it's already great that they are submitting patches.
Comment 6 Alexander Kojevnikov 2009-02-22 09:01:52 UTC
Created attachment 129243 [details] [review]
updated version

This patch fixes formatting issues.

I also added a check for circular symlinks and replaced tail-recursion with iteration.
Comment 7 Bertrand Lorentz 2009-02-22 23:06:05 UTC
Created attachment 129290 [details] [review]
Do not follow symlinks that go up the tree

I updated Alexander's patch, so that symlinks that point higher up in the directory tree are ignored.
Without this additional restriction, the 2 following structures would lead to an infinite loop :

FolderA/
  link -> ../FolderA

FolderA/
  FolderB/
    link -> ../../FolderA

The other possibility would be to keep track of all visited folder in the DirectoryScannerPipelineElement class.
I putting this here in case someone has a better idea...
Comment 8 Gabriel Burt 2009-02-26 20:46:41 UTC
A couple problems with this

1. it creates a Dictionary for every child - that's a lot of Dictionaries!
2. it doesn't prevent all ways in which a recursive symlink could occur; as you mention Bertrand, we'd have to do this at a higher level
3. the file symlink traverser shouldn't traverse directory-symlinks, (eg getfiles for / where it contains this: /dir-link1/dir-link2/actual-file would return actual-file when it shouldn't)

Should we really even try?  Is there any legitimate use of such a symlink structure?  If we're even going to try, let's do it right.
Comment 9 Alexander Kojevnikov 2009-05-01 02:12:04 UTC
Created attachment 133715 [details] [review]
Updated to comment #8

Updated Bertrand's patch to address all these issues.
Comment 10 Gabriel Burt 2009-10-27 20:17:30 UTC
Bulk changing the assignee to banshee-maint@gnome.bugs to make it easier for people to get updated on all banshee bugs by following that address.  It's usually quite apparent who is working on a given bug by the comments and/or patches attached.
Comment 11 Michael Martin-Smucker 2009-12-24 14:29:04 UTC
I've seen this issue mentioned in a couple different places recently (particularly the Ubuntu forums).  This would be a nice fix to have; is there any chance that the patch still applies?
Comment 12 yermandu 2010-01-22 15:12:37 UTC
I have the same problem i can not apply the patch. 
How i can do it?

Is there any way to make this fix permanent?
Comment 13 Alexander Kojevnikov 2010-02-04 11:24:35 UTC
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.
Comment 14 Alexander Kojevnikov 2010-03-14 01:32:58 UTC
*** Bug 612838 has been marked as a duplicate of this bug. ***