diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2005-05-05 11:33:39 +0000 |
---|---|---|
committer | Miklos Szeredi <miklos@szeredi.hu> | 2005-05-05 11:33:39 +0000 |
commit | c67cf9b98b9056d30261199774d6062eb68cda2f (patch) | |
tree | 809355298bea9cd10f472fa0e2647145e1573396 | |
parent | effd586502b27c97e44bca4e4248adaaba5ef067 (diff) | |
download | sshfs-c67cf9b98b9056d30261199774d6062eb68cda2f.tar sshfs-c67cf9b98b9056d30261199774d6062eb68cda2f.tar.gz sshfs-c67cf9b98b9056d30261199774d6062eb68cda2f.tar.bz2 sshfs-c67cf9b98b9056d30261199774d6062eb68cda2f.zip |
fix
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | sshfs.c | 25 |
2 files changed, 28 insertions, 3 deletions
@@ -1,3 +1,9 @@ +2005-05-05 Miklos Szeredi <miklos@szeredi.hu> + + * Work around missing truncate() support in some older sftp + servers (only works for zero size truncate). Thanks to Eduard + Czimbalmos for the bug report and help with testing + 2005-04-13 Miklos Szeredi <miklos@szeredi.hu> * Fix compilation with gcc-2.95. Reported by David A. Gershman @@ -1108,9 +1108,28 @@ static int sshfs_truncate(const char *path, off_t size) struct buffer buf; buf_init(&buf, 0); buf_add_path(&buf, path); - buf_add_uint32(&buf, SSH_FILEXFER_ATTR_SIZE); - buf_add_uint64(&buf, size); - err = sftp_request(SSH_FXP_SETSTAT, &buf, SSH_FXP_STATUS, NULL); + if (size == 0) { + /* If size is zero, use open(..., O_TRUNC), to work around + broken sftp servers */ + struct buffer handle; + buf_add_uint32(&buf, SSH_FXF_WRITE | SSH_FXF_TRUNC); + buf_add_uint32(&buf, 0); + err = sftp_request(SSH_FXP_OPEN, &buf, SSH_FXP_HANDLE, &handle); + if (!err) { + int err2; + buf_finish(&handle); + err2 = sftp_request(SSH_FXP_CLOSE, &handle, 0, NULL); + if (!err) + err = err2; + buf_free(&handle); + } + } else { + buf_init(&buf, 0); + buf_add_path(&buf, path); + buf_add_uint32(&buf, SSH_FILEXFER_ATTR_SIZE); + buf_add_uint64(&buf, size); + err = sftp_request(SSH_FXP_SETSTAT, &buf, SSH_FXP_STATUS, NULL); + } buf_free(&buf); return err; } |