mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-18 11:05:14 +00:00
parent
10f9d95cd2
commit
f890fe6fd3
@ -261,8 +261,8 @@ func (f *FolderConfiguration) CheckAvailableSpace(req uint64) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if !checkAvailableSpace(req, f.MinDiskFree, usage) {
|
if err := checkAvailableSpace(req, f.MinDiskFree, usage); err != nil {
|
||||||
return fmt.Errorf("insufficient space in %v %v", fs.Type(), fs.URI())
|
return fmt.Errorf("insufficient space in folder %v (%v): %w", f.Description(), fs.URI(), err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -83,10 +83,10 @@ func CheckFreeSpace(minFree Size, usage fs.Usage) error {
|
|||||||
if minFree.Percentage() {
|
if minFree.Percentage() {
|
||||||
freePct := (float64(usage.Free) / float64(usage.Total)) * 100
|
freePct := (float64(usage.Free) / float64(usage.Total)) * 100
|
||||||
if freePct < val {
|
if freePct < val {
|
||||||
return fmt.Errorf("%.1f %% < %v", freePct, minFree)
|
return fmt.Errorf("current %.2f %% < required %v", freePct, minFree)
|
||||||
}
|
}
|
||||||
} else if float64(usage.Free) < val {
|
} else if float64(usage.Free) < val {
|
||||||
return fmt.Errorf("%sB < %v", formatSI(usage.Free), minFree)
|
return fmt.Errorf("current %sB < required %v", formatSI(usage.Free), minFree)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -94,12 +94,12 @@ func CheckFreeSpace(minFree Size, usage fs.Usage) error {
|
|||||||
|
|
||||||
// checkAvailableSpace checks that the free space does not fall below the minimum
|
// checkAvailableSpace checks that the free space does not fall below the minimum
|
||||||
// required free space, considering additional required space for a future operation.
|
// required free space, considering additional required space for a future operation.
|
||||||
func checkAvailableSpace(req uint64, minFree Size, usage fs.Usage) bool {
|
func checkAvailableSpace(req uint64, minFree Size, usage fs.Usage) error {
|
||||||
if usage.Free < req {
|
if usage.Free < req {
|
||||||
return false
|
return fmt.Errorf("current %sB < required %sB", formatSI(usage.Free), formatSI(req))
|
||||||
}
|
}
|
||||||
usage.Free -= req
|
usage.Free -= req
|
||||||
return CheckFreeSpace(minFree, usage) == nil
|
return CheckFreeSpace(minFree, usage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatSI(b uint64) string {
|
func formatSI(b uint64) string {
|
||||||
|
@ -159,8 +159,10 @@ func TestCheckAvailableSize(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
usage := fs.Usage{Free: tc.free, Total: tc.total}
|
usage := fs.Usage{Free: tc.free, Total: tc.total}
|
||||||
if ok := checkAvailableSpace(tc.req, minFree, usage); ok != tc.ok {
|
err = checkAvailableSpace(tc.req, minFree, usage)
|
||||||
t.Errorf("checkAvailableSpace(%v, %v, %v) == %v, expected %v", tc.req, minFree, usage, ok, tc.ok)
|
t.Log(err)
|
||||||
|
if (err == nil) != tc.ok {
|
||||||
|
t.Errorf("checkAvailableSpace(%v, %v, %v) == %v, expected %v", tc.req, minFree, usage, err, tc.ok)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ func (f *folder) getHealthErrorWithoutIgnores() error {
|
|||||||
dbPath := locations.Get(locations.Database)
|
dbPath := locations.Get(locations.Database)
|
||||||
if usage, err := fs.NewFilesystem(fs.FilesystemTypeBasic, dbPath).Usage("."); err == nil {
|
if usage, err := fs.NewFilesystem(fs.FilesystemTypeBasic, dbPath).Usage("."); err == nil {
|
||||||
if err = config.CheckFreeSpace(f.model.cfg.Options().MinHomeDiskFree, usage); err != nil {
|
if err = config.CheckFreeSpace(f.model.cfg.Options().MinHomeDiskFree, usage); err != nil {
|
||||||
return errors.Wrapf(err, "insufficient space on disk for database (%v)", dbPath)
|
return fmt.Errorf("insufficient space on disk for database (%v): %w", dbPath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user