fix: version doesn't update

pull/2849/head v3.7.1
Noah Hsu 2022-12-30 00:24:10 +08:00
parent dad3012ec3
commit f777a2fab4
1 changed files with 12 additions and 11 deletions

View File

@ -5,9 +5,9 @@ import (
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/op"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/pkg/utils/random"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"gorm.io/gorm"
)
@ -18,7 +18,7 @@ func initSettings() {
// check deprecated
settings, err := op.GetSettingItems()
if err != nil {
log.Fatalf("failed get settings: %+v", err)
utils.Log.Fatalf("failed get settings: %+v", err)
}
for i := range settings {
@ -26,7 +26,7 @@ func initSettings() {
settings[i].Flag = model.DEPRECATED
err = op.SaveSettingItem(&settings[i])
if err != nil {
log.Fatalf("failed save setting: %+v", err)
utils.Log.Fatalf("failed save setting: %+v", err)
}
}
}
@ -37,24 +37,25 @@ func initSettings() {
// err
stored, err := op.GetSettingItemByKey(item.Key)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
log.Fatalf("failed get setting: %+v", err)
utils.Log.Fatalf("failed get setting: %+v", err)
continue
}
// save
if stored != nil {
if stored != nil && item.Key != conf.VERSION {
item.Value = stored.Value
}
if stored == nil || *item != *stored {
err = op.SaveSettingItem(item)
if err != nil {
log.Fatalf("failed save setting: %+v", err)
utils.Log.Fatalf("failed save setting: %+v", err)
}
} else {
// Not save so needs to execute hook
_, err = op.HandleSettingItemHook(item)
if err != nil {
utils.Log.Errorf("failed to execute hook on %s: %+v", item.Key, err)
}
continue
}
// Not save so needs to execute hook
op.HandleSettingItemHook(item)
}
}