From 6e99ca573e683cb3a3280b9fb75869385e172284 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Mon, 17 Nov 2025 15:29:41 +0000 Subject: [PATCH] chore(storage): do not read/write to user file when updating in maintainer mode --- internal/cli/update.go | 6 +++++- internal/storage/storage.go | 10 +++++++--- internal/storage/sync.go | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/cli/update.go b/internal/cli/update.go index ae05bd23..2acad8ae 100644 --- a/internal/cli/update.go +++ b/internal/cli/update.go @@ -81,7 +81,11 @@ func (c *CLI) Update(ctx context.Context, args []string, logger UpdaterLogger) e return fmt.Errorf("options validation failed: %w", err) } - storage, err := storage.New(logger, constants.ServersData) + serversDataPath := constants.ServersData + if maintainerMode { + serversDataPath = "" + } + storage, err := storage.New(logger, serversDataPath) if err != nil { return fmt.Errorf("creating servers storage: %w", err) } diff --git a/internal/storage/storage.go b/internal/storage/storage.go index 5210b07f..4dd7d3dd 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -23,7 +23,8 @@ type Infoer interface { // New creates a new storage and reads the servers from the // embedded servers file and the file on disk. -// Passing an empty filepath disables writing servers to a file. +// Passing an empty filepath disables the reading and writing of +// servers. func New(logger Infoer, filepath string) (storage *Storage, err error) { // A unit test prevents any error from being returned // and ensures all providers are part of the servers returned. @@ -31,12 +32,15 @@ func New(logger Infoer, filepath string) (storage *Storage, err error) { storage = &Storage{ hardcodedServers: hardcodedServers, + mergedServers: hardcodedServers, logger: logger, filepath: filepath, } - if err := storage.syncServers(); err != nil { - return nil, err + if filepath != "" { + if err := storage.syncServers(); err != nil { + return nil, err + } } return storage, nil diff --git a/internal/storage/sync.go b/internal/storage/sync.go index 1e0b539b..f31b5ca9 100644 --- a/internal/storage/sync.go +++ b/internal/storage/sync.go @@ -46,7 +46,7 @@ func (s *Storage) syncServers() (err error) { } // Eventually write file - if s.filepath == "" || reflect.DeepEqual(serversOnFile, s.mergedServers) { + if reflect.DeepEqual(serversOnFile, s.mergedServers) { return nil }