[f-spot] Remove addin-db on initialization failure, retry.



commit 633d23757ddffaf579b04de8c3bb3e461b1d19c1
Author: Ruben Vermeersch <ruben savanne be>
Date:   Thu Jul 22 18:50:57 2010 +0200

    Remove addin-db on initialization failure, retry.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=624313

 src/Utils/FileExtensions.cs |   18 ++++++++++++++++++
 src/main.cs                 |   31 +++++++++++++++++++++++++++++--
 2 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/src/Utils/FileExtensions.cs b/src/Utils/FileExtensions.cs
index f8fbe8b..9b32cec 100644
--- a/src/Utils/FileExtensions.cs
+++ b/src/Utils/FileExtensions.cs
@@ -44,5 +44,23 @@ namespace FSpot.Utils
 			fe.Close (cancellable);
 			return result;
 		}
+
+		public static void DeleteRecursive (this GLib.File file)
+		{
+			// FIXME: no cancellation support
+
+			var type = file.QueryFileType (FileQueryInfoFlags.None, null);
+			if (type != FileType.Directory) {
+				file.Delete (null);
+				return;
+			}
+
+			var children = file.EnumerateChildren ("standard::name", GLib.FileQueryInfoFlags.None, null);
+			foreach (GLib.FileInfo child in children) {
+				var child_file = FileFactory.NewForPath (Path.Combine (file.Path, child.Name));
+				child_file.DeleteRecursive ();
+			}
+			file.Delete (null);
+		}
 	}
 }
diff --git a/src/main.cs b/src/main.cs
index 00234cb..58efd1f 100644
--- a/src/main.cs
+++ b/src/main.cs
@@ -277,8 +277,13 @@ namespace FSpot
 		static void InitializeAddins ()
 		{
 			uint timer = Log.InformationTimerStart ("Initializing Mono.Addins");
-			AddinManager.Initialize (FSpot.Global.BaseDirectory);
-			AddinManager.Registry.Update (null);
+			try {
+				UpdatePlugins ();
+			} catch (Exception e) {
+				Log.Debug ("Failed to initialize plugins, will remove addin-db and try again.");
+				Log.DebugException (e);
+				ResetPluginDb ();
+			}
 			SetupService setupService = new SetupService (AddinManager.Registry);
 			foreach (AddinRepository repo in setupService.Repositories.GetRepositories ()) {
 				if (repo.Url.StartsWith ("http://addins.f-spot.org/";)) {
@@ -289,6 +294,28 @@ namespace FSpot
 			Log.DebugTimerPrint (timer, "Mono.Addins Initialization took {0}");
 		}
 
+		static void UpdatePlugins ()
+		{
+			AddinManager.Initialize (FSpot.Global.BaseDirectory);
+			AddinManager.Registry.Update (null);
+		}
+
+		static void ResetPluginDb ()
+		{
+			// Nuke addin-db
+			var directory = GLib.FileFactory.NewForUri (new SafeUri (FSpot.Global.BaseDirectory));
+			var list = directory.EnumerateChildren ("standard::name", GLib.FileQueryInfoFlags.None, null);
+			foreach (GLib.FileInfo info in list) {
+				if (info.Name.StartsWith ("addin-db-")) {
+					var file = GLib.FileFactory.NewForPath (Path.Combine (directory.Path, info.Name));
+					file.DeleteRecursive ();
+				}
+			}
+
+			// Try again
+			UpdatePlugins ();
+		}
+
 		static void Startup ()
 		{
 			if (ApplicationContext.CommandLine.Contains ("slideshow"))



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