aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--sshfs.c25
2 files changed, 28 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index dd90926..46fb46c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/sshfs.c b/sshfs.c
index 1f11e43..92b3c43 100644
--- a/sshfs.c
+++ b/sshfs.c
@@ -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;
}