Skip to content

Commit 4299af1

Browse files
imsodinAudriusButkevicius
authored andcommitted
lib/config, lib/model: Use path from locations to check disk space for db (syncthing#5525)
1 parent d85ef94 commit 4299af1

File tree

4 files changed

+8
-19
lines changed

4 files changed

+8
-19
lines changed

lib/config/folderconfiguration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (f *FolderConfiguration) CheckAvailableSpace(req int64) error {
278278
}
279279
usage.Free -= req
280280
if usage.Free > 0 {
281-
if err := checkFreeSpace(f.MinDiskFree, usage); err == nil {
281+
if err := CheckFreeSpace(f.MinDiskFree, usage); err == nil {
282282
return nil
283283
}
284284
}

lib/config/size.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (s *Size) ParseDefault(str string) error {
7878
return err
7979
}
8080

81-
func checkFreeSpace(req Size, usage fs.Usage) error {
81+
func CheckFreeSpace(req Size, usage fs.Usage) error {
8282
val := req.BaseValue()
8383
if val <= 0 {
8484
return nil

lib/config/wrapper.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77
package config
88

99
import (
10-
"fmt"
1110
"os"
12-
"path/filepath"
1311
"sync/atomic"
1412
"time"
1513

1614
"github.com/syncthing/syncthing/lib/events"
17-
"github.com/syncthing/syncthing/lib/fs"
1815
"github.com/syncthing/syncthing/lib/osutil"
1916
"github.com/syncthing/syncthing/lib/protocol"
2017
"github.com/syncthing/syncthing/lib/sync"
@@ -488,15 +485,3 @@ func (w *Wrapper) AddOrUpdatePendingFolder(id, label string, device protocol.Dev
488485

489486
panic("bug: adding pending folder for non-existing device")
490487
}
491-
492-
// CheckHomeFreeSpace returns nil if the home disk has the required amount of
493-
// free space, or if home disk free space checking is disabled.
494-
func (w *Wrapper) CheckHomeFreeSpace() error {
495-
path := filepath.Dir(w.ConfigPath())
496-
if usage, err := fs.NewFilesystem(fs.FilesystemTypeBasic, path).Usage("."); err == nil {
497-
if err = checkFreeSpace(w.Options().MinHomeDiskFree, usage); err != nil {
498-
return fmt.Errorf("insufficient space on home disk (%v): %v", path, err)
499-
}
500-
}
501-
return nil
502-
}

lib/model/folder.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/syncthing/syncthing/lib/events"
2222
"github.com/syncthing/syncthing/lib/fs"
2323
"github.com/syncthing/syncthing/lib/ignore"
24+
"github.com/syncthing/syncthing/lib/locations"
2425
"github.com/syncthing/syncthing/lib/osutil"
2526
"github.com/syncthing/syncthing/lib/protocol"
2627
"github.com/syncthing/syncthing/lib/scanner"
@@ -269,8 +270,11 @@ func (f *folder) getHealthError() error {
269270
return err
270271
}
271272

272-
if err := f.model.cfg.CheckHomeFreeSpace(); err != nil {
273-
return err
273+
dbPath := locations.Get(locations.Database)
274+
if usage, err := fs.NewFilesystem(fs.FilesystemTypeBasic, dbPath).Usage("."); err == nil {
275+
if err = config.CheckFreeSpace(f.model.cfg.Options().MinHomeDiskFree, usage); err != nil {
276+
return fmt.Errorf("insufficient space on disk for database (%v): %v", dbPath, err)
277+
}
274278
}
275279

276280
return nil

0 commit comments

Comments
 (0)