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:
committed by
Audrius Butkevicius
parent
166273b357
commit
9c855ab22e
@@ -399,17 +399,21 @@ func convertV22V23(cfg *Configuration) {
|
||||
// begin with.
|
||||
permBits = 0700
|
||||
}
|
||||
|
||||
// Upgrade code remains hardcoded for .stfolder despite configurable
|
||||
// marker name in later versions.
|
||||
|
||||
for i := range cfg.Folders {
|
||||
fs := cfg.Folders[i].Filesystem()
|
||||
// Invalid config posted, or tests.
|
||||
if fs == nil {
|
||||
continue
|
||||
}
|
||||
if stat, err := fs.Stat(".stfolder"); err == nil && !stat.IsDir() {
|
||||
err = fs.Remove(".stfolder")
|
||||
if stat, err := fs.Stat(DefaultMarkerName); err == nil && !stat.IsDir() {
|
||||
err = fs.Remove(DefaultMarkerName)
|
||||
if err == nil {
|
||||
err = fs.Mkdir(".stfolder", permBits)
|
||||
fs.Hide(".stfolder") // ignore error
|
||||
err = fs.Mkdir(DefaultMarkerName, permBits)
|
||||
fs.Hide(DefaultMarkerName) // ignore error
|
||||
}
|
||||
if err != nil {
|
||||
l.Infoln("Failed to upgrade folder marker:", err)
|
||||
|
||||
@@ -85,13 +85,13 @@ func TestDefaultValues(t *testing.T) {
|
||||
|
||||
func TestDeviceConfig(t *testing.T) {
|
||||
for i := OldestHandledVersion; i <= CurrentVersion; i++ {
|
||||
os.RemoveAll("testdata/.stfolder")
|
||||
os.RemoveAll(filepath.Join("testdata", DefaultMarkerName))
|
||||
wr, err := Load(fmt.Sprintf("testdata/v%d.xml", i), device1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = os.Stat("testdata/.stfolder")
|
||||
_, err = os.Stat(filepath.Join("testdata", DefaultMarkerName))
|
||||
if i < 6 && err != nil {
|
||||
t.Fatal(err)
|
||||
} else if i >= 6 && err == nil {
|
||||
@@ -120,6 +120,7 @@ func TestDeviceConfig(t *testing.T) {
|
||||
Params: map[string]string{},
|
||||
},
|
||||
WeakHashThresholdPct: 25,
|
||||
MarkerName: DefaultMarkerName,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user