* sftp: read downloads as the file's logical content
Downloads read through filer.NewFileReader, which stops at the last stored
byte: holes between chunks, a tail no chunk stores and the zeros after
partial inline content came back missing, so sparse files downloaded short
or with later bytes shifted.
Read chunked files through filer.ChunkReadAt with one shared ReaderCache,
set up as WebDAV's: it serves FileSize bytes, zero-fills what no chunk
stores, resolves manifests, prefetches and re-looks-up moved volumes.
Closing a handle only releases its stream, as S3 does. Inline content is
read up to the file's size, then zeros. This replaces sftpd's own block
cache, whose LRU helper is now unused.
* sftp: read large downloads in sections, as the FUSE mount does
ChunkReadAt walks the file's chunk views from the start on every read, so
a sequential download of a file with many chunks costs time quadratic in
its chunk count. Read through filer.ChunkGroup instead, the reader of a
mount's file handle: it keeps chunks in 64 MiB sections, returns EOF at
the file size for any offset, and holds every open file's buffers to one
shared budget (the mount's default 256 MiB).
* sftp: cache remote-only content on open instead of refusing it
A file whose content only a remote store holds is copied into the cluster
with CacheRemoteObjectToLocalCluster when it is opened for reading, as a
mount's read and the filer's HTTP read do, and then read from the cached
chunks. It is still refused when the remote store cannot be read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Denis Maier <denis@dAir.lab>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: honor the CREATE, EXCL and APPEND open flags
An upload open ignored three of its flags:
- Without CREATE, opening a missing file created it on close. It now fails
with NO_SUCH_FILE, as OpenSSH's sftp-server and SFTPGo do.
- CREATE|EXCL on an existing file succeeded and overwrote it. The open now
creates the empty file with an exclusive filer create, so it fails when
the name is taken, also while another exclusive upload of it buffers.
- APPEND wrote at the client's offset, usually 0, over the start of the
file. A write below the size the file had at open is now refused, as
SFTPGo does. Writes keep their offsets rather than going to the current
end, because pkg/sftp may run a client's pipelined writes in any order.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: leave a file alone when an open of it changes nothing
An APPEND open whose writes were all refused still uploaded the copied
bytes on close, which rewrote the file and handed it to the session's
user. Any open that copied the existing file now uploads only once the
handle writes or sets attributes, not only read-write opens.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Denis Maier <denis@dAir.lab>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
chmod on a folder over SFTP failed with "existing entry is a directory".
SETSTAT copied the client's mode into the entry as-is. A client sends
only the permission bits, so the directory bit was dropped and the filer
refused an update that would turn the folder into a file. Files lost
their stored type bits the same way, just without an error.
Keep the stored type bits and take only the permission, setuid, setgid
and sticky bits from the client.
Co-authored-by: Denis Maier <denis@dAir.lab>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: create uploaded files with mode 0644
The upload writer carried a 0644 mode that never reached the filer, so the
PUT fell back to the filer default of 0660. Pass the mode on the PUT, as
OpenSSH's sftp-server creates new files 0666 minus a 022 umask.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: keep an existing file's mode when an upload overwrites it
An overwrite went through the same PUT as a new file, so a 0600 file came
back with the default mode. Send the stored mode instead, as open(2) on an
existing file keeps it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: apply an fsetstat sent while an upload is still buffering
"put -p" sets the mode and times on the open handle before closing it, but
the upload only reaches the filer on close, so the setstat found no entry and
the client failed with "No such file or directory". Keep such attributes on
the open upload: a size cuts the buffered bytes, the mode goes on the PUT,
and the rest is set once the file is stored.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: clear the sub-second part of an mtime a setstat replaces
SFTP times are whole seconds, but the stored nanoseconds of the old mtime
stayed, so a touched or "put -p" file showed a time the client never set.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: set the attributes queued on an upload in its post-upload update
A new file can be under its bucket's default retention as soon as the PUT
stores it, and a setstat after that is refused, so "put -p" into such a
bucket stored the file and then failed the close. Apply the queued
attributes in the update that already sets the owner after the upload.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: leave a setstat alone when two uploads share its path
A setstat carries only the path, so with two uploads of one path open in a
session it went to whichever opened last, and a size cut the other upload's
bytes. Route it to an upload only when that upload is the only one open.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* 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>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* s3_objectlock: read a bucket's default retention from its entry
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: give uploads into an Object Lock bucket its default retention
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: match uploads against the cleaned buckets folder
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: refuse to delete entries under Object Lock or WORM
rm and rmdir sent DeleteEntry with no protection check, so an SFTP user
could delete versions under legal hold or retention, and filer.conf WORM
files, that the S3 API and the filer HTTP API refuse to delete. Check the
entry first and pin the delete to the Object Lock state that was checked.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: refuse to rename entries under Object Lock or WORM
A rename moved a protected version out of its .versions folder, or
replaced a protected target, which the delete check alone does not stop.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: refuse to overwrite or setstat entries under Object Lock or WORM
An upload over an existing protected entry replaced its content, and a
setstat could truncate it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: let a rename onto itself succeed for a protected entry
The filer treats it as a no-op, so there is nothing to protect.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: read WORM rules from a filer.conf stored in chunks
ReadFilerConf without a master client reads only inline content, so a
chunked filer.conf looked empty and WORM went unenforced.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: pin setstat to the Object Lock state it checked
The update writes back the entry it read, so a hold set in between
would be dropped. The filer now refuses the update instead.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: recheck an upload's target when it commits, and refuse directories
The upload buffers until Close, so a hold set while it was open still
let it overwrite the entry. A PUT to a directory path also lands on a
child of that directory, whose protection was never checked.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: refuse to rename a directory that holds protected entries
A directory rename moves every descendant, so checking the directory
alone let it carry locked versions away from their keys, or WORM files
out from under their rule. Refuse when a WORM rule covers the subtree,
as the filer does for scoped tokens, or when an object in it is under
Object Lock.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* s3_objectlock: scan a literal .versions directory recursively
A directory named exactly .versions was listed as flat version files, so a
locked object nested below it was missed by the subtree and bucket scans.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>