chmod after truncate and setutimes on the remote side.

When the source file permission is r--r--r--, truncate and setutimes
AFTER chmod fail due to permission deined. So, do chmod after truncate
and setutimes.
This commit is contained in:
Ryo Nakamura
2024-03-14 15:14:31 +09:00
parent 433f155cd3
commit 07a6cbf039
2 changed files with 21 additions and 4 deletions

View File

@@ -323,12 +323,14 @@ int mscp_setstat(const char *path, struct stat *st, bool preserve_ts, sftp_sessi
ret = sftp_setstat(sftp, path, &attr);
sftp_err_to_errno(sftp);
} else {
if ((ret = chmod(path, st->st_mode)) < 0)
return ret;
if ((ret = truncate(path, st->st_size)) < 0)
return ret;
if (preserve_ts)
ret = setutimes(path, st->st_atim, st->st_mtim);
if (preserve_ts) {
if ((ret = setutimes(path, st->st_atim, st->st_mtim)) < 0)
return ret;
}
if ((ret = chmod(path, st->st_mode)) < 0)
return ret;
}
return ret;