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 540597 - Files get not copied to "Music Library" when imported twice
Files get not copied to "Music Library" when imported twice
Status: RESOLVED FIXED
Product: banshee
Classification: Other
Component: Importing
1.0.0
Other All
: Normal critical
: 1.x
Assigned To: Banshee Maintainers
Banshee Maintainers
: 561978 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-06-28 11:34 UTC by Timm
Modified: 2009-09-22 23:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to rename file name if exist (edited to add using) (1.02 KB, patch)
2009-07-16 06:09 UTC, olivier dufour
needs-work Details | Review
Always copy the file when we're supposed to (1.88 KB, patch)
2009-07-18 18:26 UTC, Bertrand Lorentz
none Details | Review
Patch to fix import when copy to file is selected and also duplicate imports (4.46 KB, patch)
2009-09-08 16:42 UTC, Jack Deslippe
needs-work Details | Review
Updated Patch To Fit HACKERS Style (4.47 KB, patch)
2009-09-10 00:28 UTC, Jack Deslippe
none Details | Review

Description Timm 2008-06-28 11:34:26 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:
Comment 1 Bertrand Lorentz 2008-06-30 16:27:16 UTC
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.
Comment 2 Timm 2008-06-30 16:31:09 UTC
Yes, I have ever since.
Otherwise it wouldn't have worked for the first import, would it?
Comment 3 Bertrand Lorentz 2008-06-30 17:16:12 UTC
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.
Comment 4 Timm 2008-06-30 18:04:32 UTC
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.
Comment 5 olivier dufour 2009-07-16 06:09:40 UTC
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 6 olivier dufour 2009-07-16 06:14:54 UTC
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
Comment 7 Bertrand Lorentz 2009-07-18 15:43:36 UTC
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.
Comment 8 Bertrand Lorentz 2009-07-18 18:17:18 UTC
*** Bug 561978 has been marked as a duplicate of this bug. ***
Comment 9 Bertrand Lorentz 2009-07-18 18:26:52 UTC
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.
Comment 10 William Witt 2009-07-18 19:56:59 UTC
The patch works for me.  We should think about hashing the source and destination to prevent copying the exact same file twice.
Comment 11 Jack Deslippe 2009-09-08 16:42:44 UTC
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.
Comment 12 Jack Deslippe 2009-09-08 16:43:19 UTC
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 13 Gabriel Burt 2009-09-09 18:03:26 UTC
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
Comment 14 Jack Deslippe 2009-09-10 00:28:01 UTC
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
Comment 15 Gabriel Burt 2009-09-22 23:11:35 UTC
Thanks Jack, committed.