chore(storage): do not read/write to user file when updating in maintainer mode
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,13 +32,16 @@ func New(logger Infoer, filepath string) (storage *Storage, err error) {
|
||||
|
||||
storage = &Storage{
|
||||
hardcodedServers: hardcodedServers,
|
||||
mergedServers: hardcodedServers,
|
||||
logger: logger,
|
||||
filepath: filepath,
|
||||
}
|
||||
|
||||
if filepath != "" {
|
||||
if err := storage.syncServers(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return storage, nil
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user