diff options
| author | Ryo Nakamura <upa@haeena.net> | 2023-08-04 15:06:14 +0900 |
|---|---|---|
| committer | Ryo Nakamura <upa@haeena.net> | 2023-08-04 15:06:14 +0900 |
| commit | 24c1bc9149eb8f1c383eaf16d94636b62d07c152 (patch) | |
| tree | 54dd5823cb8255a493a851e4ecec74aeae675370 /src/fileops.c | |
| parent | 16f2f88cc91ffa2421393b077611d55d6cd2b771 (diff) | |
do not set O_TRUNC when opening destination file.
It prevents `mscp localhost:hoge ~/hoge` from truncating the source
file. See https://bugzilla.mindrot.org/show_bug.cgi?id=3431.
https://github.com/upa/mscp/issues/1
Diffstat (limited to 'src/fileops.c')
| -rw-r--r-- | src/fileops.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/fileops.c b/src/fileops.c index 994dd77..d9587ef 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -293,15 +293,24 @@ int mscp_lseek(mf *f, size_t off) return ret; } -int mscp_chmod(const char *path, mode_t mode, sftp_session sftp) +int mscp_setstat(const char *path, mode_t mode, size_t size, sftp_session sftp) { int ret; if (sftp) { - ret = sftp_chmod(sftp, path, mode); + struct sftp_attributes_struct attr; + memset(&attr, 0, sizeof(attr)); + attr.permissions = mode; + attr.size = size; + attr.flags = (SSH_FILEXFER_ATTR_PERMISSIONS|SSH_FILEXFER_ATTR_SIZE); + ret = sftp_setstat(sftp, path, &attr); sftp_err_to_errno(sftp); - } else - ret = chmod(path, mode); + } else { + if ((ret = chmod(path, mode)) < 0) + return ret; + if ((ret = truncate(path, size)) < 0) + return ret; + } return ret; } |
