mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
Don't check for free space on master folders (fixes #2236)
Also clean up the logic a little, I thought it was a bit muddled.
This commit is contained in:
parent
47c7351b16
commit
209bc59e8c
@ -1713,7 +1713,7 @@ func (m *Model) BringToFront(folder, file string) {
|
|||||||
func (m *Model) CheckFolderHealth(id string) error {
|
func (m *Model) CheckFolderHealth(id string) error {
|
||||||
if minFree := m.cfg.Options().MinHomeDiskFreePct; minFree > 0 {
|
if minFree := m.cfg.Options().MinHomeDiskFreePct; minFree > 0 {
|
||||||
if free, err := osutil.DiskFreePercentage(m.cfg.ConfigPath()); err == nil && free < minFree {
|
if free, err := osutil.DiskFreePercentage(m.cfg.ConfigPath()); err == nil && free < minFree {
|
||||||
return errors.New("home disk is out of space")
|
return errors.New("home disk has insufficient free space")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1723,29 +1723,41 @@ func (m *Model) CheckFolderHealth(id string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fi, err := os.Stat(folder.Path())
|
fi, err := os.Stat(folder.Path())
|
||||||
if v, ok := m.CurrentLocalVersion(id); ok && v > 0 {
|
|
||||||
// Safety check. If the cached index contains files but the
|
v, ok := m.CurrentLocalVersion(id)
|
||||||
// folder doesn't exist, we have a problem. We would assume
|
indexHasFiles := ok && v > 0
|
||||||
// that all files have been deleted which might not be the case,
|
|
||||||
// so mark it as invalid instead.
|
if indexHasFiles {
|
||||||
if err != nil || !fi.IsDir() {
|
// There are files in the folder according to the index, so it must
|
||||||
|
// have existed and had a correct marker at some point. Verify that
|
||||||
|
// this is still the case.
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case err != nil || !fi.IsDir():
|
||||||
err = errors.New("folder path missing")
|
err = errors.New("folder path missing")
|
||||||
} else if !folder.HasMarker() {
|
|
||||||
|
case !folder.HasMarker():
|
||||||
err = errors.New("folder marker missing")
|
err = errors.New("folder marker missing")
|
||||||
} else if free, errDfp := osutil.DiskFreePercentage(folder.Path()); errDfp == nil && free < folder.MinDiskFreePct {
|
|
||||||
err = errors.New("out of disk space")
|
case !folder.ReadOnly:
|
||||||
|
// Check for free space, if it isn't a master folder. We aren't
|
||||||
|
// going to change the contents of master folders, so we don't
|
||||||
|
// care about the amount of free space there.
|
||||||
|
if free, errDfp := osutil.DiskFreePercentage(folder.Path()); errDfp == nil && free < folder.MinDiskFreePct {
|
||||||
|
err = errors.New("insufficient free space")
|
||||||
}
|
}
|
||||||
} else if os.IsNotExist(err) {
|
}
|
||||||
// If we don't have any files in the index, and the directory
|
} else {
|
||||||
// doesn't exist, try creating it.
|
// It's a blank folder, so this may the first time we're looking at
|
||||||
|
// it. Attempt to create and tag with our marker as appropriate.
|
||||||
|
|
||||||
|
if os.IsNotExist(err) {
|
||||||
err = osutil.MkdirAll(folder.Path(), 0700)
|
err = osutil.MkdirAll(folder.Path(), 0700)
|
||||||
if err == nil {
|
}
|
||||||
|
|
||||||
|
if err == nil && !folder.HasMarker() {
|
||||||
err = folder.CreateMarker()
|
err = folder.CreateMarker()
|
||||||
}
|
}
|
||||||
} else if !folder.HasMarker() {
|
|
||||||
// If we don't have any files in the index, and the path does exist
|
|
||||||
// but the marker is not there, create it.
|
|
||||||
err = folder.CreateMarker()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m.fmut.RLock()
|
m.fmut.RLock()
|
||||||
|
Loading…
Reference in New Issue
Block a user