lib/config, lib/model: Configurable folder marker name (fixes #1126)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4483
This commit is contained in:
Jakob Borg
2017-11-05 12:18:05 +00:00
committed by Audrius Butkevicius
parent 166273b357
commit 9c855ab22e
6 changed files with 111 additions and 21 deletions

View File

@@ -20,6 +20,8 @@ var (
errMarkerMissing = errors.New("folder marker missing")
)
const DefaultMarkerName = ".stfolder"
type FolderConfiguration struct {
ID string `xml:"id,attr" json:"id"`
Label string `xml:"label,attr" json:"label"`
@@ -47,6 +49,7 @@ type FolderConfiguration struct {
DisableTempIndexes bool `xml:"disableTempIndexes" json:"disableTempIndexes"`
Paused bool `xml:"paused" json:"paused"`
WeakHashThresholdPct int `xml:"weakHashThresholdPct" json:"weakHashThresholdPct"` // Use weak hash if more than X percent of the file has changed. Set to -1 to always use weak hash.
MarkerName string `xml:"markerName" json:"markerName"`
cachedFilesystem fs.Filesystem
@@ -91,6 +94,12 @@ func (f *FolderConfiguration) CreateMarker() error {
if err := f.CheckPath(); err != errMarkerMissing {
return err
}
if f.MarkerName != DefaultMarkerName {
// Folder uses a non-default marker so we shouldn't mess with it.
// Pretend we created it and let the subsequent health checks sort
// out the actual situation.
return nil
}
permBits := fs.FileMode(0777)
if runtime.GOOS == "windows" {
@@ -99,7 +108,7 @@ func (f *FolderConfiguration) CreateMarker() error {
permBits = 0700
}
fs := f.Filesystem()
err := fs.Mkdir(".stfolder", permBits)
err := fs.Mkdir(DefaultMarkerName, permBits)
if err != nil {
return err
}
@@ -108,7 +117,7 @@ func (f *FolderConfiguration) CreateMarker() error {
} else if err := dir.Sync(); err != nil {
l.Debugln("folder marker: fsync . failed:", err)
}
fs.Hide(".stfolder")
fs.Hide(DefaultMarkerName)
return nil
}
@@ -120,7 +129,7 @@ func (f *FolderConfiguration) CheckPath() error {
return errPathMissing
}
_, err = f.Filesystem().Stat(".stfolder")
_, err = f.Filesystem().Stat(f.MarkerName)
if err != nil {
return errMarkerMissing
}
@@ -187,6 +196,10 @@ func (f *FolderConfiguration) prepare() {
if f.WeakHashThresholdPct == 0 {
f.WeakHashThresholdPct = 25
}
if f.MarkerName == "" {
f.MarkerName = DefaultMarkerName
}
}
type FolderDeviceConfigurationList []FolderDeviceConfiguration