GNOME Bugzilla – Bug 540597
Files get not copied to "Music Library" when imported twice
Last modified: 2009-09-22 23:11:35 UTC
Please describe the problem: If you import music twice into Banshee (same files), then it Banshee doesn't copy the files the second time into its Library. Steps to reproduce: 1. Pick some music album you wanted to delete anyway 2. Import this into Banshee (see that it is moved to "Music Library") 3. Import the exact same source-files again (see that they are still in their original place) 4. Search for the album in Banshee and delete all found songs from drive Actual results: The music source-files are also deleted. Expected results: That Banshee copied the music twice into its "Music Library" and deleted it twice from there, and *not from my sources*. Does this happen every time? Yeah, sadly. Other information:
Did you have the "Copy files to media folders when importing" option checked when you imported the files ? It's in the Edit > Preferences menu option.
Yes, I have ever since. Otherwise it wouldn't have worked for the first import, would it?
I just wanted to make sure I understood the problem, and I think I do now, and I was able to reproduce it. However, I don't think having the same files twice in the library is a good idea. Another solution would be that at the second import, the files are just copied again, and no new entry is added to the Library. It would be more of a "refresh" than an import. But that would mean that any metadata changes written to the first files would be lost.
You mean overwriting the data? If it's equal, why copy it any way? -> right if not, copy it again.. why not have the exact same id3-tags and filename on two different versions? may happen. but please, never overwrite or delete user's data without asking.
Created attachment 138501 [details] [review] patch to rename file name if exist (edited to add using) Here is a patch. Can you test if it solve the issue? I think it solve the bug 540394 too.
Comment on attachment 138501 [details] [review] patch to rename file name if exist (edited to add using) Index: AudioCdRipper.cs =================================================================== --- AudioCdRipper.cs (révision 5209) +++ AudioCdRipper.cs (copie de travail) @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; +using System.Text; using Mono.Unix; using Mono.Addins; @@ -182,8 +183,20 @@ user_job.Status = status; SafeUri uri = new SafeUri (FileNamePattern.BuildFull (track, null)); + int i = 0; + SafeUri uri2 = uri; + StringBuilder bld = new StringBuilder(); + //To avoid the overwrite of previous file + while (Banshee.IO.File.Exists(uri2)) { + bld = new StringBuilder(); + bld.Append(uri); + bld.Append("("); + bld.Append(i); + bld.Append(")"); + uri2 = new SafeUri(bld.ToString()); + } bool tagging_supported; - ripper.RipTrack (track.IndexOnDisc, track, uri, out tagging_supported); + ripper.RipTrack (track.IndexOnDisc, track, uri2, out tagging_supported); } #region Ripper Event Handlers
Olivier, thanks for the patch ! This bug is about importing music files (mp3, ogg, etc.), so I don't think your patch addresses the issue. I guess it might fix bug 540394.
*** Bug 561978 has been marked as a duplicate of this bug. ***
Created attachment 138695 [details] [review] Always copy the file when we're supposed to If the destination already exists, change filename.ext to filename (1).ext, instead of not doing the copy. Please test and check if this fixes the issues in all cases.
The patch works for me. We should think about hashing the source and destination to prevent copying the exact same file twice.
Created attachment 142710 [details] [review] Patch to fix import when copy to file is selected and also duplicate imports Patch to fix import when copy to file is selected and also duplicate imports.
Bertrand, I am uploading a revised patch that I think solves this bug and several other bugs. Basically it is the same as your patch but it also checks to see if the file size of the new and existing file are the same. If they are, it does NOT do the renaming and copy. The new patch also prevents the file from being added to the database twice. Thus, this also fixes the bugs where people complain about when you import a directory twice - you get two files in your database (the new and original location). The addition is very important when importing music from Android Phones amazon source for example - every time I do it, I get duplicates in my library. Can you please review the patch and get it into git-master?
Comment on attachment 142710 [details] [review] Patch to fix import when copy to file is selected and also duplicate imports Thanks Jack. 1. Follow HACKING style guide - eg 4 spaces for a tab, spaces around if's, etc 2. Get rid of the copy_success DebugFormat line
Created attachment 142842 [details] [review] Updated Patch To Fit HACKERS Style Hi Gabriel, I believe I fixed the patch given your comments can you please review it again and commit it if it is sufficient. -Jack
Thanks Jack, committed.