open with SSH_FXF_TRUNC without SSH_FXF_CREAT violates SFTP spec, but everyone does it anyway #1050
Labels
No Label
0.2.0
0.3.0
0.4.0
0.5.0
0.5.1
0.6.0
0.6.1
0.7.0
0.8.0
0.9.0
1.0.0
1.1.0
1.10.0
1.10.1
1.10.2
1.10a2
1.11.0
1.12.0
1.12.1
1.13.0
1.14.0
1.15.0
1.15.1
1.2.0
1.3.0
1.4.1
1.5.0
1.6.0
1.6.1
1.7.0
1.7.1
1.7β
1.8.0
1.8.1
1.8.2
1.8.3
1.8β
1.9.0
1.9.0-s3branch
1.9.0a1
1.9.0a2
1.9.0b1
1.9.1
1.9.2
1.9.2a1
LeastAuthority.com automation
blocker
cannot reproduce
cloud-branch
code
code-dirnodes
code-encoding
code-frontend
code-frontend-cli
code-frontend-ftp-sftp
code-frontend-magic-folder
code-frontend-web
code-mutable
code-network
code-nodeadmin
code-peerselection
code-storage
contrib
critical
defect
dev-infrastructure
documentation
duplicate
enhancement
fixed
invalid
major
minor
n/a
normal
operational
packaging
somebody else's problem
supercritical
task
trivial
unknown
was already fixed
website
wontfix
worksforme
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Reference: tahoe-lafs/trac-2024-07-25#1050
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
It apparrently is against the SFTP spec (but not the POSIX) to open a file with SSH_FXF_TRUNC without including SSH_FXF_CREAT.
Programs like OpenSSH server and sshfs ignore this little detail, though, and programs like "cp" fail if it is followed.
workaround:
SFTP frontend should accept FXF_WRITE | FXF_TRUNC.
See http://tools.ietf.org/html/draft-ietf-secsh-filexfer-02#section-6.3 for the relevant specification of FXF_TRUNC and FXF_CREAT, and http://www.opengroup.org/onlinepubs/000095399/functions/open.html for the POSIX open call.
sshfs appears to just pass the POSIX flags along with the obvious mappings.
the SFTP frontend now accepts WRITE | TRUNC, so
works.
but doing:
or
when newfile doesn't already exist fails with a:
it does create a 'newfile' file, but it has zero length. (and repeating the command will succeed on the existing file)
from strace, it appears to be opening 'newfile' with the flags WRITE | CREAT | TRUNC.
The problem in comment:77424 is due to the shell assuming that newfile already exists just after the open call. It does a
stat
which causes agetAttrs
request, which fails withNoSuchChildError
(FX_NO_SUCH_FILE
). Then newfile is closed, but nothing has been written to it, so it is zero-length.The ticket1037 branch has been changed to keep track of which paths correspond to open files. This allows us to return fake attributes from the
getAttrs
request (without having to write a zero-length file on the open call). zooko: please review this changeset, and bj0: please pull and re-test.Please also test '
touch newfile
' before and after pulling the changes. Based on https://bugzilla.gnome.org/show_bug.cgi?id=522532 , I think it might have the same issue.I just checked and
Does work before the latest patches, although it takes like 20s before the new file appears in ls
After the patch, it shows up in ls instantly. Also:
works.
Thanks for the testing.
The current code is not quite right: it indexes the
global_open_files
dict by canonical path, but this does not include the root node. So, paths for different user accounts could be confused. It should instead index by the directory entry, i.e. parent cap and child name.The test coverage also needs to be improved to cover cases where the same directory entry is opened more than once, and where files are still open when a connection is logged out.
Replying to davidsarah:
This is now fixed. Also, we now try to support renaming immutable files that have been opened for writing or creation, while they are still open. Many apps depend on this: they create a temporary file, rename it to the destination file, and then close it.
bj0: please re-test both the previous tests, and saving files with
gedit
and OpenOffice.I tried, and got no errors with:
cp
mv
cat >
cat >>
gedit
OpenOffice
gedit and OO both saved fine it seemed.
One odd thing i noticed was that when i open a file with vi, then close it, the .swp file isn't deleted. I took a quick look at the flog and it looks like it called removeFile and got a SUCCESS, but the file is still there.
Assigning to bj0 to check whether the remaining bug in comment:77430 still exists. (It should have been fixed by the changes to handle remove/close race conditions.)
Fixed according to bj0 on IRC.