Skip to content

Commit 43934c4

Browse files
committed
review feedback, nit
1 parent fdfee20 commit 43934c4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Services/FaviconService.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,24 @@ await Parallel.ForEachAsync(bookmarks, options, async (bookmark, token) =>
121121
var localData = await _localExtractor.GetFaviconDataAsync(bookmark, token);
122122
if (localData != null)
123123
{
124-
var (pngData, _) = await _imageConverter.ToPngAsync(new MemoryStream(localData), token);
124+
using var ms = new MemoryStream(localData, writable: false);
125+
var (pngData, _) = await _imageConverter.ToPngAsync(ms, token);
125126
if (pngData != null)
126127
{
127128
var path = hostCachePath;
129+
var tmp = path + "." + Guid.NewGuid().ToString("N") + ".tmp";
128130
try
129131
{
130-
await File.WriteAllBytesAsync(path, pngData, token);
132+
await File.WriteAllBytesAsync(tmp, pngData, token);
133+
try { File.Move(tmp, path, overwrite: false); }
134+
catch (IOException)
135+
{
136+
// Another thread may have created it concurrently.
137+
}
131138
}
132-
catch (IOException)
139+
finally
133140
{
134-
// Another thread may have created it concurrently.
141+
try { if (File.Exists(tmp)) File.Delete(tmp); } catch { /* best effort */ }
135142
}
136143
if (File.Exists(path))
137144
{

0 commit comments

Comments
 (0)