Stop folder when running out of disk space (fixes #2057)
& tweaks by calmh
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/calmh/du"
|
||||
"github.com/syncthing/syncthing/lib/sync"
|
||||
)
|
||||
|
||||
@@ -210,3 +211,13 @@ func init() {
|
||||
func IsWindowsExecutable(path string) bool {
|
||||
return execExts[strings.ToLower(filepath.Ext(path))]
|
||||
}
|
||||
|
||||
func DiskFreeBytes(path string) (free int64, err error) {
|
||||
u, err := du.Get(path)
|
||||
return u.FreeBytes, err
|
||||
}
|
||||
|
||||
func DiskFreePercentage(path string) (freePct float64, err error) {
|
||||
u, err := du.Get(path)
|
||||
return (float64(u.FreeBytes) / float64(u.TotalBytes)) * 100, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user