summaryrefslogtreecommitdiff
path: root/src/path.c
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2024-02-06 16:15:43 +0900
committerRyo Nakamura <upa@haeena.net>2024-02-06 16:15:43 +0900
commita7f8ad948b38c450c0f9ccd52185771ae8f9754e (patch)
treec480252f0a26dca743d1c81818dec6f6a660f29e /src/path.c
parentff45d9d71b85a618aed6d3d5e5056bada6ff81f9 (diff)
add -p option, preserving file timestamps
Diffstat (limited to 'src/path.c')
-rw-r--r--src/path.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/path.c b/src/path.c
index c4e1b94..706dac2 100644
--- a/src/path.c
+++ b/src/path.c
@@ -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);
}