Skip to content

Commit 150ea84

Browse files
committed
Make sure temporary files deleted
1 parent 62a5dd7 commit 150ea84

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ protected List<Bookmark> GetBookmarksFromPath(string placesPath)
4141
if (string.IsNullOrEmpty(placesPath) || !File.Exists(placesPath))
4242
return bookmarks;
4343

44+
var tempDbPath = Path.Combine(_faviconCacheDir, $"tempplaces_{Guid.NewGuid()}.sqlite");
45+
4446
try
4547
{
4648
// Try to register file monitoring
@@ -54,7 +56,6 @@ protected List<Bookmark> GetBookmarksFromPath(string placesPath)
5456
}
5557

5658
// Use a copy to avoid lock issues with the original file
57-
var tempDbPath = Path.Combine(_faviconCacheDir, $"tempplaces_{Guid.NewGuid()}.sqlite");
5859
File.Copy(placesPath, tempDbPath, true);
5960

6061
// Connect to database and execute query
@@ -83,31 +84,32 @@ protected List<Bookmark> GetBookmarksFromPath(string placesPath)
8384
// https://github.com/dotnet/efcore/issues/26580
8485
SqliteConnection.ClearPool(dbConnection);
8586
dbConnection.Close();
86-
87-
// Delete temporary file
88-
try
89-
{
90-
File.Delete(tempDbPath);
91-
}
92-
catch (Exception ex)
93-
{
94-
Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex);
95-
}
9687
}
9788
catch (Exception ex)
9889
{
9990
Main._context.API.LogException(ClassName, $"Failed to load Firefox bookmarks: {placesPath}", ex);
10091
}
10192

93+
// Delete temporary file
94+
try
95+
{
96+
File.Delete(tempDbPath);
97+
}
98+
catch (Exception ex)
99+
{
100+
Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex);
101+
}
102+
102103
return bookmarks;
103104
}
104105

105106
private void LoadFaviconsFromDb(string faviconDbPath, List<Bookmark> bookmarks)
106107
{
108+
var tempDbPath = Path.Combine(_faviconCacheDir, $"tempfavicons_{Guid.NewGuid()}.sqlite");
109+
107110
try
108111
{
109112
// Use a copy to avoid lock issues with the original file
110-
var tempDbPath = Path.Combine(_faviconCacheDir, $"tempfavicons_{Guid.NewGuid()}.sqlite");
111113
File.Copy(faviconDbPath, tempDbPath, true);
112114

113115
var defaultIconPath = Path.Combine(
@@ -177,21 +179,21 @@ ORDER BY i.width DESC -- Select largest icon available
177179
// https://github.com/dotnet/efcore/issues/26580
178180
SqliteConnection.ClearPool(connection);
179181
connection.Close();
180-
181-
// Delete temporary file
182-
try
183-
{
184-
File.Delete(tempDbPath);
185-
}
186-
catch (Exception ex)
187-
{
188-
Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex);
189-
}
190182
}
191183
catch (Exception ex)
192184
{
193185
Main._context.API.LogException(ClassName, $"Failed to load Firefox favicon DB: {faviconDbPath}", ex);
194186
}
187+
188+
// Delete temporary file
189+
try
190+
{
191+
File.Delete(tempDbPath);
192+
}
193+
catch (Exception ex)
194+
{
195+
Main._context.API.LogException(ClassName, $"Failed to delete temporary favicon DB: {tempDbPath}", ex);
196+
}
195197
}
196198

197199
private static void SaveBitmapData(byte[] imageData, string outputPath)

0 commit comments

Comments
 (0)