sftp: fail the close when an upload's queued attributes are not stored

The setstat already answered success, so a failed post-upload update was
only logged and "put -p" lost the times without the client knowing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-12-02 14:50:40 -08:00
1 parent 4a43a9f014
commit ba31775360
3 files changed
+25 -1

No files matched your search

+4 -1
View File
@@ -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)
}
}
+17
View File
@@ -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
+4
View File
@@ -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