summaryrefslogtreecommitdiff
path: root/src/lib/ext.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-12-05 01:14:52 +0100
committerCarl Hetherington <cth@carlh.net>2021-12-06 09:57:49 +0100
commitc1a86fe33aa0aafc0af23f3a19a30e4148b2208b (patch)
treeccbfc089b0a8209fc288e6201bfa8d8a626380df /src/lib/ext.cc
parent178961c18cdbc93ef0059483ba170401df77daa1 (diff)
Set up {m,c,a}times on copied files (#2145).
Diffstat (limited to 'src/lib/ext.cc')
-rw-r--r--src/lib/ext.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib/ext.cc b/src/lib/ext.cc
index 863cc0307..06add8d84 100644
--- a/src/lib/ext.cc
+++ b/src/lib/ext.cc
@@ -57,6 +57,7 @@ extern "C" {
#include <lwext4/ext4_mkfs.h>
}
#include <boost/filesystem.hpp>
+#include <chrono>
#include <string>
@@ -90,6 +91,18 @@ count (boost::filesystem::path dir, uint64_t& total_bytes)
}
}
+
+static
+void
+set_timestamps_to_now (boost::filesystem::path path)
+{
+ auto const now = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
+ ext4_mtime_set (path.generic_string().c_str(), now);
+ ext4_ctime_set (path.generic_string().c_str(), now);
+ ext4_atime_set (path.generic_string().c_str(), now);
+}
+
+
static
string
write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_remaining, uint64_t total, Nanomsg* nanomsg)
@@ -147,6 +160,8 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total
fclose (in);
ext4_fclose (&out);
+ set_timestamps_to_now (to);
+
return digester.get ();
}
@@ -225,6 +240,7 @@ copy (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_
if (r != EOK) {
throw CopyError (String::compose("Failed to create directory %1", cr.generic_string()), r);
}
+ set_timestamps_to_now (cr);
for (directory_iterator i = directory_iterator(from); i != directory_iterator(); ++i) {
copy (i->path(), cr, total_remaining, total, copied_files, nanomsg);