diff --git a/weed/sftpd/sftp_filer.go b/weed/sftpd/sftp_filer.go index d1de338365..d6b1453e99 100644 --- a/weed/sftpd/sftp_filer.go +++ b/weed/sftpd/sftp_filer.go @@ -749,9 +749,12 @@ func (fs *SftpServer) putFile(filepath string, reader io.Reader, user *user.User return err }) + if err != nil && len(stats) > 0 { + return fmt.Errorf("set attributes of %s: %w", filepath, err) + } if err != nil { // Log the error but don't fail the whole operation - glog.Errorf("Failed to update file attributes for %s: %v", filepath, err) + glog.Errorf("Failed to update file ownership for %s: %v", filepath, err) } } diff --git a/weed/sftpd/sftp_filer_test.go b/weed/sftpd/sftp_filer_test.go index c0eee725d6..658190370f 100644 --- a/weed/sftpd/sftp_filer_test.go +++ b/weed/sftpd/sftp_filer_test.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "encoding/binary" "encoding/hex" + "errors" "fmt" "io" "net" @@ -378,6 +379,22 @@ func TestSetstatOnBufferingUpload(t *testing.T) { if fs.openUpload("/buckets/plain/new") != nil { t.Error("closed upload is still tracked") } + + // The client was told the setstat worked, so losing it must fail the close. + fake.mu.Lock() + fake.updateErr = errors.New("update refused") + fake.mu.Unlock() + open.Filepath, setstat.Filepath = "/plain/other", "/plain/other" + w, err = fs.newFileWriter(open) + if err != nil { + t.Fatalf("newFileWriter: %v", err) + } + if err := fs.dispatchCmd(setstat); err != nil { + t.Fatalf("setstat before close: %v", err) + } + if err := w.(io.Closer).Close(); err == nil { + t.Error("close succeeded although the queued attributes were not stored") + } } // A setstat names only the path, so it can't pick between two uploads open diff --git a/weed/sftpd/sftp_object_lock_test.go b/weed/sftpd/sftp_object_lock_test.go index 7aa5fdad31..156b927a6c 100644 --- a/weed/sftpd/sftp_object_lock_test.go +++ b/weed/sftpd/sftp_object_lock_test.go @@ -37,6 +37,7 @@ type lockTestFiler struct { volume string lastUpdate *filer_pb.UpdateEntryRequest + updateErr error } func (f *lockTestFiler) LookupDirectoryEntry(_ context.Context, req *filer_pb.LookupDirectoryEntryRequest) (*filer_pb.LookupDirectoryEntryResponse, error) { @@ -228,6 +229,9 @@ func TestRenameRefusesProtectedSourceAndTarget(t *testing.T) { func (f *lockTestFiler) UpdateEntry(_ context.Context, req *filer_pb.UpdateEntryRequest) (*filer_pb.UpdateEntryResponse, error) { f.mu.Lock() defer f.mu.Unlock() + if f.updateErr != nil { + return nil, f.updateErr + } f.updates++ f.lastUpdate = req return &filer_pb.UpdateEntryResponse{}, nil