[banshee] Fix issue with copying file to library (BGO #540597)
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [banshee] Fix issue with copying file to library (BGO #540597)
- Date: Tue, 22 Sep 2009 23:11:14 +0000 (UTC)
commit f101ad01b518b0f49859101dcb27fed3c4f31c49
Author: Jack Deslippe <jdeslip gmail com>
Date: Wed Sep 9 17:22:24 2009 -0700
Fix issue with copying file to library (BGO #540597)
Signed-off-by: Gabriel Burt <gabriel burt gmail com>
.../DatabaseImportManager.cs | 7 ++++-
.../DatabaseTrackInfo.cs | 25 ++++++++++++++++----
2 files changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs
index d36b28b..31162b8 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs
@@ -178,11 +178,14 @@ namespace Banshee.Collection.Database
track.PrimarySource = trackPrimarySourceChooser (track);
+ bool save_track = true;
if (track.PrimarySource is Banshee.Library.LibrarySource) {
- track.CopyToLibraryIfAppropriate (force_copy);
+ save_track = track.CopyToLibraryIfAppropriate (force_copy);
}
- track.Save (false);
+ if (save_track) {
+ track.Save (false);
+ }
ServiceManager.DbConnection.CommitTransaction ();
} catch (Exception) {
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
index ac58a49..57abea6 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
@@ -610,12 +610,14 @@ namespace Banshee.Collection.Database
}
}
- public void CopyToLibraryIfAppropriate (bool force_copy)
+ public bool CopyToLibraryIfAppropriate (bool force_copy)
{
+ bool copy_success = true;
+
SafeUri old_uri = this.Uri;
if (old_uri == null) {
// Get out quick, no URI set yet.
- return;
+ return copy_success;
}
bool in_library = old_uri.AbsolutePath.StartsWith (PrimarySource.BaseDirectoryWithSeparator);
@@ -626,16 +628,29 @@ namespace Banshee.Collection.Database
try {
if (Banshee.IO.File.Exists (new_uri)) {
- Hyena.Log.DebugFormat ("Not copying {0} to library because there is already a file at {1}", old_uri, new_uri);
- return;
+ if (Banshee.IO.File.GetSize (old_uri) == Banshee.IO.File.GetSize (new_uri)) {
+ Hyena.Log.DebugFormat ("Not copying {0} to library because there is already a file of same size at {1}", old_uri, new_uri);
+ copy_success = false;
+ return copy_success;
+ } else {
+ string extension = Path.GetExtension (new_filename);
+ string filename_no_ext = new_filename.Remove (new_filename.Length - extension.Length);
+ int duplicate_index = 1;
+ while (Banshee.IO.File.Exists (new_uri)) {
+ new_filename = String.Format ("{0} ({1}){2}", filename_no_ext, duplicate_index, extension);
+ new_uri = new SafeUri (new_filename);
+ duplicate_index++;
+ }
+ }
}
-
+
Banshee.IO.File.Copy (old_uri, new_uri, false);
Uri = new_uri;
} catch (Exception e) {
Log.ErrorFormat ("Exception copying into library: {0}", e);
}
}
+ return copy_success;
}
private static HyenaSqliteCommand get_uri_id_cmd = new HyenaSqliteCommand ("SELECT TrackID FROM CoreTracks WHERE Uri = ? LIMIT 1");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]