Bug 475528 - Songs get deleted from local collection when new ones are added
Summary: Songs get deleted from local collection when new ones are added
Status: RESOLVED FIXED
Alias: None
Product: amarok
Classification: Applications
Component: Collections/Local (show other bugs)
Version: 2.9.82
Platform: openSUSE Linux
: NOR major
Target Milestone: kf5
Assignee: Amarok Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-10-12 17:56 UTC by Stephan Schöttl
Modified: 2024-04-20 11:52 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Schöttl 2023-10-12 17:56:06 UTC
SUMMARY
When I add a new subdirectory to the folder Reggae in my local collection, all songs in the folder Reggeaton disappear from the local collection. Using the Tools > Update Collection menu item, the track re-appear, but all statistics (first played, last played, play count) and lyrics are lost.

STEPS TO REPRODUCE
1. Create folders Reggae and Reggaeton in the same parent directory and add both to the local collection.
2. Add sub-directories and songs to both of those folder.
3. Play each song at least once.
4. Add lyrics to some of the songs.
5. With amarok running, add a new subdirectory with a few songs to the Reggae folder.

OBSERVED RESULT
All songs from the Reggaeton folder disappear from the collection. They may re-appear when the collection is re-scanned, but then statistics and lyrics are lost.

EXPECTED RESULT
All old and new songs should appear in the local collection.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: OpenSUSE 15.5 5.14.21-150500.55.19-default #1 SMP PREEMPT_DYNAMIC Tue Aug 8 22:15:01 UTC 2023 (9908c29) x86_64 x86_64 x86_64 GNU/Linux
KDE Plasma Version: 5.102.0
KDE Frameworks Version: 5.103.0

ADDITIONAL INFORMATION
The same happened previously with the folders Latin and Latin_Hip-Hop. Could it have an effect that one folder name is a substring of the other folder name?
Comment 1 Tuomas Nurmi 2024-04-17 10:08:41 UTC
Thank you for the report!
Seems to be reproducable, I will inspect & try to fix this before 3.0.
Comment 2 Tuomas Nurmi 2024-04-18 11:00:06 UTC
Managed to narrow down reproduction a bit:
Start with an empty embedded database, have tracks
Foghat/Foghat - 01 - Honey Hush.ogg
Fogh/16 - Punk Reggae Party.ogg
in library path. Scan the library and observe both of them appear in collection browser.

Add both tracks to playlist. The other one does not have to be played.
Start playing Foghat/Energized/Foghat - 01 - Honey Hush.ogg, skip to nearly end of the track but make sure it plays some seconds., check that playcount after playing is 1

touch Fogh/

Foghat - Honey Hush disappears from collection. If not with first try, playing the track some seconds and doing touch Fogh/ again will probably do trick.
Comment 3 Bug Janitor Service 2024-04-19 20:54:15 UTC
A possibly relevant merge request was started @ https://invent.kde.org/multimedia/amarok/-/merge_requests/88
Comment 4 Tuomas Nurmi 2024-04-20 11:11:47 UTC
Git commit 154e31b5b3002f0bb290ef55ec0eb6c612113e91 by Tuomas Nurmi.
Committed on 20/04/2024 at 11:04.
Pushed by nurmi into branch 'master'.

Fix erronous database query

After three days of debugging, refreshing related autotests, writing more tests,
hunting for differences between autotest mock components and real ones and digging
deep into database queries related to saving paths, I am happy to announce that I
have a fix which changes a single _ to /.

I guess the original idea might have been to handle both unix and windows path
separators. However, based on my digging, I think Qt does that anyhow in every case
before anything is written to db. Also, the directories saved into db always come
from MountPointManager's getRelativePath, which has never a trailing /, so the
slash instead of underscore should always be a correct character here to match
subdirectories.

M  +1    -1    src/core-impl/collections/db/sql/SqlScanResultProcessor.cpp

https://invent.kde.org/multimedia/amarok/-/commit/154e31b5b3002f0bb290ef55ec0eb6c612113e91
Comment 5 Stephan Schöttl 2024-04-20 11:48:51 UTC
(In reply to Tuomas Nurmi from comment #4)
> After three days of debugging, refreshing related autotests, writing more
> tests,
> hunting for differences between autotest mock components and real ones and
> digging
> deep into database queries related to saving paths, I am happy to announce
> that I
> have a fix which changes a single _ to /.
Thank you!
Comment 6 Tuomas Nurmi 2024-04-20 11:52:06 UTC
(In reply to Tuomas Nurmi from comment #4)
> Git commit 154e31b5b3002f0bb290ef55ec0eb6c612113e91 by Tuomas Nurmi.
> Committed on 20/04/2024 at 11:04.
> Pushed by nurmi into branch 'master'.
> 
> Fix erronous database query
> 
> After three days of debugging, refreshing related autotests, writing more
> tests,
> hunting for differences between autotest mock components and real ones and
> digging
> deep into database queries related to saving paths, I am happy to announce
> that I
> have a fix which changes a single _ to /.
> 
> I guess the original idea might have been to handle both unix and windows
> path
> separators. However, based on my digging, I think Qt does that anyhow in
> every case
> before anything is written to db. Also, the directories saved into db always
> come
> from MountPointManager's getRelativePath, which has never a trailing /, so
> the
> slash instead of underscore should always be a correct character here to
> match
> subdirectories.
> 
> M  +1    -1    src/core-impl/collections/db/sql/SqlScanResultProcessor.cpp
> 
> https://invent.kde.org/multimedia/amarok/-/commit/
> 154e31b5b3002f0bb290ef55ec0eb6c612113e91

Your welcome!
I think I've hit this bug myself once or twice, too, but it was too random to get a good grasp on where to inspect. Your observation on the substrings in folder names was very valuable in finding the cause of this, so thank you for that!