[f-spot/taglib-metadata: 11/13] Remove the home-made safe-writing pattern.



commit 91fa1b92616729eacae8af542db55aea1251c36d
Author: Ruben Vermeersch <ruben savanne be>
Date:   Tue Jun 15 21:15:33 2010 +0200

    Remove the home-made safe-writing pattern.
    
    The file abstraction now handles that.

 src/Jobs/SyncMetadataJob.cs |   33 ++++-----------------------------
 src/RotateCommand.cs        |   27 +--------------------------
 2 files changed, 5 insertions(+), 55 deletions(-)
---
diff --git a/src/Jobs/SyncMetadataJob.cs b/src/Jobs/SyncMetadataJob.cs
index 04d1463..6e10659 100644
--- a/src/Jobs/SyncMetadataJob.cs
+++ b/src/Jobs/SyncMetadataJob.cs
@@ -44,31 +44,6 @@ namespace FSpot.Jobs {
             return false;
         }
 
-        public void SaveMetaData (TagLib.File image, string path)
-        {
-            // FIXME: This currently copies the file out to a tmp file, overwrites it
-            // and restores the tmp file in case of failure. Should obviously be the
-            // other way around, but Taglib# doesn't have an interface to do this.
-            // https://bugzilla.gnome.org/show_bug.cgi?id=618768
-
-            var uri = new SafeUri (path);
-            var tmp = System.IO.Path.GetTempFileName ();
-            var tmp_uri = new SafeUri (tmp);
-
-            var orig_file = GLib.FileFactory.NewForUri (uri);
-            var tmp_file = GLib.FileFactory.NewForUri (tmp_uri);
-
-            tmp_file.Delete ();
-            orig_file.Copy (tmp_file, GLib.FileCopyFlags.AllMetadata | GLib.FileCopyFlags.Overwrite, null, null);
-
-            try {
-                image.Save ();
-            } catch (Exception e) {
-                Log.DebugException (e);
-                tmp_file.Copy (orig_file, GLib.FileCopyFlags.AllMetadata | GLib.FileCopyFlags.Overwrite, null, null);
-            }
-        }
-
         void WriteMetadataToImage (Photo photo)
         {
             string path = photo.DefaultVersion.Uri.LocalPath;
@@ -79,19 +54,19 @@ namespace FSpot.Jobs {
             for (int i = 0; i < tags.Length; i++)
                 names [i] = tags [i].Name;
 
-            //var res = new GIOTagLibFileAbstraction () { Uri = photo.DefaultVersion.Uri };
-            var res = photo.DefaultVersion.Uri.AbsolutePath;
+            var res = new GIOTagLibFileAbstraction () { Uri = photo.DefaultVersion.Uri };
             using (var metadata = TagLib.File.Create (res) as TagLib.Image.File) {
                 metadata.GetTag (TagLib.TagTypes.XMP, true);
 
                 var tag = metadata.ImageTag;
                 tag.DateTime = photo.Time;
-                tag.Comment = photo.Description;
+                tag.Comment = photo.Description ?? String.Empty;
                 tag.Keywords = names;
                 tag.Rating = photo.Rating;
                 tag.Software = FSpot.Defines.PACKAGE + " version " + FSpot.Defines.VERSION;
 
-                SaveMetaData (metadata, path);
+                Hyena.Log.Information (photo.DefaultVersion.Uri);
+                metadata.Save ();
             }
         }
     }
diff --git a/src/RotateCommand.cs b/src/RotateCommand.cs
index 7a15a6d..43f5bd3 100644
--- a/src/RotateCommand.cs
+++ b/src/RotateCommand.cs
@@ -68,38 +68,13 @@ namespace FSpot {
                         : FSpot.Utils.PixbufUtils.Rotate270 (tag.Orientation);
 
                     tag.Orientation = orientation;
-                    SaveMetaData (metadata, original_path);
+                    metadata.Save ();
                 }
             } catch (Exception e) {
                 throw new RotateException (Catalog.GetString ("Unable to rotate this type of photo"), original_path);
             }
 		}
 
-        private static void SaveMetaData (TagLib.File image, string path)
-        {
-            // FIXME: This currently copies the file out to a tmp file, overwrites it
-            // and restores the tmp file in case of failure. Should obviously be the
-            // other way around, but Taglib# doesn't have an interface to do this.
-            // https://bugzilla.gnome.org/show_bug.cgi?id=618768
-
-            var uri = new SafeUri (path);
-            var tmp = System.IO.Path.GetTempFileName ();
-            var tmp_uri = new SafeUri (tmp);
-
-            var orig_file = GLib.FileFactory.NewForUri (uri);
-            var tmp_file = GLib.FileFactory.NewForUri (tmp_uri);
-
-            tmp_file.Delete ();
-            orig_file.Copy (tmp_file, GLib.FileCopyFlags.AllMetadata | GLib.FileCopyFlags.Overwrite, null, null);
-
-            try {
-                image.Save ();
-            } catch (Exception e) {
-                tmp_file.Copy (orig_file, GLib.FileCopyFlags.AllMetadata | GLib.FileCopyFlags.Overwrite, null, null);
-                throw e;
-            }
-        }
-		       
 		private void Rotate (string original_path, RotateDirection dir)
 		{
 			RotateOrientation (original_path, dir);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]