From 150ea841912f5dc280a42e6d522f78c86afe60b0 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Wed, 9 Apr 2025 17:27:34 +0800 Subject: [PATCH] Make sure temporary files deleted --- .../FirefoxBookmarkLoader.cs | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs index b356d08b8..75f26d322 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs @@ -41,6 +41,8 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader if (string.IsNullOrEmpty(placesPath) || !File.Exists(placesPath)) return bookmarks; + var tempDbPath = Path.Combine(_faviconCacheDir, $"tempplaces_{Guid.NewGuid()}.sqlite"); + try { // Try to register file monitoring @@ -54,7 +56,6 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader } // Use a copy to avoid lock issues with the original file - var tempDbPath = Path.Combine(_faviconCacheDir, $"tempplaces_{Guid.NewGuid()}.sqlite"); File.Copy(placesPath, tempDbPath, true); // Connect to database and execute query @@ -83,31 +84,32 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader // https://github.com/dotnet/efcore/issues/26580 SqliteConnection.ClearPool(dbConnection); dbConnection.Close(); - - // Delete temporary file - try - { - File.Delete(tempDbPath); - } - catch (Exception ex) - { - Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex); - } } catch (Exception ex) { Main._context.API.LogException(ClassName, $"Failed to load Firefox bookmarks: {placesPath}", ex); } + // Delete temporary file + try + { + File.Delete(tempDbPath); + } + catch (Exception ex) + { + Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex); + } + return bookmarks; } private void LoadFaviconsFromDb(string faviconDbPath, List bookmarks) { + var tempDbPath = Path.Combine(_faviconCacheDir, $"tempfavicons_{Guid.NewGuid()}.sqlite"); + try { // Use a copy to avoid lock issues with the original file - var tempDbPath = Path.Combine(_faviconCacheDir, $"tempfavicons_{Guid.NewGuid()}.sqlite"); File.Copy(faviconDbPath, tempDbPath, true); var defaultIconPath = Path.Combine( @@ -177,21 +179,21 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader // https://github.com/dotnet/efcore/issues/26580 SqliteConnection.ClearPool(connection); connection.Close(); - - // Delete temporary file - try - { - File.Delete(tempDbPath); - } - catch (Exception ex) - { - Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex); - } } catch (Exception ex) { Main._context.API.LogException(ClassName, $"Failed to load Firefox favicon DB: {faviconDbPath}", ex); } + + // Delete temporary file + try + { + File.Delete(tempDbPath); + } + catch (Exception ex) + { + Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex); + } } private static void SaveBitmapData(byte[] imageData, string outputPath)