From 1e47c04aade72934a832359fce0e11d328255a25 Mon Sep 17 00:00:00 2001 From: Steven Price Date: Sat, 24 Oct 2020 11:56:09 +0100 Subject: [PATCH] clitar: restore mtime on files The documentation for smbclient states that when extracting a tar archive: Restored files have their creation times (mtime) set to the date saved in the tar file. However this behaviour was lost in commit 2945596011cc ("clitar.c: fresh new compilable file."). Add a call to cli_setatr() to set both the mtime and the mode of files after they have been extracted. Signed-off-by: Steven Price Reviewed-by: Andreas Schneider Reviewed-by: Noel Power Autobuild-User(master): Volker Lendecke Autobuild-Date(master): Wed Jan 27 19:26:03 UTC 2021 on sn-devel-184 --- source3/client/clitar.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 7348420db5e..d62b53d2b17 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -1126,7 +1126,9 @@ static int tar_send_file(struct tar *t, struct archive_entry *entry) uint16_t remote_fd = (uint16_t) -1; int err = 0; int flags = O_RDWR | O_CREAT | O_TRUNC; - mode_t mode = archive_entry_filetype(entry); + mode_t filetype = archive_entry_filetype(entry); + mode_t mode = archive_entry_mode(entry); + time_t mtime = archive_entry_mtime(entry); int rc; TALLOC_CTX *ctx = talloc_new(NULL); if (ctx == NULL) { @@ -1156,7 +1158,7 @@ static int tar_send_file(struct tar *t, struct archive_entry *entry) goto out; } - if (mode != AE_IFREG && mode != AE_IFDIR) { + if (filetype != AE_IFREG && filetype != AE_IFDIR) { d_printf("Skipping non-dir & non-regular file %s\n", full_path); goto out; } @@ -1167,7 +1169,7 @@ static int tar_send_file(struct tar *t, struct archive_entry *entry) goto out; } - if (mode == AE_IFDIR) { + if (filetype == AE_IFDIR) { goto out; } @@ -1215,6 +1217,13 @@ close_out: err = 1; } + status = cli_setatr(cli, full_path, mode, mtime); + if (!NT_STATUS_IS_OK(status)) { + d_printf("Error setting attributes on remote file %s: %s\n", + full_path, nt_errstr(status)); + err = 1; + } + out: talloc_free(ctx); return err;