diff --git a/api.go b/api.go index b4170e7..174453c 100644 --- a/api.go +++ b/api.go @@ -446,6 +446,8 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc } } if invite.UserExpiry { + app.storage.usersLock.Lock() + defer app.storage.usersLock.Unlock() expiry := time.Now().Add(time.Duration(60*(invite.UserDays*24+invite.UserHours)+invite.UserMinutes) * time.Minute) app.storage.users[id] = expiry if err := app.storage.storeUsers(); err != nil { @@ -473,6 +475,8 @@ func (app *appContext) ExtendExpiry(gc *gin.Context) { respondBool(400, false, gc) return } + app.storage.usersLock.Lock() + defer app.storage.usersLock.Unlock() for _, id := range req.Users { if expiry, ok := app.storage.users[id]; ok { app.storage.users[id] = expiry.Add(time.Duration(60*(req.Days*24+req.Hours)+req.Minutes) * time.Minute) diff --git a/main.go b/main.go index 713d546..6a60418 100644 --- a/main.go +++ b/main.go @@ -353,17 +353,29 @@ func start(asDaemon, firstCall bool) { app.debug.Println("Loading storage") app.storage.invite_path = app.config.Section("files").Key("invites").String() - app.storage.loadInvites() + if err := app.storage.loadInvites(); err != nil { + app.err.Printf("Failed to load Invites: %v", err) + } app.storage.emails_path = app.config.Section("files").Key("emails").String() - app.storage.loadEmails() + if err := app.storage.loadEmails(); err != nil { + app.err.Printf("Failed to load Emails: %v", err) + } app.storage.policy_path = app.config.Section("files").Key("user_template").String() - app.storage.loadPolicy() + if err := app.storage.loadPolicy(); err != nil { + app.err.Printf("Failed to load Policy: %v", err) + } app.storage.configuration_path = app.config.Section("files").Key("user_configuration").String() - app.storage.loadConfiguration() + if err := app.storage.loadConfiguration(); err != nil { + app.err.Printf("Failed to load Configuration: %v", err) + } app.storage.displayprefs_path = app.config.Section("files").Key("user_displayprefs").String() - app.storage.loadDisplayprefs() + if err := app.storage.loadDisplayprefs(); err != nil { + app.err.Printf("Failed to load Displayprefs: %v", err) + } app.storage.users_path = app.config.Section("files").Key("users").String() - app.storage.loadUsers() + if err := app.storage.loadUsers(); err != nil { + app.err.Printf("Failed to load Users: %v", err) + } app.storage.profiles_path = app.config.Section("files").Key("user_profiles").String() app.storage.loadProfiles() diff --git a/storage.go b/storage.go index ad2396c..447f6a0 100644 --- a/storage.go +++ b/storage.go @@ -26,7 +26,7 @@ type Storage struct { policy mediabrowser.Policy configuration mediabrowser.Configuration lang Lang - invitesLock sync.Mutex + invitesLock, usersLock sync.Mutex } type customEmails struct { @@ -480,6 +480,8 @@ func (st *Storage) storeInvites() error { } func (st *Storage) loadUsers() error { + st.usersLock.Lock() + defer st.usersLock.Unlock() return loadJSON(st.users_path, &st.users) } diff --git a/userdaemon.go b/userdaemon.go index cfa7e0e..35a4287 100644 --- a/userdaemon.go +++ b/userdaemon.go @@ -44,6 +44,12 @@ func (rt *userDaemon) run() { } func (app *appContext) checkUsers() { + if err := app.storage.loadUsers(); err != nil { + app.err.Printf("Failed to load user expiries: %v", err) + return + } + app.storage.usersLock.Lock() + defer app.storage.usersLock.Unlock() if len(app.storage.users) == 0 { return }