diff options
author | Ryo Nakamura <upa@haeena.net> | 2024-02-06 16:15:43 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2024-02-06 16:15:43 +0900 |
commit | a7f8ad948b38c450c0f9ccd52185771ae8f9754e (patch) | |
tree | c480252f0a26dca743d1c81818dec6f6a660f29e /src/path.c | |
parent | ff45d9d71b85a618aed6d3d5e5056bada6ff81f9 (diff) |
add -p option, preserving file timestamps
Diffstat (limited to 'src/path.c')
-rw-r--r-- | src/path.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -556,7 +556,7 @@ static int _copy_chunk(struct chunk *c, mf *s, mf *d, } int copy_chunk(struct chunk *c, sftp_session src_sftp, sftp_session dst_sftp, - int nr_ahead, int buf_sz, size_t *counter) + int nr_ahead, int buf_sz, bool preserve_ts, size_t *counter) { mode_t mode; int flags; @@ -610,10 +610,18 @@ int copy_chunk(struct chunk *c, sftp_session src_sftp, sftp_session dst_sftp, return ret; if (refcnt_dec(&c->p->refcnt) == 0) { + struct stat st; c->p->state = FILE_STATE_DONE; - if (mscp_setstat(c->p->dst_path, c->p->mode, c->p->size, dst_sftp) < 0) - mpr_err("failed to chmod and truncate %s: %s", - c->p->path, strerrno()); + + /* sync stat */ + if (mscp_stat(c->p->path, &st, src_sftp) < 0) { + mpr_err("mscp_stat: %s: %s", c->p->path, strerrno()); + return -1; + } + if (mscp_setstat(c->p->dst_path, &st, preserve_ts, dst_sftp) < 0) { + mpr_err("mscp_setstat: %s: %s", c->p->path, strerrno()); + return -1; + } mpr_info("copy done: %s", c->p->path); } |