This makes sure the user running Syncthing, and hence Synchting itself, has read/write/execute on directories in .stversions. The other permission bits remain copied from the source directory, ensuring whatever group and other permissions were set remain in effect. Closes #10695. --------- Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
)
|
||||
|
||||
func TestTaggedFilename(t *testing.T) {
|
||||
@@ -256,3 +257,57 @@ func TestArchiveFoldersCreationPermission(t *testing.T) {
|
||||
t.Errorf("földer2 permissions %v, want %v", folder2VersionsInfo.Mode(), folder2Perms)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDupDirTreeWritePermissions(t *testing.T) {
|
||||
// The structure should be replicated, with user permission bits set along the way
|
||||
|
||||
srcFs := fs.NewFilesystem(fs.FilesystemTypeFake, "TestDupDirTreeWritePermissions/srcFs")
|
||||
dstFs := fs.NewFilesystem(fs.FilesystemTypeFake, "TestDupDirTreeWritePermissions/dstFs")
|
||||
|
||||
// A source dir to duplicate
|
||||
_ = srcFs.Mkdir("foo", 0o444)
|
||||
_ = srcFs.Mkdir("foo/bar", 0o555)
|
||||
_ = srcFs.Mkdir("foo/bar/baz", 0o000)
|
||||
|
||||
// Duplication should succeed
|
||||
if err := dupDirTree(srcFs, dstFs, "foo/bar/baz"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Permissions should be the same, but with read/write/execute bits for
|
||||
// the user
|
||||
if info, err := dstFs.Lstat("foo"); err != nil || info.Mode() != 0o744 {
|
||||
t.Fatalf("foo: 0o%o", info.Mode())
|
||||
}
|
||||
if info, err := dstFs.Lstat("foo/bar"); err != nil || info.Mode() != 0o755 {
|
||||
t.Fatalf("foo/bar: 0o%o", info.Mode())
|
||||
}
|
||||
if info, err := dstFs.Lstat("foo/bar/baz"); err != nil || info.Mode() != 0o700 {
|
||||
t.Fatalf("foo/bar/baz: 0o%o", info.Mode())
|
||||
}
|
||||
}
|
||||
|
||||
func TestDupDirFastPath(t *testing.T) {
|
||||
srcFs := fs.NewFilesystem(fs.FilesystemTypeFake, "TestDupDirFastPath/srcFs")
|
||||
dstFs := fs.NewFilesystem(fs.FilesystemTypeFake, "TestDupDirFastPath/dstFs")
|
||||
|
||||
// A source dir to duplicate
|
||||
_ = srcFs.Mkdir("foo", 0o444)
|
||||
_ = srcFs.Mkdir("foo/bar", 0o555)
|
||||
_ = srcFs.Mkdir("foo/bar/baz", 0o000)
|
||||
|
||||
// The destination exists, but with too few permission bits
|
||||
_ = dstFs.MkdirAll("foo/bar/baz", 0o555)
|
||||
|
||||
// Duplication should succeed
|
||||
if err := dupDirTree(srcFs, dstFs, "foo/bar/baz"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Permissions for the destination should have been updated. (This
|
||||
// differs from what would have been created by the duplication of the
|
||||
// 0o000 dir in the src, because it already existed.)
|
||||
if info, err := dstFs.Lstat("foo/bar/baz"); err != nil || info.Mode() != 0o755 {
|
||||
t.Fatalf("foo/bar/baz: 0o%o", info.Mode())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user