* sftp: copy only the stored bytes on a non-truncating open
A size set by a truncate that grows a file stores nothing, but opening
the file for writing without O_TRUNC copied its whole logical size into
the temp file as zeros. Copy up to the last stored byte and extend the
temp file to the size, which leaves the rest sparse.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: upload only up to the written data on close
Close streamed the whole temp file, so a hole after the data, from a
truncate that grew the file before or during the open, was read back
and uploaded as zeros. Track where the copied and written bytes end,
upload up to there, and keep the rest as the file's size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: leave the data end alone on an empty write
A zero-length WRITE far past the data moved the data end there, so
Close uploaded the hole before it as zeros.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: cap what the test filer reads from an upload
An upload that wrongly carries a large hole now fails the test instead of
filling memory.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: hash nothing past an out-of-range size
A stored size past the largest file offset turned negative and sliced the
inline content out of range.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: refuse a setstat size past the largest file offset
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: fail the hash of an out-of-range size
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: check the size before returning a stored md5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: answer md5sum, sha1sum, df and echo exec requests
SFTP clients such as rclone verify transfers and show free space by running
md5sum/sha1sum/df over an SSH exec request. weed sftp rejected every exec
request, so rclone fell back to comparing sizes and could not report usage.
Answer the few commands those clients send, without a shell:
- echo <text>: prints text (rclone's shell detection)
- md5sum/sha1sum [path]: the file's hash in coreutils format, or the
empty-input hash without a path (the support probe). The path is resolved
inside the user's home and needs read permission. MD5 uses the hash the
filer stored when there is one, otherwise the content is read.
- df [-k] [path]: the filer's volume capacity in df -k format
Anything else fails with exit status 1. Checked with rclone: hashes md5 and
sha1 detected, md5sum/sha1sum match local files, `rclone about` works.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: describe exec commands without naming one client
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: exec hashes cover sparse files and stop with the connection
- md5sum/sha1sum read a file's whole logical content, with zeros for the
holes and tail no chunk stores, through the same sparse-aware stream an
in-place SFTP write uses; it ends with the SSH connection
- a trailing escaped space stays part of the file name
- df checks that the path exists
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: relative exec operands, hashes of holes stop, setstat size clears MD5
- a command's relative path is relative to the home, as over SFTP, so df
and the hashes of a root-home user look up the right entry
- writes into the hash check the connection, so a large file that is all
holes stops too
- a size change through SETSTAT drops the stored MD5, which md5sum reports
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: an exec ends when the client closes its channel
The command's context ended only with the SSH connection, so a client that
closed one exec channel and kept the connection left a hash running. The
channel's request stream closes with the channel, which now cancels it.
A second exec on the same channel is refused, as OpenSSH does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: a channel runs one exec or one SFTP session
With the exec running beside the request loop, a subsystem request after
it would have started SFTP on the same channel while the command was still
writing to it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: refuse a subsystem request without a name instead of panicking
The subsystem name was read as Payload[4:], so a request with fewer than
four payload bytes panicked the channel goroutine and stopped the server.
Decode the name like the exec command.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: test that a running exec keeps its channel from starting sftp
Also say in handleExec that its context ends with the channel.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* sftp: df drops -k only as a whole option
"df -kfoo" was read as "df foo"; now -kfoo is the path, which fails
unless such a file exists.
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>