Add to Library: 'Path is already in your collection' logic incorrect

Bug #218544 reported by SCdF
18
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Exaile
Fix Released
Medium
Johannes Sasongko

Bug Description

The logic that checks whether a path you are about to add is already in your collection seems to be incorrect.

Let's say you have /home/me/music and /home/me/music-sortMe. If you where to add /home/me/music it would then not let you add /home/me/music-sortMe. I don't know python, but presumably this is because path.startswith(item) is evalutating to true because /home/me/music is fully contained within /home/me/music-sortMe.

Off the top of my head the quickest fix would be to check for path == newPath && newPath.startswith(path+"/"), or possibly newPath+"/".startsWith(path+"/"). That should stop it thinking that directories that start the same are the same.

That would possibly introduce an issue if '/' was in your library, since nothing would start with '//' and could thus be entered multiple times.

Revision history for this message
SCdF (iconoclasmic) wrote :

So my quickfix seems to work, at least in the naive sense. Basically I've changed those if statements to look like the following:

/xl/gui/Library.py
--
144 if (path+'/').startswith(item+'/'):
<snip>
150 elif (item+'/').startswith(path+'/'):
--

Haven't looked at the '/' thing, would presume it would fail (i.e. let you have '/' and '/home' in your library).

Changed in exaile:
importance: Undecided → Medium
milestone: none → 0.2.14
status: New → Confirmed
Revision history for this message
qoiwejqioejqio (qioeujqioejqioe-deactivatedaccount) wrote :

Works fine here except for the / case in which you can still add its subdirectories. I've made a workaround to this:

/xl/gui/Library.py
--
144 if (path+'/').startswith(item+'/') or item == '/':
--

Very simple, but i don't know if works on all cases.

Revision history for this message
Veronika Loitzenbauer (vero) wrote :

Another appearance of this bug in my case:
If you first add "/home/me/music-sortMe" and then try to add "/home/me/music", "/home/me/music" replaces "/home/me/music-sortMe".

Revision history for this message
Johannes Sasongko (sjohannes) wrote :

Wow, I never fixed this? *sigh* Assigning to myself so I remember.

In any case, I can't use the patch as-is because it uses the non-portable "/" path separator. At the very least it should use os.sep (IIRC). Will do a more thorough review later.

Changed in exaile:
assignee: nobody → sjohannes
milestone: 0.2.14 → 0.3.0
status: Confirmed → In Progress
Changed in exaile:
status: In Progress → Fix Committed
reacocard (reacocard)
Changed in exaile:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.