X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fext.cc;h=af5229f72f41c02941f6905911eb34495be91d61;hb=cf2ed48d21ddbc32bda262064480e88e69dc031a;hp=39c90ae124e0f547f0e4e48ae29436c8d20e7f65;hpb=e5ad3fb4402d7df52c346408cbacbf68af4fa05a;p=dcpomatic.git diff --git a/src/lib/ext.cc b/src/lib/ext.cc index 39c90ae12..af5229f72 100644 --- a/src/lib/ext.cc +++ b/src/lib/ext.cc @@ -57,6 +57,7 @@ extern "C" { #include } #include +#include #include @@ -78,16 +79,30 @@ static void count (boost::filesystem::path dir, uint64_t& total_bytes) { + dir = fix_long_path (dir); + using namespace boost::filesystem; - for (directory_iterator i = directory_iterator(dir); i != directory_iterator(); ++i) { - if (is_directory(*i)) { - count (*i, total_bytes); + for (auto i: directory_iterator(dir)) { + if (is_directory(i)) { + count (i, total_bytes); } else { - total_bytes += file_size (*i); + total_bytes += file_size (i); } } } + +static +void +set_timestamps_to_now (boost::filesystem::path path) +{ + auto const now = std::chrono::duration_cast(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) @@ -149,6 +164,8 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total ext4_fclose (&out); delete[] buffer; + set_timestamps_to_now (to); + return digester.get (); } @@ -218,6 +235,7 @@ void copy (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total_remaining, uint64_t total, vector& copied_files, Nanomsg* nanomsg) { LOG_DISK ("Copy %1 -> %2", from.string(), to.generic_string()); + from = fix_long_path (from); using namespace boost::filesystem; @@ -228,9 +246,10 @@ 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); + for (auto i: directory_iterator(from)) { + copy (i.path(), cr, total_remaining, total, copied_files, nanomsg); } } else { string const write_digest = write (from, cr, total_remaining, total, nanomsg); @@ -301,10 +320,6 @@ try parts.division[2] = 0; parts.division[3] = 0; -#ifdef DCPOMATIC_LINUX - PrivilegeEscalator e; -#endif - /* XXX: not sure if disk_id matters */ int r = ext4_mbr_write (bd, &parts, 0); if (r) {