lib/versioner: Expand tildes in version directory (fixes #9241) (#9327)

### Purpose

Fix #9241 by expanding tildes in version paths.

When creating the versioner file system, first try to expand any leading
tildes to the user's home directory before handling relative paths. This
makes a version path `"~/p"` expand to `"$HOME/p"` instead of
`"/folder/~/p"`.

### Testing

Added a test to lib/versioner that exercises this code path. Also
manually tested with local syncthing instances.
This commit is contained in:
nf
2024-01-12 10:46:18 +01:00
committed by GitHub
parent 8edd67a569
commit 8b321387c0
2 changed files with 79 additions and 3 deletions
+13 -3
View File
@@ -262,10 +262,20 @@ func versionerFsFromFolderCfg(cfg config.FolderConfiguration) (versionsFs fs.Fil
folderFs := cfg.Filesystem(nil)
if cfg.Versioning.FSPath == "" {
versionsFs = fs.NewFilesystem(folderFs.Type(), filepath.Join(folderFs.URI(), DefaultPath))
} else if cfg.Versioning.FSType == fs.FilesystemTypeBasic && !filepath.IsAbs(cfg.Versioning.FSPath) {
// We only know how to deal with relative folders for basic filesystems, as that's the only one we know
} else if cfg.Versioning.FSType == fs.FilesystemTypeBasic {
// Expand any leading tildes for basic filesystems,
// before checking for absolute paths.
path, err := fs.ExpandTilde(cfg.Versioning.FSPath)
if err != nil {
path = cfg.Versioning.FSPath
}
// We only know how to deal with relative folders for
// basic filesystems, as that's the only one we know
// how to check if it's absolute or relative.
versionsFs = fs.NewFilesystem(cfg.Versioning.FSType, filepath.Join(folderFs.URI(), cfg.Versioning.FSPath))
if !filepath.IsAbs(path) {
path = filepath.Join(folderFs.URI(), path)
}
versionsFs = fs.NewFilesystem(cfg.Versioning.FSType, path)
} else {
versionsFs = fs.NewFilesystem(cfg.Versioning.FSType, cfg.Versioning.FSPath)
}