[f-spot] Fix recursive copying for FolderExport



commit c7e043660048285ca2e88e84b2c0cf735d7b9cc2
Author: Paul Wellner Bou <paul purecodes org>
Date:   Tue May 18 08:55:20 2010 +0200

    Fix recursive copying for FolderExport
    
    https://bugzilla.gnome.org/show_bug.cgi?id=618798

 extensions/Exporters/FolderExport/FolderExport.cs |   11 +++--
 src/Makefile.am                                   |    1 +
 src/Utils/FileExtensions.cs                       |   51 +++++++++++++++++++++
 3 files changed, 58 insertions(+), 5 deletions(-)
---
diff --git a/extensions/Exporters/FolderExport/FolderExport.cs b/extensions/Exporters/FolderExport/FolderExport.cs
index 7bab676..561b64a 100644
--- a/extensions/Exporters/FolderExport/FolderExport.cs
+++ b/extensions/Exporters/FolderExport/FolderExport.cs
@@ -18,7 +18,7 @@
  */
 
 //This should be used to export the selected pics to an original gallery
-//located on a VFS location.
+//located on a GIO location.
 using System;
 using System.IO;
 using System.Runtime.InteropServices;
@@ -165,7 +165,7 @@ namespace FSpotFolderExport {
 			bool result = true;
 
 			try {
-				Dialog.Hide ();
+				Gtk.Application.Invoke (delegate {Dialog.Hide ();});
 
 				GLib.File source = GLib.FileFactory.NewForPath (Path.Combine (gallery_path, gallery_name));
 				GLib.File target = GLib.FileFactory.NewForPath (Path.Combine (dest.Path, source.Basename));
@@ -250,7 +250,7 @@ namespace FSpotFolderExport {
 				// otherwise we xfer
 				if (!dest.IsNative) {
 					System.Console.WriteLine ("Xfering {0} to {1}", source.ToString (), target.ToString ());
-					result = source.Copy (target, GLib.FileCopyFlags.Overwrite, null, Progress);
+					result = FileExtensions.CopyRecursive (source, target, GLib.FileCopyFlags.Overwrite, null, Progress);
 				}
 
 				if (result == true) {
@@ -264,7 +264,8 @@ namespace FSpotFolderExport {
 				}
 
 				if (open) {
-					GtkBeans.Global.ShowUri (Dialog.Screen, target.Uri.ToString () );
+					Log.Debug (String.Format (Catalog.GetString ("Open URI {0}"), target.Uri.ToString ()));
+					Gtk.Application.Invoke (delegate {GtkBeans.Global.ShowUri (Dialog.Screen, target.Uri.ToString () );});
 				}
 
 				// Save these settings for next time
@@ -277,7 +278,7 @@ namespace FSpotFolderExport {
 				Preferences.Set (METHOD_KEY, static_radio.Active ? "static" : original_radio.Active ? "original" : "folder" );
 				Preferences.Set (URI_KEY, uri_chooser.Uri);
 			} catch (System.Exception e) {
-				// Console.WriteLine (e);
+				Log.Debug (e.ToString ());
 				progress_dialog.Message = e.ToString ();
 				progress_dialog.ProgressText = Catalog.GetString ("Error Transferring");
 			} finally {
diff --git a/src/Makefile.am b/src/Makefile.am
index 3b68737..5657f7a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -56,6 +56,7 @@ UTILS_CSDISTFILES =				\
 	$(srcdir)/Utils/CairoUtils.cs		\
 	$(srcdir)/Utils/ConsoleCrayon.cs	\
 	$(srcdir)/Utils/DbUtils.cs		\
+	$(srcdir)/Utils/FileExtensions.cs	\
 	$(srcdir)/Utils/GdkUtils.cs		\
 	$(srcdir)/Utils/GtkUtil.cs		\
 	$(srcdir)/Utils/Log.cs			\
diff --git a/src/Utils/FileExtensions.cs b/src/Utils/FileExtensions.cs
new file mode 100644
index 0000000..5b409ca
--- /dev/null
+++ b/src/Utils/FileExtensions.cs
@@ -0,0 +1,51 @@
+/*
+ * FSpot.Utils.FileExtensions.cs
+ *
+ * Author(s)
+ * 	Paul Wellner Bou <paul purecodes org>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+using System;
+using System.IO;
+using Mono.Unix;
+using GLib;
+
+namespace FSpot.Utils
+{
+	public static class FileExtensions
+	{
+			public static bool CopyRecursive (GLib.File source, GLib.File target, GLib.FileCopyFlags flags, GLib.Cancellable cancellable, GLib.FileProgressCallback callback)
+		{
+			bool result = true;
+			try {
+				result = result && source.Copy (target, flags, cancellable, callback);
+			} catch (GLib.GException e) {
+				// copy recursively, assuming that source is a directory
+				// TODO: what is better: catching an exception each time a directory is copied or
+				// checking if source is a directory and/or checking here if
+				// error message == 'Can't recursively copy directory'?
+				GLib.FileType ft = source.QueryFileType (GLib.FileQueryInfoFlags.None, null);
+				if (ft.GetType () != GLib.FileType.Directory.GetType ())
+					throw e;
+				
+				if (!target.Exists)
+					target.MakeDirectoryWithParents (null);
+				
+				GLib.FileEnumerator fe = source.EnumerateChildren ("standard::*", GLib.FileQueryInfoFlags.None, null);
+				GLib.FileInfo fi = fe.NextFile ();
+				while (fi != null) {
+					GLib.File source_file = GLib.FileFactory.NewForPath (Path.Combine (source.Path, fi.Name));
+					GLib.File target_file = GLib.FileFactory.NewForPath (Path.Combine (target.Path, fi.Name));
+					Log.Debug (String.Format (Catalog.GetString("Copying {0} -> {1}"), source_file.Path, target_file.Path));
+					result = result && CopyRecursive(source_file, target_file, flags, cancellable, callback);
+					fi = fe.NextFile ();
+				}
+				fe.Close (cancellable);
+			}
+			
+			return result;
+		}
+	}
+}



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