aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-07-31 14:56:46 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-07-31 14:56:46 -0700
commit9360423f0aae6d7ce63cc9a4b20c031a58e06820 (patch)
treec10d64f77f84a0f040b4c15decdaa440119016fb /internal
parent0ee4d86eeffe9c72dffd9e92cb33b27c8950940f (diff)
Migrate user account yaml files to new Access flag format if needed
Diffstat (limited to 'internal')
-rw-r--r--internal/mobius/account_manager.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/internal/mobius/account_manager.go b/internal/mobius/account_manager.go
index 3bb5cbc..6bbc951 100644
--- a/internal/mobius/account_manager.go
+++ b/internal/mobius/account_manager.go
@@ -8,6 +8,7 @@ import (
"os"
"path"
"path/filepath"
+ "strings"
"sync"
)
@@ -45,11 +46,25 @@ func NewYAMLAccountManager(accountDir string) (*YAMLAccountManager, error) {
return nil, fmt.Errorf("no accounts found in directory: %s", accountDir)
}
- for _, file := range matches {
+ for _, filePath := range matches {
var account hotline.Account
- if err = loadFromYAMLFile(file, &account); err != nil {
- return nil, fmt.Errorf("error loading account %s: %w", file, err)
+ fileContents, err := os.ReadFile(filePath)
+ if err != nil {
+ return nil, fmt.Errorf("read file: %v", err)
+ }
+
+ if err := yaml.Unmarshal(fileContents, &account); err != nil {
+ return nil, fmt.Errorf("unmarshal: %v", err)
}
+
+ // Check the account file contents for a field name that only appears in the new AccessBitmap flag format.
+ // If not present, re-save the file to migrate it from the old array of ints format to new bool flag format.
+ if !strings.Contains(string(fileContents), " DownloadFile:") {
+ if err := accountMgr.Update(account, account.Login); err != nil {
+ return nil, fmt.Errorf("migrate account to new access flag format: %v", err)
+ }
+ }
+
accountMgr.accounts[account.Login] = account
}