Switch the database from LevelDB to SQLite, for greater stability and simpler code. Co-authored-by: Tommy van der Vorst <tommy@pixelspark.nl> Co-authored-by: bt90 <btom1990@googlemail.com>
This commit is contained in:
co-authored by
Tommy van der Vorst
bt90
parent
b1c8f88a44
commit
025905fcdf
@@ -20,7 +20,6 @@ import (
|
||||
"github.com/shirou/gopsutil/v4/disk"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/db"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
)
|
||||
@@ -119,26 +118,24 @@ func (f FolderConfiguration) Copy() FolderConfiguration {
|
||||
// Filesystem creates a filesystem for the path and options of this folder.
|
||||
// The fset parameter may be nil, in which case no mtime handling on top of
|
||||
// the filesystem is provided.
|
||||
func (f FolderConfiguration) Filesystem(fset *db.FileSet) fs.Filesystem {
|
||||
func (f FolderConfiguration) Filesystem(extraOpts ...fs.Option) fs.Filesystem {
|
||||
// This is intentionally not a pointer method, because things like
|
||||
// cfg.Folders["default"].Filesystem(nil) should be valid.
|
||||
opts := make([]fs.Option, 0, 3)
|
||||
var opts []fs.Option
|
||||
if f.FilesystemType == FilesystemTypeBasic && f.JunctionsAsDirs {
|
||||
opts = append(opts, new(fs.OptionJunctionsAsDirs))
|
||||
}
|
||||
if !f.CaseSensitiveFS {
|
||||
opts = append(opts, new(fs.OptionDetectCaseConflicts))
|
||||
}
|
||||
if fset != nil {
|
||||
opts = append(opts, fset.MtimeOption())
|
||||
}
|
||||
opts = append(opts, extraOpts...)
|
||||
return fs.NewFilesystem(f.FilesystemType.ToFS(), f.Path, opts...)
|
||||
}
|
||||
|
||||
func (f FolderConfiguration) ModTimeWindow() time.Duration {
|
||||
dur := time.Duration(f.RawModTimeWindowS) * time.Second
|
||||
if f.RawModTimeWindowS < 1 && build.IsAndroid {
|
||||
if usage, err := disk.Usage(f.Filesystem(nil).URI()); err != nil {
|
||||
if usage, err := disk.Usage(f.Filesystem().URI()); err != nil {
|
||||
dur = 2 * time.Second
|
||||
l.Debugf(`Detecting FS at "%v" on android: Setting mtime window to 2s: err == "%v"`, f.Path, err)
|
||||
} else if strings.HasPrefix(strings.ToLower(usage.Fstype), "ext2") || strings.HasPrefix(strings.ToLower(usage.Fstype), "ext3") || strings.HasPrefix(strings.ToLower(usage.Fstype), "ext4") {
|
||||
@@ -162,7 +159,7 @@ func (f *FolderConfiguration) CreateMarker() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
ffs := f.Filesystem(nil)
|
||||
ffs := f.Filesystem()
|
||||
|
||||
// Create the marker as a directory
|
||||
err := ffs.Mkdir(DefaultMarkerName, 0o755)
|
||||
@@ -189,7 +186,7 @@ func (f *FolderConfiguration) CreateMarker() error {
|
||||
}
|
||||
|
||||
func (f *FolderConfiguration) RemoveMarker() error {
|
||||
ffs := f.Filesystem(nil)
|
||||
ffs := f.Filesystem()
|
||||
_ = ffs.Remove(filepath.Join(DefaultMarkerName, f.markerFilename()))
|
||||
return ffs.Remove(DefaultMarkerName)
|
||||
}
|
||||
@@ -209,7 +206,7 @@ func (f *FolderConfiguration) markerContents() []byte {
|
||||
|
||||
// CheckPath returns nil if the folder root exists and contains the marker file
|
||||
func (f *FolderConfiguration) CheckPath() error {
|
||||
return f.checkFilesystemPath(f.Filesystem(nil), ".")
|
||||
return f.checkFilesystemPath(f.Filesystem(), ".")
|
||||
}
|
||||
|
||||
func (f *FolderConfiguration) checkFilesystemPath(ffs fs.Filesystem, path string) error {
|
||||
@@ -252,7 +249,7 @@ func (f *FolderConfiguration) CreateRoot() (err error) {
|
||||
permBits = 0o700
|
||||
}
|
||||
|
||||
filesystem := f.Filesystem(nil)
|
||||
filesystem := f.Filesystem()
|
||||
|
||||
if _, err = filesystem.Stat("."); fs.IsNotExist(err) {
|
||||
err = filesystem.MkdirAll(".", permBits)
|
||||
@@ -363,7 +360,7 @@ func (f *FolderConfiguration) CheckAvailableSpace(req uint64) error {
|
||||
if val <= 0 {
|
||||
return nil
|
||||
}
|
||||
fs := f.Filesystem(nil)
|
||||
fs := f.Filesystem()
|
||||
usage, err := fs.Usage(".")
|
||||
if err != nil {
|
||||
return nil //nolint: nilerr
|
||||
|
||||
Reference in New Issue
Block a user