Add create timestamp

This commit is contained in:
Marcus Holland-Moritz 2021-03-17 15:50:47 +01:00
parent 480a2f839b
commit f9743537ce
3 changed files with 12 additions and 2 deletions

View File

@ -24,6 +24,7 @@
#include <cerrno>
#include <climits>
#include <cstring>
#include <ctime>
#include <numeric>
#include <ostream>
@ -574,6 +575,13 @@ void metadata_<LoggerPolicy>::dump(
os << "created by: " << *version << std::endl;
}
if (auto ts = meta_.create_timestamp()) {
time_t tp = *ts;
std::string str(20, '\0');
std::strftime(str.data(), str.size(), "%F %T", std::localtime(&tp));
os << "created on: " << str << std::endl;
}
if (detail_level > 0) {
os << "block size: " << stbuf.f_bsize << std::endl;
os << "inode count: " << stbuf.f_files << std::endl;

View File

@ -22,6 +22,7 @@
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <ctime>
#include <deque>
#include <iterator>
#include <stdexcept>
@ -726,6 +727,7 @@ void scanner_<LoggerPolicy>::scan(filesystem_writer& fsw,
mv2.total_hardlink_size_ref() = prog.hardlink_size;
mv2.options_ref() = fsopts;
mv2.dwarfs_version_ref() = std::string("libdwarfs ") + PRJ_GIT_ID;
mv2.create_timestamp_ref() = std::time(nullptr);
auto [schema, data] = metadata_v2::freeze(mv2);

View File

@ -238,6 +238,6 @@ struct metadata {
// version
22: optional string dwarfs_version,
// TODO: add timestamp
// 21: optional UInt64 timestamp,
// timestamp
23: optional UInt64 create_timestamp,
}