Add upgrade locking mechanism to core ui serving module

This commit is contained in:
Daniel
2025-04-07 15:26:35 +02:00
parent b1bc5e2d0e
commit 438f43156f
7 changed files with 122 additions and 86 deletions

View File

@@ -2,35 +2,21 @@ package ui
import (
"github.com/safing/portmaster/base/api"
"github.com/safing/portmaster/base/log"
)
func registerAPIEndpoints() error {
func (ui *UI) registerAPIEndpoints() error {
return api.RegisterEndpoint(api.Endpoint{
Path: "ui/reload",
Write: api.PermitUser,
ActionFunc: reloadUI,
ActionFunc: ui.reloadUI,
Name: "Reload UI Assets",
Description: "Removes all assets from the cache and reloads the current (possibly updated) version from disk when requested.",
})
}
func reloadUI(_ *api.Request) (msg string, err error) {
appsLock.Lock()
defer appsLock.Unlock()
func (ui *UI) reloadUI(_ *api.Request) (msg string, err error) {
// Close all archives.
for id, archiveFS := range apps {
err := archiveFS.Close()
if err != nil {
log.Warningf("ui: failed to close archive %s: %s", id, err)
}
}
// Reset index.
for key := range apps {
delete(apps, key)
}
ui.CloseArchives()
return "all ui archives successfully reloaded", nil
}