1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 17:10:10 +00:00

add more error logging; mutex for app.storage.users

This commit is contained in:
Harvey Tindall 2021-04-06 13:44:52 +01:00
parent ab3d5f3321
commit 76b822213e
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
4 changed files with 31 additions and 7 deletions

4
api.go
View File

@ -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)

24
main.go
View File

@ -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()

View File

@ -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)
}

View File

@ -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
}