[f-spot] Avoid use of exceptions, fix directory type comparison



commit 57f4a5586ae373406c9bce9ddbb0967396ad2aab
Author: Paul Wellner Bou <paul purecodes org>
Date:   Wed May 19 09:40:08 2010 +0200

    Avoid use of exceptions, fix directory type comparison
    
    https://bugzilla.gnome.org/show_bug.cgi?id=619014

 src/Utils/FileExtensions.cs |   47 +++++++++++++++++++++----------------------
 1 files changed, 23 insertions(+), 24 deletions(-)
---
diff --git a/src/Utils/FileExtensions.cs b/src/Utils/FileExtensions.cs
index 6daffc7..8f48877 100644
--- a/src/Utils/FileExtensions.cs
+++ b/src/Utils/FileExtensions.cs
@@ -19,32 +19,31 @@ namespace FSpot.Utils
 		public static bool CopyRecursive (this 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 && source_file.CopyRecursive(target_file, flags, cancellable, callback);
-					fi = fe.NextFile ();
-				}
-				fe.Close (cancellable);
+			
+			GLib.FileType ft = source.QueryFileType (GLib.FileQueryInfoFlags.None, cancellable);
+			
+			Log.Debug (Catalog.GetString("Try to copy {0} -> {1}"), source.Path, target.Path);
+			
+			if (ft != GLib.FileType.Directory) {
+				Log.Debug (Catalog.GetString("Copying {0} -> {1}"), source.Path, target.Path);
+				return source.Copy (target, flags, cancellable, callback);
 			}
 			
+			if (!target.Exists) {
+				Log.Debug ("Creating directory: "+target.Path);
+				result = result && target.MakeDirectoryWithParents (cancellable);
+			}
+			
+			GLib.FileEnumerator fe = source.EnumerateChildren ("standard::name", GLib.FileQueryInfoFlags.None, cancellable);
+			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 (Catalog.GetString("CopyRecursive {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]