lib/config, lib/model: Use path from locations to check disk space for db (#5525)

This commit is contained in:
Simon Frei 2019-02-12 13:25:11 +01:00 committed by Audrius Butkevicius
parent d85ef949be
commit 4299af1c63
4 changed files with 8 additions and 19 deletions

View File

@ -278,7 +278,7 @@ func (f *FolderConfiguration) CheckAvailableSpace(req int64) error {
}
usage.Free -= req
if usage.Free > 0 {
if err := checkFreeSpace(f.MinDiskFree, usage); err == nil {
if err := CheckFreeSpace(f.MinDiskFree, usage); err == nil {
return nil
}
}

View File

@ -78,7 +78,7 @@ func (s *Size) ParseDefault(str string) error {
return err
}
func checkFreeSpace(req Size, usage fs.Usage) error {
func CheckFreeSpace(req Size, usage fs.Usage) error {
val := req.BaseValue()
if val <= 0 {
return nil

View File

@ -7,14 +7,11 @@
package config
import (
"fmt"
"os"
"path/filepath"
"sync/atomic"
"time"
"github.com/syncthing/syncthing/lib/events"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/sync"
@ -488,15 +485,3 @@ func (w *Wrapper) AddOrUpdatePendingFolder(id, label string, device protocol.Dev
panic("bug: adding pending folder for non-existing device")
}
// CheckHomeFreeSpace returns nil if the home disk has the required amount of
// free space, or if home disk free space checking is disabled.
func (w *Wrapper) CheckHomeFreeSpace() error {
path := filepath.Dir(w.ConfigPath())
if usage, err := fs.NewFilesystem(fs.FilesystemTypeBasic, path).Usage("."); err == nil {
if err = checkFreeSpace(w.Options().MinHomeDiskFree, usage); err != nil {
return fmt.Errorf("insufficient space on home disk (%v): %v", path, err)
}
}
return nil
}

View File

@ -21,6 +21,7 @@ import (
"github.com/syncthing/syncthing/lib/events"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/ignore"
"github.com/syncthing/syncthing/lib/locations"
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/scanner"
@ -269,8 +270,11 @@ func (f *folder) getHealthError() error {
return err
}
if err := f.model.cfg.CheckHomeFreeSpace(); err != nil {
return err
dbPath := locations.Get(locations.Database)
if usage, err := fs.NewFilesystem(fs.FilesystemTypeBasic, dbPath).Usage("."); err == nil {
if err = config.CheckFreeSpace(f.model.cfg.Options().MinHomeDiskFree, usage); err != nil {
return fmt.Errorf("insufficient space on disk for database (%v): %v", dbPath, err)
}
}
return nil