diff options
author | Jakob Borg <jakob@kastelo.net> | 2022-11-11 11:49:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-11 11:49:15 +0100 |
commit | 6aa04118a6e3c288ec9cc44499df3b5f6a96a015 (patch) | |
tree | c1d277bac86e5b4ec257f504f39fe8a3519e880a | |
parent | 1b32e9f8582e27986d6c805f3bd66fa3d7e22b0c (diff) |
lib/model: Correctly set xattrs on temp files (fixes #8667) (#8670)v1.22.2-rc.2
-rw-r--r-- | lib/model/folder_sendrecv.go | 2 | ||||
-rw-r--r-- | lib/model/folder_test.go | 42 |
2 files changed, 43 insertions, 1 deletions
diff --git a/lib/model/folder_sendrecv.go b/lib/model/folder_sendrecv.go index 6adb6f5d8b..6111bc4257 100644 --- a/lib/model/folder_sendrecv.go +++ b/lib/model/folder_sendrecv.go @@ -2120,7 +2120,7 @@ func (f *sendReceiveFolder) checkToBeDeleted(file, cur protocol.FileInfo, hasCur func (f *sendReceiveFolder) setPlatformData(file *protocol.FileInfo, name string) error { if f.SyncXattrs { // Set extended attributes. - if err := f.mtimefs.SetXattr(file.Name, file.Platform.Xattrs(), f.XattrFilter); errors.Is(err, fs.ErrXattrsNotSupported) { + if err := f.mtimefs.SetXattr(name, file.Platform.Xattrs(), f.XattrFilter); errors.Is(err, fs.ErrXattrsNotSupported) { l.Debugf("Cannot set xattrs on %q: %v", file.Name, err) } else if err != nil { return err diff --git a/lib/model/folder_test.go b/lib/model/folder_test.go index e348288360..38036ca95f 100644 --- a/lib/model/folder_test.go +++ b/lib/model/folder_test.go @@ -14,6 +14,8 @@ import ( "github.com/syncthing/syncthing/lib/build" "github.com/syncthing/syncthing/lib/config" + "github.com/syncthing/syncthing/lib/fs" + "github.com/syncthing/syncthing/lib/protocol" ) type unifySubsCase struct { @@ -149,3 +151,43 @@ func BenchmarkUnifySubs(b *testing.B) { } } } + +func TestSetPlatformData(t *testing.T) { + // Checks that setPlatformData runs without error when applied to a temp + // file, named differently than the given FileInfo. + + dir := t.TempDir() + fs := fs.NewFilesystem(fs.FilesystemTypeBasic, dir) + if fd, err := fs.Create("file.tmp"); err != nil { + t.Fatal(err) + } else { + fd.Close() + } + + xattr := []protocol.Xattr{{Name: "user.foo", Value: []byte("bar")}} + fi := &protocol.FileInfo{ + Name: "should be ignored", + Permissions: 0400, + ModifiedS: 1234567890, + Platform: protocol.PlatformData{ + Linux: &protocol.XattrData{Xattrs: xattr}, + Darwin: &protocol.XattrData{Xattrs: xattr}, + FreeBSD: &protocol.XattrData{Xattrs: xattr}, + NetBSD: &protocol.XattrData{Xattrs: xattr}, + }, + } + + // Minimum required to support setPlatformData + sr := &sendReceiveFolder{ + folder: folder{ + FolderConfiguration: config.FolderConfiguration{ + SyncXattrs: true, + }, + mtimefs: fs, + }, + } + + if err := sr.setPlatformData(fi, "file.tmp"); err != nil { + t.Error(err) + } +} |