diff options
author | 2009-12-13 19:50:53 +0000 | |
---|---|---|
committer | 2009-12-13 19:50:53 +0000 | |
commit | dee918a74ce99cb059de73f0ea9369cecbdf9567 (patch) | |
tree | f2c7f7932ae90ccaeba72d1cc97d59864322c9c2 | |
parent | eed895d5762216657d897196cc6dced9a9eb3225 (diff) | |
download | paludis-dee918a74ce99cb059de73f0ea9369cecbdf9567.tar.gz paludis-dee918a74ce99cb059de73f0ea9369cecbdf9567.tar.xz |
Timestamp wrapper class
40 files changed, 336 insertions, 114 deletions
diff --git a/doc/api/cplusplus/examples/example_metadata_key.cc b/doc/api/cplusplus/examples/example_metadata_key.cc index 865747e90..b705f9165 100644 --- a/doc/api/cplusplus/examples/example_metadata_key.cc +++ b/doc/api/cplusplus/examples/example_metadata_key.cc @@ -92,7 +92,7 @@ namespace { cout << indent << left << setw(30) << " Class:" << " " << "MetadataTimeKey" << endl; - cout << indent << left << setw(30) << " Value:" << " " << pretty_print_time(key.value()) << endl; + cout << indent << left << setw(30) << " Value:" << " " << pretty_print_time(key.value().seconds()) << endl; } void visit(const MetadataValueKey<std::tr1::shared_ptr<const Contents> > &) diff --git a/paludis/dep_list.cc b/paludis/dep_list.cc index f29a7b7ac..aa2552a3f 100644 --- a/paludis/dep_list.cc +++ b/paludis/dep_list.cc @@ -55,6 +55,7 @@ #include <paludis/util/make_named_values.hh> #include <paludis/util/simple_visitor_cast.hh> #include <paludis/util/accept_visitor.hh> +#include <paludis/util/timestamp.hh> #include <paludis/util/sequence-impl.hh> #include <paludis/util/set-impl.hh> @@ -1520,8 +1521,8 @@ DepList::prefer_installed_over_uninstalled(const PackageID & installed, if (uninstalled.version() == installed.version() && (installed.version().is_scm() || is_scm(installed.name()))) { - static time_t current_time(time(0)); /* static to avoid weirdness */ - time_t installed_time(current_time); + static Timestamp current_time(Timestamp::now()); /* static to avoid weirdness */ + Timestamp installed_time(current_time); if (installed.installed_time_key()) installed_time = installed.installed_time_key()->value(); @@ -1533,12 +1534,12 @@ DepList::prefer_installed_over_uninstalled(const PackageID & installed, return false; case dl_reinstall_scm_daily: - if (current_time - installed_time > (24 * 60 * 60)) + if (current_time.seconds() - installed_time.seconds() > (24 * 60 * 60)) return false; continue; case dl_reinstall_scm_weekly: - if (current_time - installed_time > (24 * 60 * 60 * 7)) + if (current_time.seconds() - installed_time.seconds() > (24 * 60 * 60 * 7)) return false; continue; diff --git a/paludis/literal_metadata_key.cc b/paludis/literal_metadata_key.cc index b85f391bc..816da451f 100644 --- a/paludis/literal_metadata_key.cc +++ b/paludis/literal_metadata_key.cc @@ -23,6 +23,7 @@ #include <paludis/util/sequence.hh> #include <paludis/util/wrapped_forward_iterator.hh> #include <paludis/util/join.hh> +#include <paludis/util/timestamp.hh> #include <paludis/formatter.hh> #include <paludis/package_id.hh> #include <paludis/action.hh> @@ -350,9 +351,9 @@ namespace paludis const std::string raw_name; const std::string human_name; const MetadataKeyType type; - const time_t value; + const Timestamp value; - Implementation(const std::string & r, const std::string & h, const MetadataKeyType t, const time_t v) : + Implementation(const std::string & r, const std::string & h, const MetadataKeyType t, const Timestamp v) : raw_name(r), human_name(h), type(t), @@ -363,7 +364,7 @@ namespace paludis } LiteralMetadataTimeKey::LiteralMetadataTimeKey( - const std::string & r, const std::string & h, const MetadataKeyType k, const time_t v) : + const std::string & r, const std::string & h, const MetadataKeyType k, const Timestamp v) : PrivateImplementationPattern<LiteralMetadataTimeKey>(new Implementation<LiteralMetadataTimeKey>(r, h, k, v)), _imp(PrivateImplementationPattern<LiteralMetadataTimeKey>::_imp) { @@ -391,7 +392,7 @@ LiteralMetadataTimeKey::type() const return _imp->type; } -time_t +Timestamp LiteralMetadataTimeKey::value() const { return _imp->value; diff --git a/paludis/literal_metadata_key.hh b/paludis/literal_metadata_key.hh index 38956182a..67eeee451 100644 --- a/paludis/literal_metadata_key.hh +++ b/paludis/literal_metadata_key.hh @@ -247,6 +247,7 @@ namespace paludis * * \ingroup g_literal_metadata_key * \since 0.36 + * \since 0.44 Timestamp instead of time_t */ class PALUDIS_VISIBLE LiteralMetadataTimeKey : public MetadataTimeKey, @@ -259,12 +260,12 @@ namespace paludis ///\name Basic operations ///\{ - LiteralMetadataTimeKey(const std::string &, const std::string &, const MetadataKeyType, const time_t); + LiteralMetadataTimeKey(const std::string &, const std::string &, const MetadataKeyType, const Timestamp); ~LiteralMetadataTimeKey(); ///\} - virtual time_t value() const PALUDIS_ATTRIBUTE((warn_unused_result)); + virtual Timestamp value() const PALUDIS_ATTRIBUTE((warn_unused_result)); virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result)); virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result)); diff --git a/paludis/merger.cc b/paludis/merger.cc index 8a180d484..665327344 100644 --- a/paludis/merger.cc +++ b/paludis/merger.cc @@ -27,6 +27,7 @@ #include <paludis/util/hashes.hh> #include <paludis/util/private_implementation_pattern-impl.hh> #include <paludis/util/set.hh> +#include <paludis/util/timestamp.hh> #include <paludis/selinux/security_context.hh> #include <paludis/environment.hh> #include <paludis/hook.hh> @@ -812,8 +813,7 @@ Merger::install_file(const FSEntry & src, const FSEntry & dst_dir, const std::st { /* futimens is POSIX, futimes isn't */ struct timespec ts[2]; - ts[0].tv_sec = ts[1].tv_sec = src.mtime(); - ts[0].tv_nsec = ts[1].tv_nsec = 0; + ts[0] = ts[1] = src.mtim().as_timespec(); if (0 != ::futimens(output_fd, ts)) throw MergerError("Cannot futimens '" + stringify(dst) + "': " + stringify(::strerror(errno))); } diff --git a/paludis/merger_TEST.cc b/paludis/merger_TEST.cc index 9f8bcc634..391ef0b43 100644 --- a/paludis/merger_TEST.cc +++ b/paludis/merger_TEST.cc @@ -26,6 +26,7 @@ #include <paludis/util/safe_ifstream.hh> #include <paludis/util/set.hh> #include <paludis/util/make_shared_ptr.hh> +#include <paludis/util/timestamp.hh> #include <paludis/hook.hh> #include <test/test_framework.hh> #include <test/test_runner.hh> @@ -539,14 +540,14 @@ namespace test_cases void run() { - time_t m_new((image_dir / "new_file").mtime()); - time_t m_existing((image_dir / "existing_file").mtime()); + Timestamp m_new((image_dir / "new_file").mtim()); + Timestamp m_existing((image_dir / "existing_file").mtim()); TEST_CHECK(merger.check()); merger.merge(); - TEST_CHECK_EQUAL((root_dir / "new_file").mtime(), m_new); - TEST_CHECK_EQUAL((root_dir / "existing_file").mtime(), m_existing); + TEST_CHECK((root_dir / "new_file").mtim() == m_new); + TEST_CHECK((root_dir / "existing_file").mtim() == m_existing); } } test_merger_mtimes; } diff --git a/paludis/metadata_key.hh b/paludis/metadata_key.hh index cfa5c1a87..b03005be8 100644 --- a/paludis/metadata_key.hh +++ b/paludis/metadata_key.hh @@ -37,6 +37,7 @@ #include <paludis/util/remove_shared_ptr.hh> #include <paludis/util/simple_visitor.hh> #include <paludis/util/type_list.hh> +#include <paludis/util/timestamp-fwd.hh> #include <tr1/type_traits> #include <string> @@ -249,10 +250,11 @@ namespace paludis }; /** - * A MetadataTimeKey is a MetadataKey that has a time_t as its value. + * A MetadataTimeKey is a MetadataKey that has a Timestamp as its value. * * \ingroup g_metadata_key * \since 0.26 + * \since 0.44 Timestamp instead of time_t * \nosubgrouping */ class PALUDIS_VISIBLE MetadataTimeKey : @@ -264,8 +266,10 @@ namespace paludis /** * Fetch our value. + * + * \since 0.44 Timestamp instead of time_t */ - virtual time_t value() const + virtual Timestamp value() const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0; }; diff --git a/paludis/ndbam.cc b/paludis/ndbam.cc index c8b88ccd0..3b3f260b0 100644 --- a/paludis/ndbam.cc +++ b/paludis/ndbam.cc @@ -30,6 +30,7 @@ #include <paludis/util/hashes.hh> #include <paludis/util/make_named_values.hh> #include <paludis/util/safe_ofstream.hh> +#include <paludis/util/timestamp.hh> #include <paludis/ndbam.hh> #include <paludis/package_id.hh> #include <paludis/metadata_key.hh> @@ -556,7 +557,7 @@ NDBAM::parse_contents(const PackageID & id, std::tr1::shared_ptr<ContentsFileEntry> entry(make_shared_ptr(new ContentsFileEntry(path))); entry->add_metadata_key(make_shared_ptr(new LiteralMetadataValueKey<std::string>("md5", "md5", mkt_normal, md5))); - entry->add_metadata_key(make_shared_ptr(new LiteralMetadataTimeKey("mtime", "mtime", mkt_normal, mtime))); + entry->add_metadata_key(make_shared_ptr(new LiteralMetadataTimeKey("mtime", "mtime", mkt_normal, Timestamp(mtime, 0)))); on_file(entry); } else if ("dir" == type) @@ -583,7 +584,7 @@ NDBAM::parse_contents(const PackageID & id, time_t mtime(destringify<time_t>(tokens.find("mtime")->second)); std::tr1::shared_ptr<ContentsSymEntry> entry(make_shared_ptr(new ContentsSymEntry(path, target))); - entry->add_metadata_key(make_shared_ptr(new LiteralMetadataTimeKey("mtime", "mtime", mkt_normal, mtime))); + entry->add_metadata_key(make_shared_ptr(new LiteralMetadataTimeKey("mtime", "mtime", mkt_normal, Timestamp(mtime, 0)))); on_sym(entry); } else diff --git a/paludis/ndbam_merger.cc b/paludis/ndbam_merger.cc index 2a2d5d041..2545b7903 100644 --- a/paludis/ndbam_merger.cc +++ b/paludis/ndbam_merger.cc @@ -32,6 +32,7 @@ #include <paludis/output_manager.hh> #include <paludis/util/safe_ofstream.hh> #include <paludis/util/safe_ifstream.hh> +#include <paludis/util/timestamp.hh> #include <paludis/hook.hh> #include <paludis/package_id.hh> #include <paludis/util/md5.hh> @@ -151,7 +152,7 @@ NDBAMMerger::record_install_file(const FSEntry & src, const FSEntry & dst_dir, c { std::string tidy(stringify((dst_dir / dst_name).strip_leading(_imp->realroot))), tidy_real(stringify((dst_dir / src.basename()).strip_leading(_imp->realroot))); - time_t timestamp((dst_dir / dst_name).mtime()); + time_t timestamp((dst_dir / dst_name).mtim().seconds()); SafeIFStream infile(FSEntry(dst_dir / dst_name)); if (! infile) @@ -194,13 +195,13 @@ NDBAMMerger::record_install_sym(const FSEntry & src, const FSEntry & dst_dir, co { std::string tidy(stringify((dst_dir / src.basename()).strip_leading(_imp->realroot))); std::string target((dst_dir / src.basename()).readlink()); - time_t timestamp((dst_dir / src.basename()).mtime()); + Timestamp timestamp((dst_dir / src.basename()).mtim()); display_override(make_arrows(flags) + " [sym] " + tidy); *_imp->contents_file << "type=sym path=" << escape(tidy); *_imp->contents_file << " target=" << escape(target); - *_imp->contents_file << " mtime=" << timestamp << std::endl; + *_imp->contents_file << " mtime=" << timestamp.seconds() << std::endl; } void diff --git a/paludis/ndbam_unmerger.cc b/paludis/ndbam_unmerger.cc index 54776e978..94fb5f7f5 100644 --- a/paludis/ndbam_unmerger.cc +++ b/paludis/ndbam_unmerger.cc @@ -40,6 +40,7 @@ #include <paludis/util/simple_visitor_cast.hh> #include <paludis/util/safe_ifstream.hh> #include <paludis/util/set.hh> +#include <paludis/util/timestamp.hh> #include <paludis/output_manager.hh> #include <paludis/metadata_key.hh> #include <tr1/functional> @@ -209,7 +210,7 @@ NDBAMUnmerger::check_file(const std::tr1::shared_ptr<const ContentsEntry> & e) c display("--- [gone ] " + stringify(f)); else if (! (_imp->options.root() / f).is_regular_file()) display("--- [!type] " + stringify(f)); - else if ((_imp->options.root() / f).mtime() != require_key<MetadataTimeKey>(*e, "mtime").value()) + else if ((_imp->options.root() / f).mtim().seconds() != require_key<MetadataTimeKey>(*e, "mtime").value().seconds()) display("--- [!time] " + stringify(f)); else { @@ -240,7 +241,7 @@ NDBAMUnmerger::check_sym(const std::tr1::shared_ptr<const ContentsEntry> & e) co display("--- [gone ] " + stringify(f)); else if (! (_imp->options.root() / f).is_symbolic_link()) display("--- [!type] " + stringify(f)); - else if ((_imp->options.root() / f).mtime() != require_key<MetadataTimeKey>(*e, "mtime").value()) + else if ((_imp->options.root() / f).mtim().seconds() != require_key<MetadataTimeKey>(*e, "mtime").value().seconds()) display("--- [!time] " + stringify(f)); else if ((_imp->options.root() / f).readlink() != require_key<MetadataValueKey<std::string> >(*e, "target").value()) display("--- [!dest] " + stringify(f)); diff --git a/paludis/repositories/e/e_key.cc b/paludis/repositories/e/e_key.cc index 258c33371..7e92bf6b6 100644 --- a/paludis/repositories/e/e_key.cc +++ b/paludis/repositories/e/e_key.cc @@ -43,6 +43,7 @@ #include <paludis/util/destringify.hh> #include <paludis/util/wrapped_forward_iterator.hh> #include <paludis/util/wrapped_output_iterator.hh> +#include <paludis/util/timestamp.hh> #include <paludis/contents.hh> #include <paludis/repository.hh> @@ -1011,7 +1012,8 @@ EContentsKey::value() const if ("obj" == tokens.at(0)) { std::tr1::shared_ptr<ContentsEntry> e(new ContentsFileEntry(tokens.at(1))); - e->add_metadata_key(make_shared_ptr(new LiteralMetadataTimeKey("mtime", "mtime", mkt_normal, destringify<time_t>(tokens.at(3))))); + e->add_metadata_key(make_shared_ptr(new LiteralMetadataTimeKey("mtime", "mtime", mkt_normal, + Timestamp(destringify<time_t>(tokens.at(3)), 0)))); e->add_metadata_key(make_shared_ptr(new LiteralMetadataValueKey<std::string>("md5", "md5", mkt_normal, tokens.at(2)))); _imp->value->add(e); } @@ -1023,7 +1025,8 @@ EContentsKey::value() const else if ("sym" == tokens.at(0)) { std::tr1::shared_ptr<ContentsEntry> e(new ContentsSymEntry(tokens.at(1), tokens.at(2))); - e->add_metadata_key(make_shared_ptr(new LiteralMetadataTimeKey("mtime", "mtime", mkt_normal, destringify<time_t>(tokens.at(3))))); + e->add_metadata_key(make_shared_ptr(new LiteralMetadataTimeKey("mtime", "mtime", mkt_normal, + Timestamp(destringify<time_t>(tokens.at(3)), 0)))); _imp->value->add(e); } else if ("misc" == tokens.at(0) || "fif" == tokens.at(0) || "dev" == tokens.at(0)) @@ -1059,7 +1062,7 @@ namespace paludis const std::tr1::shared_ptr<const ERepositoryID> id; const FSEntry filename; mutable Mutex value_mutex; - mutable std::tr1::shared_ptr<time_t> value; + mutable std::tr1::shared_ptr<Timestamp> value; const std::string raw_name; const std::string human_name; @@ -1087,7 +1090,7 @@ EMTimeKey::~EMTimeKey() { } -time_t +Timestamp EMTimeKey::value() const { Lock l(_imp->value_mutex); @@ -1095,11 +1098,11 @@ EMTimeKey::value() const if (_imp->value) return *_imp->value; - _imp->value.reset(new time_t(0)); + _imp->value.reset(new Timestamp(Timestamp::now())); try { - *_imp->value = _imp->filename.mtime(); + *_imp->value = _imp->filename.mtim(); } catch (const FSError & e) { diff --git a/paludis/repositories/e/e_key.hh b/paludis/repositories/e/e_key.hh index 0d7622953..ae5ce326e 100644 --- a/paludis/repositories/e/e_key.hh +++ b/paludis/repositories/e/e_key.hh @@ -309,7 +309,7 @@ namespace paludis const std::string &, const std::string &, const FSEntry &, const MetadataKeyType); ~EMTimeKey(); - time_t value() const + Timestamp value() const PALUDIS_ATTRIBUTE((warn_unused_result)); virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result)); diff --git a/paludis/repositories/e/e_repository.cc b/paludis/repositories/e/e_repository.cc index 8d8672d05..ac85d7784 100644 --- a/paludis/repositories/e/e_repository.cc +++ b/paludis/repositories/e/e_repository.cc @@ -94,6 +94,7 @@ #include <paludis/util/stringify.hh> #include <paludis/util/strip.hh> #include <paludis/util/system.hh> +#include <paludis/util/timestamp.hh> #include <paludis/util/tokeniser.hh> #include <paludis/util/wrapped_forward_iterator.hh> #include <paludis/util/wrapped_output_iterator.hh> @@ -366,7 +367,7 @@ namespace paludis FSEntry mtf(params.location() / "metadata" / "timestamp"); if (mtf.exists()) - master_mtime = mtf.mtime(); + master_mtime = mtf.mtim().seconds(); } Implementation<ERepository>::~Implementation() @@ -793,7 +794,7 @@ ERepository::purge_invalid_cache() const time_t master_mtime(0); FSEntry master_mtime_file(_imp->params.location() / "metadata" / "timestamp"); if (master_mtime_file.exists()) - master_mtime = master_mtime_file.mtime(); + master_mtime = master_mtime_file.mtim().seconds(); for (DirIterator dc(write_cache, DirIteratorOptions() + dio_inode_sort), dc_end ; dc != dc_end ; ++dc) { diff --git a/paludis/repositories/e/ebuild_flat_metadata_cache.cc b/paludis/repositories/e/ebuild_flat_metadata_cache.cc index 647a06135..d44e7dc8a 100644 --- a/paludis/repositories/e/ebuild_flat_metadata_cache.cc +++ b/paludis/repositories/e/ebuild_flat_metadata_cache.cc @@ -27,6 +27,7 @@ #include <paludis/util/wrapped_forward_iterator.hh> #include <paludis/util/safe_ofstream.hh> #include <paludis/util/safe_ifstream.hh> +#include <paludis/util/timestamp.hh> #include <paludis/repositories/e/dep_spec_pretty_printer.hh> #include <paludis/repositories/e/dep_parser.hh> #include <paludis/repositories/e/dependencies_rewriter.hh> @@ -107,11 +108,11 @@ namespace } { - std::time_t cache_time(std::max(_imp->master_mtime, _imp->filename.mtime())); - bool ok(_imp->ebuild.mtime() <= cache_time); + std::time_t cache_time(std::max(_imp->master_mtime, _imp->filename.mtim().seconds())); + bool ok(_imp->ebuild.mtim().seconds() <= cache_time); if (! ok) Log::get_instance()->message("e.cache.flat_list.mtime", ll_debug, lc_context) - << "ebuild has mtime " << _imp->ebuild.mtime() << ", but expected at most " << cache_time; + << "ebuild has mtime " << _imp->ebuild.mtim().seconds() << ", but expected at most " << cache_time; if (ok && "0" != id->guessed_eapi_name()) { @@ -148,11 +149,11 @@ namespace ok = false; } - else if (eclass->mtime() > cache_time) + else if (eclass->mtim().seconds() > cache_time) { Log::get_instance()->message("e.cache.flat_list.eclass.wrong_mtime", ll_debug, lc_context) << "Cache-requested eclass '" << *it << "' has mtime " - << eclass->mtime() << ", but expected at most " << cache_time; + << eclass->mtim().seconds() << ", but expected at most " << cache_time; ok = false; } @@ -361,11 +362,11 @@ EbuildFlatMetadataCache::load(const std::tr1::shared_ptr<const EbuildID> & id, c { std::map<std::string, std::string>::const_iterator mtime_it(keys.find("_mtime_")); - std::time_t cache_time(keys.end() == mtime_it ? _imp->filename.mtime() : destringify<std::time_t>(mtime_it->second)); - bool ok(_imp->ebuild.mtime() == cache_time); + std::time_t cache_time(keys.end() == mtime_it ? _imp->filename.mtim().seconds() : destringify<std::time_t>(mtime_it->second)); + bool ok(_imp->ebuild.mtim().seconds() == cache_time); if (! ok) Log::get_instance()->message("e.cache.flat_hash.mtime", ll_debug, lc_context) - << "ebuild has mtime " << _imp->ebuild.mtime() << ", but expected " << cache_time; + << "ebuild has mtime " << _imp->ebuild.mtim().seconds() << ", but expected " << cache_time; if (ok) { std::string cache_guessed(keys["_guessed_eapi_"]); @@ -424,11 +425,11 @@ EbuildFlatMetadataCache::load(const std::tr1::shared_ptr<const EbuildID> & id, c ok = false; } - else if (eclass->mtime() != eclass_mtime) + else if (eclass->mtim().seconds() != eclass_mtime) { Log::get_instance()->message("e.cache.flat_hash.eclass.wrong_mtime", ll_debug, lc_context) << "Cache-requested eclass '" << eclass_name << "' has mtime " - << eclass->mtime() << ", but expected " << eclass_mtime; + << eclass->mtim().seconds() << ", but expected " << eclass_mtime; ok = false; } @@ -481,11 +482,11 @@ EbuildFlatMetadataCache::load(const std::tr1::shared_ptr<const EbuildID> & id, c ok = false; } - else if (exlib->mtime() != exlib_mtime) + else if (exlib->mtim().seconds() != exlib_mtime) { Log::get_instance()->message("e.cache.flat_hash.exlib.wrong_mtime", ll_debug, lc_context) << "Cache-requested exlib '" << exlib_name << "' has mtime " - << exlib->mtime() << ", but expected " << exlib_mtime; + << exlib->mtim().seconds() << ", but expected " << exlib_mtime; ok = false; } @@ -681,7 +682,7 @@ EbuildFlatMetadataCache::save(const std::tr1::shared_ptr<const EbuildID> & id) } std::ostringstream cache; - write_kv(cache, "_mtime_", _imp->ebuild.mtime()); + write_kv(cache, "_mtime_", _imp->ebuild.mtim().seconds()); write_kv(cache, "_guessed_eapi_", id->guessed_eapi_name()); if (id->eapi()->supported()->ebuild_options()->support_eclasses() && id->inherited_key()) @@ -695,7 +696,7 @@ EbuildFlatMetadataCache::save(const std::tr1::shared_ptr<const EbuildID> & id) throw InternalError(PALUDIS_HERE, "eclass '" + *it + "' disappeared?"); eclasses.push_back(*it); eclasses.push_back(stringify(eclass->dirname())); - eclasses.push_back(stringify(eclass->mtime())); + eclasses.push_back(stringify(eclass->mtim().seconds())); } write_kv(cache, "_eclasses_", join(eclasses.begin(), eclasses.end(), "\t")); } @@ -711,7 +712,7 @@ EbuildFlatMetadataCache::save(const std::tr1::shared_ptr<const EbuildID> & id) throw InternalError(PALUDIS_HERE, "exlib '" + *it + "' for '" + stringify(id->name()) + "' disappeared?"); exlibs.push_back(*it); exlibs.push_back(stringify(exlib->dirname())); - exlibs.push_back(stringify(exlib->mtime())); + exlibs.push_back(stringify(exlib->mtim().seconds())); } write_kv(cache, "_exlibs_", join(exlibs.begin(), exlibs.end(), "\t")); } @@ -825,7 +826,7 @@ EbuildFlatMetadataCache::save(const std::tr1::shared_ptr<const EbuildID> & id) SafeOFStream cache_file(_imp->filename); cache_file << cache.str(); } - struct ::utimbuf times = { _imp->ebuild.mtime(), _imp->ebuild.mtime() }; + struct ::utimbuf times = { _imp->ebuild.mtim().seconds(), _imp->ebuild.mtim().seconds() }; _imp->filename.utime(×); } catch (const SafeOFStreamError & e) diff --git a/paludis/repositories/e/ebuild_flat_metadata_cache_TEST.cc b/paludis/repositories/e/ebuild_flat_metadata_cache_TEST.cc index 715565b01..8cf4b8186 100644 --- a/paludis/repositories/e/ebuild_flat_metadata_cache_TEST.cc +++ b/paludis/repositories/e/ebuild_flat_metadata_cache_TEST.cc @@ -33,6 +33,7 @@ #include <paludis/util/wrapped_forward_iterator.hh> #include <paludis/util/safe_ifstream.hh> #include <paludis/util/fs_entry.hh> +#include <paludis/util/timestamp.hh> #include <test/test_framework.hh> #include <test/test_runner.hh> #include <iterator> @@ -1221,7 +1222,7 @@ namespace test_cases TEST_CHECK(id->short_description_key()); TEST_CHECK_EQUAL(contents("ebuild_flat_metadata_cache_TEST_dir/cache/test-repo/cat/write-1"), contents("ebuild_flat_metadata_cache_TEST_dir/cache/expected/cat/write-1")); - TEST_CHECK_EQUAL(FSEntry("ebuild_flat_metadata_cache_TEST_dir/cache/test-repo/cat/write-1").mtime(), 60); + TEST_CHECK_EQUAL(FSEntry("ebuild_flat_metadata_cache_TEST_dir/cache/test-repo/cat/write-1").mtim().seconds(), 60); } } test_metadata_write; @@ -1257,7 +1258,7 @@ namespace test_cases TEST_CHECK(id->short_description_key()); TEST_CHECK_EQUAL(contents("ebuild_flat_metadata_cache_TEST_dir/cache/test-repo/cat/write-eapi1-1"), contents("ebuild_flat_metadata_cache_TEST_dir/cache/expected/cat/write-eapi1-1")); - TEST_CHECK_EQUAL(FSEntry("ebuild_flat_metadata_cache_TEST_dir/cache/test-repo/cat/write-eapi1-1").mtime(), 60); + TEST_CHECK_EQUAL(FSEntry("ebuild_flat_metadata_cache_TEST_dir/cache/test-repo/cat/write-eapi1-1").mtim().seconds(), 60); } } test_metadata_write_eapi1; @@ -1295,7 +1296,7 @@ namespace test_cases TEST_CHECK(id->short_description_key()); TEST_CHECK_EQUAL(contents("ebuild_flat_metadata_cache_TEST_dir/cache/test-repo/cat/write-eclasses-1"), contents("ebuild_flat_metadata_cache_TEST_dir/cache/expected/cat/write-eclasses-1")); - TEST_CHECK_EQUAL(FSEntry("ebuild_flat_metadata_cache_TEST_dir/cache/test-repo/cat/write-eclasses-1").mtime(), 60); + TEST_CHECK_EQUAL(FSEntry("ebuild_flat_metadata_cache_TEST_dir/cache/test-repo/cat/write-eclasses-1").mtim().seconds(), 60); } } test_metadata_write_eclasses; @@ -1332,7 +1333,7 @@ namespace test_cases TEST_CHECK(id->short_description_key()); TEST_CHECK_EQUAL(contents("ebuild_flat_metadata_cache_TEST_dir/cache/test-repo/cat/write-exlibs-1"), contents("ebuild_flat_metadata_cache_TEST_dir/cache/expected/cat/write-exlibs-1")); - TEST_CHECK_EQUAL(FSEntry("ebuild_flat_metadata_cache_TEST_dir/cache/test-repo/cat/write-exlibs-1").mtime(), 60); + TEST_CHECK_EQUAL(FSEntry("ebuild_flat_metadata_cache_TEST_dir/cache/test-repo/cat/write-exlibs-1").mtim().seconds(), 60); } } test_metadata_write_exlibs; } diff --git a/paludis/repositories/e/memoised_hashes.cc b/paludis/repositories/e/memoised_hashes.cc index 328e6e677..2da2403a0 100644 --- a/paludis/repositories/e/memoised_hashes.cc +++ b/paludis/repositories/e/memoised_hashes.cc @@ -28,6 +28,7 @@ #include <paludis/util/sha1.hh> #include <paludis/util/sha256.hh> #include <paludis/util/md5.hh> +#include <paludis/util/timestamp.hh> #include <map> @@ -36,7 +37,7 @@ using namespace paludis::erepository; namespace paludis { - typedef std::map<std::pair<std::string, int>, std::pair<time_t, std::string> > HashesMap; + typedef std::map<std::pair<std::string, int>, std::pair<Timestamp, std::string> > HashesMap; template <> struct Implementation<MemoisedHashes> @@ -98,7 +99,7 @@ const std::string MemoisedHashes::get(const FSEntry & file, SafeIFStream & stream) const { std::pair<std::string, int> key(stringify(file), HashIDs<H_>::id); - time_t mtime = file.mtime(); + Timestamp mtime(file.mtim()); Lock l(_imp->mutex); @@ -107,7 +108,7 @@ MemoisedHashes::get(const FSEntry & file, SafeIFStream & stream) const if (i == _imp->hashes.end() || i->second.first != mtime) { H_ hash(stream); - std::pair<time_t, std::string> value = std::make_pair(mtime, hash.hexsum()); + std::pair<Timestamp, std::string> value(std::make_pair(mtime, hash.hexsum())); stream.clear(); stream.seekg(0, std::ios::beg); diff --git a/paludis/repositories/e/vdb_merger.cc b/paludis/repositories/e/vdb_merger.cc index da48eaecc..bcf0a8afc 100644 --- a/paludis/repositories/e/vdb_merger.cc +++ b/paludis/repositories/e/vdb_merger.cc @@ -30,6 +30,7 @@ #include <paludis/util/options.hh> #include <paludis/util/make_named_values.hh> #include <paludis/util/enum_iterator.hh> +#include <paludis/util/timestamp.hh> #include <paludis/output_manager.hh> #include <paludis/util/safe_ofstream.hh> #include <paludis/util/safe_ifstream.hh> @@ -138,7 +139,7 @@ VDBMerger::record_install_file(const FSEntry & src, const FSEntry & dst_dir, con { std::string tidy(stringify((dst_dir / dst_name).strip_leading(_imp->realroot))), tidy_real(stringify((dst_dir / src.basename()).strip_leading(_imp->realroot))); - time_t timestamp((dst_dir / dst_name).mtime()); + Timestamp timestamp((dst_dir / dst_name).mtim()); SafeIFStream infile(FSEntry(dst_dir / dst_name)); if (! infile) @@ -151,7 +152,7 @@ VDBMerger::record_install_file(const FSEntry & src, const FSEntry & dst_dir, con line.append(" (" + FSEntry(tidy).basename() + ")"); display_override(line); - *_imp->contents_file << "obj " << tidy_real << " " << md5.hexsum() << " " << timestamp << std::endl; + *_imp->contents_file << "obj " << tidy_real << " " << md5.hexsum() << " " << timestamp.seconds() << std::endl; } void @@ -177,11 +178,11 @@ VDBMerger::record_install_sym(const FSEntry & src, const FSEntry & dst_dir, cons { std::string tidy(stringify((dst_dir / src.basename()).strip_leading(_imp->realroot))); std::string target((dst_dir / src.basename()).readlink()); - time_t timestamp((dst_dir / src.basename()).mtime()); + Timestamp timestamp((dst_dir / src.basename()).mtim()); display_override(make_arrows(flags) + " [sym] " + tidy); - *_imp->contents_file << "sym " << tidy << " -> " << target << " " << timestamp << std::endl; + *_imp->contents_file << "sym " << tidy << " -> " << target << " " << timestamp.seconds() << std::endl; } void diff --git a/paludis/repositories/e/vdb_repository.cc b/paludis/repositories/e/vdb_repository.cc index 1b180b6b1..31f7bc022 100644 --- a/paludis/repositories/e/vdb_repository.cc +++ b/paludis/repositories/e/vdb_repository.cc @@ -76,6 +76,7 @@ #include <paludis/output_manager.hh> #include <paludis/util/safe_ifstream.hh> #include <paludis/util/safe_ofstream.hh> +#include <paludis/util/timestamp.hh> #include <paludis/util/private_implementation_pattern-impl.hh> #include <paludis/util/create_iterator-impl.hh> @@ -1292,7 +1293,7 @@ VDBRepository::perform_updates() FSEntry cache_dir(_imp->params.location() / ".cache"); FSEntry cache_file(cache_dir / "updates_time_cache"); if (cache_file.is_regular_file_or_symlink_to_regular_file()) - ignore_updates_before = cache_file.mtime(); + ignore_updates_before = cache_file.mtim().seconds(); std::cout << std::endl << "Checking for updates (package moves etc):" << std::endl; @@ -1336,7 +1337,7 @@ VDBRepository::perform_updates() if (! d->is_regular_file_or_symlink_to_regular_file()) continue; - if (d->mtime() <= ignore_updates_before) + if (d->mtim().seconds() <= ignore_updates_before) { Log::get_instance()->message("e.vdb.updates.ignoring", ll_debug, lc_context) << "Ignoring " << *d << " because it hasn't changed"; diff --git a/paludis/repositories/e/vdb_unmerger.cc b/paludis/repositories/e/vdb_unmerger.cc index 6d35b68b3..0ae5943b4 100644 --- a/paludis/repositories/e/vdb_unmerger.cc +++ b/paludis/repositories/e/vdb_unmerger.cc @@ -41,6 +41,7 @@ using namespace paludis; #include <paludis/util/make_named_values.hh> #include <paludis/util/simple_visitor_cast.hh> #include <paludis/util/set.hh> +#include <paludis/util/timestamp.hh> #include <paludis/output_manager.hh> #include <paludis/util/safe_ifstream.hh> @@ -222,7 +223,7 @@ VDBUnmerger::check_file(const std::tr1::shared_ptr<const ContentsEntry> & e) con display("--- [gone ] " + stringify(f)); else if (! (_imp->options.root() / f).is_regular_file()) display("--- [!type] " + stringify(f)); - else if ((_imp->options.root() / f).mtime() != require_key<MetadataTimeKey>(*e, "mtime").value()) + else if ((_imp->options.root() / f).mtim().seconds() != require_key<MetadataTimeKey>(*e, "mtime").value().seconds()) display("--- [!time] " + stringify(f)); else { @@ -256,7 +257,7 @@ VDBUnmerger::check_sym(const std::tr1::shared_ptr<const ContentsEntry> & e) cons display("--- [gone ] " + stringify(f)); else if (! (_imp->options.root() / f).is_symbolic_link()) display("--- [!type] " + stringify(f)); - else if ((_imp->options.root() / f).mtime() != require_key<MetadataTimeKey>(*e, "mtime").value()) + else if ((_imp->options.root() / f).mtim().seconds() != require_key<MetadataTimeKey>(*e, "mtime").value().seconds()) display("--- [!time] " + stringify(f)); else if ((_imp->options.root() / f).readlink() != require_key<MetadataValueKey<std::string> >(*e, "target").value()) display("--- [!dest] " + stringify(f)); diff --git a/paludis/repositories/unpackaged/installed_id.cc b/paludis/repositories/unpackaged/installed_id.cc index 38055a0a2..eff03a4bd 100644 --- a/paludis/repositories/unpackaged/installed_id.cc +++ b/paludis/repositories/unpackaged/installed_id.cc @@ -35,6 +35,7 @@ #include <paludis/util/wrapped_forward_iterator.hh> #include <paludis/util/safe_ifstream.hh> #include <paludis/util/return_literal_function.hh> +#include <paludis/util/timestamp.hh> #include <paludis/output_manager.hh> #include <paludis/name.hh> #include <paludis/version_spec.hh> @@ -157,15 +158,15 @@ namespace public MetadataTimeKey { private: - const time_t _time; + const Timestamp _time; public: InstalledUnpackagedTimeKey(const FSEntry & f) : - _time(f.mtime()) + _time(f.mtim()) { } - time_t value() const + Timestamp value() const { return _time; } diff --git a/paludis/user_dep_spec.cc b/paludis/user_dep_spec.cc index 83d9d3b4e..e416e7c8b 100644 --- a/paludis/user_dep_spec.cc +++ b/paludis/user_dep_spec.cc @@ -36,6 +36,7 @@ #include <paludis/util/set.hh> #include <paludis/util/sequence.hh> #include <paludis/util/indirect_iterator-impl.hh> +#include <paludis/util/timestamp.hh> using namespace paludis; @@ -386,7 +387,7 @@ namespace bool visit(const MetadataTimeKey & k) const { - return pattern == stringify(k.value()); + return pattern == stringify(k.value().seconds()); } bool visit(const MetadataValueKey<std::string> & k) const diff --git a/paludis/util/files.m4 b/paludis/util/files.m4 index 710614cf0..6a8404353 100644 --- a/paludis/util/files.m4 +++ b/paludis/util/files.m4 @@ -78,6 +78,7 @@ add(`tail_output_stream', `hh', `cc', `fwd', `test') add(`tee_output_stream', `hh', `cc', `fwd') add(`thread', `hh', `cc', `test') add(`thread_pool', `hh', `cc', `test') +add(`timestamp', `hh', `cc', `fwd') add(`tokeniser', `hh', `cc', `test') add(`tribool', `hh', `cc', `fwd', `test') add(`type_list', `hh', `cc', `fwd') diff --git a/paludis/util/fs_entry.cc b/paludis/util/fs_entry.cc index 3c7058536..a83e2c965 100644 --- a/paludis/util/fs_entry.cc +++ b/paludis/util/fs_entry.cc @@ -27,6 +27,7 @@ #include <paludis/util/sequence-impl.hh> #include <paludis/util/set.hh> #include <paludis/util/set-impl.hh> +#include <paludis/util/timestamp.hh> #include <paludis/util/wrapped_forward_iterator.hh> #include <paludis/util/wrapped_forward_iterator-impl.hh> #include <paludis/util/wrapped_output_iterator.hh> @@ -510,26 +511,26 @@ paludis::operator<< (std::ostream & s, const FSEntry & f) return s; } -time_t -FSEntry::ctime() const +Timestamp +FSEntry::ctim() const { _stat(); if (! _imp->exists) throw FSError("Filesystem entry '" + _imp->path + "' does not exist"); - return (*_imp->stat_info).st_ctime; + return Timestamp((*_imp->stat_info).st_ctim); } -time_t -FSEntry::mtime() const +Timestamp +FSEntry::mtim() const { _stat(); if (! _imp->exists) throw FSError("Filesystem entry '" + _imp->path + "' does not exist"); - return (*_imp->stat_info).st_mtime; + return Timestamp((*_imp->stat_info).st_mtim); } off_t diff --git a/paludis/util/fs_entry.hh b/paludis/util/fs_entry.hh index 0b87a0744..e0763d163 100644 --- a/paludis/util/fs_entry.hh +++ b/paludis/util/fs_entry.hh @@ -1,7 +1,7 @@ /* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* - * Copyright (c) 2005, 2006, 2007, 2008 Ciaran McCreesh + * Copyright (c) 2005, 2006, 2007, 2008, 2009 Ciaran McCreesh * Copyright (c) 2006 Mark Loeser * * This file is part of the Paludis package manager. Paludis is free software; @@ -25,6 +25,7 @@ #include <paludis/util/exception.hh> #include <paludis/util/operators.hh> #include <paludis/util/private_implementation_pattern.hh> +#include <paludis/util/timestamp-fwd.hh> #include <string> #include <tr1/memory> #include <iosfwd> @@ -254,16 +255,20 @@ namespace paludis /** * Return the time the inode for the filesystem entry was last modified + * * \exception FSError if there was a problem accessing the filesystem entry + * \since 0.43 */ - time_t ctime() const + Timestamp ctim() const PALUDIS_ATTRIBUTE((warn_unused_result)); /** * Return the time the filesystem entry was last modified + * * \exception FSError if there was a problem accessing the filesystem entry + * \since 0.43 */ - time_t mtime() const + Timestamp mtim() const PALUDIS_ATTRIBUTE((warn_unused_result)); /** diff --git a/paludis/util/fs_entry_TEST.cc b/paludis/util/fs_entry_TEST.cc index ec1fcfd57..e70c4a6b4 100644 --- a/paludis/util/fs_entry_TEST.cc +++ b/paludis/util/fs_entry_TEST.cc @@ -1,7 +1,7 @@ /* vim: set sw=4 sts=4 et foldmethod=syntax : */ /* - * Copyright (c) 2005, 2006, 2007, 2008 Ciaran McCreesh + * Copyright (c) 2005, 2006, 2007, 2008, 2009 Ciaran McCreesh * Copyright (c) 2006 Mark Loeser * * This file is part of the Paludis package manager. Paludis is free software; @@ -18,15 +18,16 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <ctime> #include <paludis/util/fs_entry.hh> #include <paludis/util/log.hh> +#include <paludis/util/timestamp.hh> #include <test/test_framework.hh> #include <test/test_runner.hh> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <pwd.h> +#include <ctime> using namespace paludis; using namespace test; @@ -62,26 +63,20 @@ namespace test_cases FSEntry c("fs_entry_TEST_dir/no_such_file"); FSEntry d("fs_entry_TEST_dir/dir_a/dir_in_a"); - paludis::Log::get_instance()->message("util.fs_entry_TEST.cmtime", ll_debug, lc_context) - << "a.ctime() : " << a.ctime() << " :: a.mtime() : " << a.mtime() << " :: std::time(0) : " << std::time(0); - paludis::Log::get_instance()->message("util.fs_entry_TEST.cmtime", ll_debug, lc_context) - << "b.ctime() : " << b.ctime() << " :: b.mtime() : " << b.mtime() << " :: std::time(0) : " << std::time(0); - paludis::Log::get_instance()->message("util.fs_entry_TEST.cmtime", ll_debug, lc_context) - << "d.ctime() : " << d.ctime() << " :: d.mtime() : " << d.mtime() << " :: std::time(0) : " << std::time(0); #if !defined(__FreeBSD__) - TEST_CHECK(a.ctime() < std::time(0)); - TEST_CHECK(a.mtime() < std::time(0)); + TEST_CHECK(a.ctim() < Timestamp::now()); + TEST_CHECK(a.mtim() < Timestamp::now()); #endif - TEST_CHECK(b.ctime() < std::time(0)); - TEST_CHECK(b.mtime() < std::time(0)); - TEST_CHECK(d.ctime() < std::time(0)); - TEST_CHECK(d.mtime() < std::time(0)); + TEST_CHECK(b.ctim() < Timestamp::now()); + TEST_CHECK(b.mtim() < Timestamp::now()); + TEST_CHECK(d.ctim() < Timestamp::now()); + TEST_CHECK(d.mtim() < Timestamp::now()); - TEST_CHECK(b.mtime() < b.ctime()); - TEST_CHECK(d.mtime() == d.ctime()); + TEST_CHECK(b.mtim() < b.ctim()); + TEST_CHECK(d.mtim() == d.ctim()); - TEST_CHECK_THROWS(time_t PALUDIS_ATTRIBUTE((unused)) x = c.ctime(), FSError); - TEST_CHECK_THROWS(time_t PALUDIS_ATTRIBUTE((unused)) x = c.mtime(), FSError); + TEST_CHECK_THROWS(Timestamp PALUDIS_ATTRIBUTE((unused)) x = c.ctim(), FSError); + TEST_CHECK_THROWS(Timestamp PALUDIS_ATTRIBUTE((unused)) x = c.mtim(), FSError); } } test_fs_entry_time; diff --git a/paludis/util/timestamp-fwd.hh b/paludis/util/timestamp-fwd.hh new file mode 100644 index 000000000..6c329f4f2 --- /dev/null +++ b/paludis/util/timestamp-fwd.hh @@ -0,0 +1,28 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2009 Ciaran McCreesh + * + * This file is part of the Paludis package manager. Paludis is free software; + * you can redistribute it and/or modify it under the terms of the GNU General + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PALUDIS_GUARD_PALUDIS_UTIL_TIMESTAMP_FWD_HH +#define PALUDIS_GUARD_PALUDIS_UTIL_TIMESTAMP_FWD_HH 1 + +namespace paludis +{ + struct Timestamp; +} + +#endif diff --git a/paludis/util/timestamp.cc b/paludis/util/timestamp.cc new file mode 100644 index 000000000..95553b259 --- /dev/null +++ b/paludis/util/timestamp.cc @@ -0,0 +1,92 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2009 Ciaran McCreesh + * + * This file is part of the Paludis package manager. Paludis is free software; + * you can redistribute it and/or modify it under the terms of the GNU General + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <paludis/util/timestamp.hh> +#include <paludis/util/stringify.hh> +#include <paludis/util/exception.hh> +#include <time.h> + +using namespace paludis; + +Timestamp::Timestamp(const struct timespec & t) : + _s(t.tv_sec), + _ns(t.tv_nsec) +{ +} + +Timestamp::Timestamp(const time_t s, const long ns) : + _s(s), + _ns(ns) +{ +} + +Timestamp::Timestamp(const Timestamp & other) : + _s(other._s), + _ns(other._ns) +{ +} + +Timestamp & +Timestamp::operator= (const Timestamp & other) +{ + _s = other._s; + _ns = other._ns; + return *this; +} + +bool +Timestamp::operator== (const Timestamp & other) const +{ + return _s == other._s && _ns == other._ns; +} + +bool +Timestamp::operator< (const Timestamp & other) const +{ + return (_s < other._s) || (_s == other._s && _ns < other._ns); +} + +time_t +Timestamp::seconds() const +{ + return _s; +} + +long +Timestamp::nanoseconds() const +{ + return _ns; +} + +struct timespec +Timestamp::as_timespec() const +{ + struct timespec result = { _s, _ns }; + return result; +} + +Timestamp +Timestamp::now() +{ + struct timespec t; + if (0 != clock_gettime(CLOCK_REALTIME, &t)) + throw InternalError(PALUDIS_HERE, "clock_gettime returned non-zero"); + return Timestamp(t); +} + diff --git a/paludis/util/timestamp.hh b/paludis/util/timestamp.hh new file mode 100644 index 000000000..2e3fd84b4 --- /dev/null +++ b/paludis/util/timestamp.hh @@ -0,0 +1,65 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2009 Ciaran McCreesh + * + * This file is part of the Paludis package manager. Paludis is free software; + * you can redistribute it and/or modify it under the terms of the GNU General + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PALUDIS_GUARD_PALUDIS_UTIL_TIMESTAMP_HH +#define PALUDIS_GUARD_PALUDIS_UTIL_TIMESTAMP_HH 1 + +#include <paludis/util/timestamp-fwd.hh> +#include <paludis/util/operators.hh> +#include <paludis/util/attributes.hh> +#include <sys/stat.h> + +namespace paludis +{ + /** + * Wrapper class to simplify dealing with the zillion different ways C has + * of dealing with timestamps. + * + * Most definitely not for use for durations (that is, the difference + * between two date-times). + * + * \since 0.44 + */ + class PALUDIS_VISIBLE Timestamp : + public relational_operators::HasRelationalOperators + { + private: + time_t _s; + long _ns; + + public: + explicit Timestamp(const struct timespec &); + Timestamp(const time_t, const long); + Timestamp(const Timestamp &); + + Timestamp & operator= (const Timestamp &); + + bool operator== (const Timestamp &) const PALUDIS_ATTRIBUTE((warn_unused_result)); + bool operator< (const Timestamp &) const PALUDIS_ATTRIBUTE((warn_unused_result)); + + time_t seconds() const PALUDIS_ATTRIBUTE((warn_unused_result)); + long nanoseconds() const PALUDIS_ATTRIBUTE((warn_unused_result)); + + struct timespec as_timespec() const PALUDIS_ATTRIBUTE((warn_unused_result)); + + static Timestamp now() PALUDIS_ATTRIBUTE((warn_unused_result)); + }; +} + +#endif diff --git a/python/additional_tests.cc b/python/additional_tests.cc index 0219d675b..f1abe0787 100644 --- a/python/additional_tests.cc +++ b/python/additional_tests.cc @@ -37,6 +37,7 @@ #include <paludis/formatter.hh> #include <paludis/stringify_formatter-impl.hh> #include <paludis/util/clone-impl.hh> +#include <paludis/util/timestamp.hh> #include <tr1/memory> using namespace paludis; @@ -169,7 +170,7 @@ namespace metadata_key void test_metadata_time_key(const MetadataTimeKey & m) { test_metadata_key(m); - time_t PALUDIS_ATTRIBUTE((unused)) t(m.value()); + Timestamp PALUDIS_ATTRIBUTE((unused)) t(m.value()); } void test_metadata_contents_key(const MetadataValueKey<std::tr1::shared_ptr<const Contents> > & m) diff --git a/python/metadata_key.cc b/python/metadata_key.cc index 101a6e06d..8d5cfc329 100644 --- a/python/metadata_key.cc +++ b/python/metadata_key.cc @@ -29,6 +29,7 @@ #include <paludis/util/set.hh> #include <paludis/util/make_shared_ptr.hh> #include <paludis/util/sequence.hh> +#include <paludis/util/timestamp.hh> using namespace paludis; using namespace paludis::python; @@ -391,13 +392,13 @@ struct MetadataTimeKeyWrapper : MetadataTimeKey, bp::wrapper<MetadataTimeKey> { - virtual time_t value() const + virtual Timestamp value() const PALUDIS_ATTRIBUTE((warn_unused_result)) { Lock l(get_mutex()); if (bp::override f = get_override("value")) - return f(); + return Timestamp(f(), 0); else throw PythonMethodNotImplemented("MetadataTimeKey", "value"); } diff --git a/ruby/metadata_key.cc b/ruby/metadata_key.cc index 3305ae694..5bd33772a 100644 --- a/ruby/metadata_key.cc +++ b/ruby/metadata_key.cc @@ -26,6 +26,7 @@ #include <paludis/util/set.hh> #include <paludis/util/sequence.hh> #include <paludis/util/simple_visitor_cast.hh> +#include <paludis/util/timestamp.hh> #include <ruby.h> using namespace paludis; @@ -368,7 +369,7 @@ namespace { std::tr1::shared_ptr<const MetadataKey> * self_ptr; Data_Get_Struct(self, std::tr1::shared_ptr<const MetadataKey>, self_ptr); - return rb_time_new((std::tr1::static_pointer_cast<const MetadataTimeKey>(*self_ptr))->value(), 0); + return rb_time_new((std::tr1::static_pointer_cast<const MetadataTimeKey>(*self_ptr))->value().seconds(), 0); } catch (const std::exception & e) { diff --git a/src/clients/cave/cmd_resolve.cc b/src/clients/cave/cmd_resolve.cc index 51141a3e2..59d273eb6 100644 --- a/src/clients/cave/cmd_resolve.cc +++ b/src/clients/cave/cmd_resolve.cc @@ -35,6 +35,7 @@ #include <paludis/util/wrapped_output_iterator.hh> #include <paludis/util/string_list_stream.hh> #include <paludis/util/thread.hh> +#include <paludis/util/timestamp.hh> #include <paludis/args/do_help.hh> #include <paludis/args/escape.hh> #include <paludis/resolver/resolver.hh> @@ -500,12 +501,12 @@ namespace { if (id->version().is_scm() || is_scm_name(id->name())) { - static time_t current_time(time(0)); /* static to avoid weirdness */ - time_t installed_time(current_time); + static Timestamp current_time(Timestamp::now()); /* static to avoid weirdness */ + time_t installed_time(current_time.seconds()); if (id->installed_time_key()) - installed_time = id->installed_time_key()->value(); + installed_time = id->installed_time_key()->value().seconds(); - return (current_time - installed_time) > (24 * 60 * 60 * n); + return (current_time.seconds() - installed_time) > (24 * 60 * 60 * n); } else return false; diff --git a/src/clients/cave/cmd_show.cc b/src/clients/cave/cmd_show.cc index 50e32bac0..3e4f80a75 100644 --- a/src/clients/cave/cmd_show.cc +++ b/src/clients/cave/cmd_show.cc @@ -42,6 +42,7 @@ #include <paludis/util/simple_visitor_cast.hh> #include <paludis/util/indirect_iterator-impl.hh> #include <paludis/util/pretty_print.hh> +#include <paludis/util/timestamp.hh> #include <paludis/action.hh> #include <paludis/mask.hh> #include <paludis/choice.hh> @@ -589,7 +590,7 @@ namespace void visit(const MetadataTimeKey & k) { cout << format_general_rhvib(f::show_metadata_key_value(), k.raw_name(), k.human_name(), - pretty_print_time(k.value()), indent, important); + pretty_print_time(k.value().seconds()), indent, important); } }; diff --git a/src/clients/cave/format_plain_metadata_key.cc b/src/clients/cave/format_plain_metadata_key.cc index a908cd7f0..b0a42cabb 100644 --- a/src/clients/cave/format_plain_metadata_key.cc +++ b/src/clients/cave/format_plain_metadata_key.cc @@ -24,6 +24,7 @@ #include <paludis/util/sequence.hh> #include <paludis/util/wrapped_forward_iterator.hh> #include <paludis/util/map.hh> +#include <paludis/util/timestamp.hh> #include <paludis/stringify_formatter.hh> #include <paludis/metadata_key.hh> #include <paludis/mask.hh> @@ -40,7 +41,7 @@ namespace void visit(const MetadataTimeKey & k) { - s << k.value(); + s << k.value().seconds(); } void visit(const MetadataValueKey<std::tr1::shared_ptr<const RepositoryMaskInfo> > & k) diff --git a/src/clients/inquisitio/key_extractor.cc b/src/clients/inquisitio/key_extractor.cc index 13e2562ac..c0ae96580 100644 --- a/src/clients/inquisitio/key_extractor.cc +++ b/src/clients/inquisitio/key_extractor.cc @@ -26,6 +26,7 @@ #include <paludis/util/join.hh> #include <paludis/util/sequence.hh> #include <paludis/util/indirect_iterator-impl.hh> +#include <paludis/util/timestamp.hh> #include <paludis/package_id.hh> #include <paludis/metadata_key.hh> #include <paludis/stringify_formatter.hh> @@ -227,7 +228,7 @@ namespace void visit(const MetadataTimeKey & s) { - result = _m(stringify(s.value())); + result = _m(stringify(s.value().seconds())); } void visit(const MetadataValueKey<std::tr1::shared_ptr<const Contents> > &) diff --git a/src/clients/instruo/instruo.cc b/src/clients/instruo/instruo.cc index a3fdc9694..98a098c54 100644 --- a/src/clients/instruo/instruo.cc +++ b/src/clients/instruo/instruo.cc @@ -42,6 +42,7 @@ #include <paludis/util/safe_ofstream.hh> #include <paludis/util/pretty_print.hh> #include <paludis/util/indirect_iterator-impl.hh> +#include <paludis/util/timestamp.hh> #include <paludis/environments/no_config/no_config_environment.hh> #include <paludis/package_database.hh> #include <paludis/metadata_key.hh> @@ -87,7 +88,7 @@ namespace void visit(const MetadataTimeKey & k) { - time_t PALUDIS_ATTRIBUTE((unused)) t(k.value()); + Timestamp PALUDIS_ATTRIBUTE((unused)) t(k.value()); } void visit(const MetadataValueKey<std::tr1::shared_ptr<const Contents> > & k) diff --git a/src/clients/paludis/applets.cc b/src/clients/paludis/applets.cc index b15efba30..83c41fe00 100644 --- a/src/clients/paludis/applets.cc +++ b/src/clients/paludis/applets.cc @@ -27,6 +27,7 @@ #include <paludis/util/dir_iterator.hh> #include <paludis/util/system.hh> #include <paludis/util/tokeniser.hh> +#include <paludis/util/timestamp.hh> #include <paludis/repository_factory.hh> #include <string> #include <set> @@ -172,7 +173,7 @@ namespace void visit(const MetadataTimeKey & k) { - std::cout << k.value() << std::endl; + std::cout << k.value().seconds() << std::endl; } }; } diff --git a/src/clients/paludis/info.cc b/src/clients/paludis/info.cc index 6eececd9f..50cac280e 100644 --- a/src/clients/paludis/info.cc +++ b/src/clients/paludis/info.cc @@ -30,6 +30,7 @@ #include <paludis/util/pretty_print.hh> #include <paludis/util/wrapped_output_iterator.hh> #include <paludis/util/indirect_iterator-impl.hh> +#include <paludis/util/timestamp.hh> #include <paludis/package_database.hh> #include <paludis/environment.hh> #include <paludis/package_id.hh> @@ -135,7 +136,7 @@ namespace void visit(const MetadataTimeKey & k) { cout << std::setw(30) << (indent + k.human_name() + ":") << " " - << pretty_print_time(k.value()) << endl; + << pretty_print_time(k.value().seconds()) << endl; } void visit(const MetadataSpecTreeKey<PlainTextSpecTree> & k) diff --git a/src/output/console_query_task.cc b/src/output/console_query_task.cc index 468694d05..4a062fa7d 100644 --- a/src/output/console_query_task.cc +++ b/src/output/console_query_task.cc @@ -32,6 +32,7 @@ #include <paludis/util/make_named_values.hh> #include <paludis/util/pretty_print.hh> #include <paludis/util/indirect_iterator-impl.hh> +#include <paludis/util/timestamp.hh> #include <paludis/package_dep_spec_properties.hh> #include <paludis/mask.hh> #include <paludis/metadata_key.hh> @@ -645,10 +646,10 @@ namespace void visit(const MetadataTimeKey & k) { - if (0 == k.value()) + if (0 == k.value().seconds()) return; - std::string pretty_time(pretty_print_time(k.value())); + std::string pretty_time(pretty_print_time(k.value().seconds())); if (k.type() == type) { diff --git a/src/output/mask_displayer.cc b/src/output/mask_displayer.cc index 7732f270e..8788bf50a 100644 --- a/src/output/mask_displayer.cc +++ b/src/output/mask_displayer.cc @@ -26,6 +26,7 @@ #include <paludis/util/set.hh> #include <paludis/util/wrapped_forward_iterator.hh> #include <paludis/util/pretty_print.hh> +#include <paludis/util/timestamp.hh> #include <paludis/name.hh> #include <paludis/metadata_key.hh> #include <sstream> @@ -107,7 +108,7 @@ namespace void visit(const MetadataTimeKey & k) { - s << pretty_print_time(k.value()); + s << pretty_print_time(k.value().seconds()); } void visit(const MetadataValueKey<std::tr1::shared_ptr<const Contents> > &) |