From 00fdbafeb7f93eb9812236e71f2877bd3efba4af Mon Sep 17 00:00:00 2001 From: tutman96 <11356668+tutman96@users.noreply.github.com> Date: Sat, 4 Jan 2025 15:53:07 +0000 Subject: [PATCH] Write plugin database to tmp file first --- internal/plugin/database.go | 8 ++++++-- ui/src/components/UploadPluginDialog.tsx | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/plugin/database.go b/internal/plugin/database.go index d5d6f60..2f9a89f 100644 --- a/internal/plugin/database.go +++ b/internal/plugin/database.go @@ -38,9 +38,9 @@ func (d *PluginDatabase) Save() error { d.saveMutex.Lock() defer d.saveMutex.Unlock() - file, err := os.Create(databaseFile) + file, err := os.Create(databaseFile + ".tmp") if err != nil { - return fmt.Errorf("failed to create plugin database: %v", err) + return fmt.Errorf("failed to create plugin database tmp: %v", err) } defer file.Close() @@ -50,5 +50,9 @@ func (d *PluginDatabase) Save() error { return fmt.Errorf("failed to encode plugin database: %v", err) } + if err := os.Rename(databaseFile+".tmp", databaseFile); err != nil { + return fmt.Errorf("failed to move plugin database to active file: %v", err) + } + return nil } diff --git a/ui/src/components/UploadPluginDialog.tsx b/ui/src/components/UploadPluginDialog.tsx index 5cbd4ad..b0c4f02 100644 --- a/ui/src/components/UploadPluginDialog.tsx +++ b/ui/src/components/UploadPluginDialog.tsx @@ -576,7 +576,7 @@ function InstallPluginView({ description={ !manifest ? `Extracting plugin from ${filename}...` : - `Do you want to install the plugin?` + `Do you want to install this plugin?` } /> {manifest && (