aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-08-17 00:12:27 +0100
committerAvatar David Leverton <levertond@googlemail.com> 2008-08-17 00:12:27 +0100
commitb4b2f99b420ad3e35291807d41112423bc46ee2a (patch)
tree4f6b5928ffeafaf0aff422b5f5478a896453abed
parent40b30301b395c737736b87ff2ed8434634b562af (diff)
downloadpaludis-b4b2f99b420ad3e35291807d41112423bc46ee2a.tar.gz
paludis-b4b2f99b420ad3e35291807d41112423bc46ee2a.tar.xz
Greater compatibility with Portage and pkgcore w.r.t. mtimes, per discussion with zmedico and ferringb.
-rw-r--r--paludis/repositories/e/ebuild_flat_metadata_cache.cc18
-rw-r--r--paludis/repositories/e/ebuild_flat_metadata_cache.hh2
-rw-r--r--paludis/repositories/e/ebuild_flat_metadata_cache_TEST.cc59
-rwxr-xr-xpaludis/repositories/e/ebuild_flat_metadata_cache_TEST_setup.sh56
4 files changed, 126 insertions, 9 deletions
diff --git a/paludis/repositories/e/ebuild_flat_metadata_cache.cc b/paludis/repositories/e/ebuild_flat_metadata_cache.cc
index c473aad..c92adab 100644
--- a/paludis/repositories/e/ebuild_flat_metadata_cache.cc
+++ b/paludis/repositories/e/ebuild_flat_metadata_cache.cc
@@ -41,6 +41,7 @@
#include <cstring>
#include <ctime>
#include <errno.h>
+#include <utime.h>
using namespace paludis;
using namespace paludis::erepository;
@@ -51,13 +52,13 @@ namespace paludis
struct Implementation<EbuildFlatMetadataCache>
{
const Environment * const env;
- const FSEntry & filename;
+ FSEntry & filename;
const FSEntry & ebuild;
std::time_t master_mtime;
std::tr1::shared_ptr<const EclassMtimes> eclass_mtimes;
bool silent;
- Implementation(const Environment * const e, const FSEntry & f, const FSEntry & eb,
+ Implementation(const Environment * const e, FSEntry & f, const FSEntry & eb,
std::time_t m, const std::tr1::shared_ptr<const EclassMtimes> em, bool s) :
env(e),
filename(f),
@@ -262,7 +263,7 @@ namespace
}
}
-EbuildFlatMetadataCache::EbuildFlatMetadataCache(const Environment * const v, const FSEntry & f,
+EbuildFlatMetadataCache::EbuildFlatMetadataCache(const Environment * const v, FSEntry & f,
const FSEntry & e, std::time_t t, std::tr1::shared_ptr<const EclassMtimes> m, bool s) :
PrivateImplementationPattern<EbuildFlatMetadataCache>(new Implementation<EbuildFlatMetadataCache>(v, f, e, t, m, s))
{
@@ -330,10 +331,12 @@ EbuildFlatMetadataCache::load(const std::tr1::shared_ptr<const EbuildID> & id)
const EAPIEbuildMetadataVariables & m(*id->eapi()->supported()->ebuild_metadata_variables());
{
- bool ok(_imp->ebuild.mtime() == destringify<std::time_t>(keys["_mtime_"]));
+ 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);
if (! ok)
Log::get_instance()->message("e.cache.flat_hash.mtime", ll_debug, lc_context)
- << "ebuild has mtime " << _imp->ebuild.mtime() << ", but expected " << keys["_mtime_"];
+ << "ebuild has mtime " << _imp->ebuild.mtime() << ", but expected " << cache_time;
if (ok && id->eapi()->supported()->ebuild_options()->support_eclasses())
{
@@ -762,7 +765,12 @@ EbuildFlatMetadataCache::save(const std::tr1::shared_ptr<const EbuildID> & id)
std::ofstream cache_file(stringify(_imp->filename).c_str());
if (cache_file)
+ {
cache_file << cache.str();
+ cache_file.close();
+ struct ::utimbuf times = { _imp->ebuild.mtime(), _imp->ebuild.mtime() };
+ _imp->filename.utime(&times);
+ }
else
{
Log::get_instance()->message("e.cache.save.failure", ll_warning, lc_no_context) << "Couldn't write cache file to '"
diff --git a/paludis/repositories/e/ebuild_flat_metadata_cache.hh b/paludis/repositories/e/ebuild_flat_metadata_cache.hh
index 88f6b52..12a98cb 100644
--- a/paludis/repositories/e/ebuild_flat_metadata_cache.hh
+++ b/paludis/repositories/e/ebuild_flat_metadata_cache.hh
@@ -46,7 +46,7 @@ namespace paludis
///\name Basic operations
///\{
- EbuildFlatMetadataCache(const Environment * const, const FSEntry & filename, const FSEntry & ebuild,
+ EbuildFlatMetadataCache(const Environment * const, FSEntry & filename, const FSEntry & ebuild,
time_t master_mtime, std::tr1::shared_ptr<const EclassMtimes> eclass_mtimes, bool silent);
~EbuildFlatMetadataCache();
diff --git a/paludis/repositories/e/ebuild_flat_metadata_cache_TEST.cc b/paludis/repositories/e/ebuild_flat_metadata_cache_TEST.cc
index 7610c06..5e850f4 100644
--- a/paludis/repositories/e/ebuild_flat_metadata_cache_TEST.cc
+++ b/paludis/repositories/e/ebuild_flat_metadata_cache_TEST.cc
@@ -351,10 +351,64 @@ namespace test_cases
&env, UserPackageDepSpecOptions()))))]->begin());
TEST_CHECK(id1->short_description_key());
- TEST_CHECK_EQUAL(id1->short_description_key()->value(), "The Generated Description flat_hash-no-mtime");
+ TEST_CHECK_EQUAL(id1->short_description_key()->value(), "the-description-flat_hash-no-mtime");
}
} test_metadata_flat_hash_no_mtime;
+ struct MetadataFlatHashNoMtimeStaleTest : TestCase
+ {
+ MetadataFlatHashNoMtimeStaleTest() : TestCase("metadata flat_hash no mtime stale") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ env.set_paludis_command("/bin/false");
+ std::tr1::shared_ptr<Map<std::string, std::string> > keys(new Map<std::string, std::string>);
+ keys->insert("format", "ebuild");
+ keys->insert("names_cache", "/var/empty");
+ keys->insert("location", "ebuild_flat_metadata_cache_TEST_dir/repo");
+ keys->insert("profiles", "ebuild_flat_metadata_cache_TEST_dir/repo/profiles/profile");
+ keys->insert("eclassdirs", "ebuild_flat_metadata_cache_TEST_dir/repo/eclass ebuild_flat_metadata_cache_TEST_dir/extra_eclasses");
+ std::tr1::shared_ptr<Repository> repo(ERepository::repository_factory_create(&env,
+ std::tr1::bind(from_keys, keys, std::tr1::placeholders::_1)));
+ env.package_database()->add_repository(1, repo);
+
+ const std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/flat_hash-no-mtime-stale-1",
+ &env, UserPackageDepSpecOptions()))))]->begin());
+
+ TEST_CHECK(id1->short_description_key());
+ TEST_CHECK_EQUAL(id1->short_description_key()->value(), "The Generated Description flat_hash-no-mtime-stale");
+ }
+ } test_metadata_flat_hash_no_mtime_stale;
+
+ struct MetadataFlatHashBadMtimeTest : TestCase
+ {
+ MetadataFlatHashBadMtimeTest() : TestCase("metadata flat_hash bad mtime") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ env.set_paludis_command("/bin/false");
+ std::tr1::shared_ptr<Map<std::string, std::string> > keys(new Map<std::string, std::string>);
+ keys->insert("format", "ebuild");
+ keys->insert("names_cache", "/var/empty");
+ keys->insert("location", "ebuild_flat_metadata_cache_TEST_dir/repo");
+ keys->insert("profiles", "ebuild_flat_metadata_cache_TEST_dir/repo/profiles/profile");
+ keys->insert("eclassdirs", "ebuild_flat_metadata_cache_TEST_dir/repo/eclass ebuild_flat_metadata_cache_TEST_dir/extra_eclasses");
+ std::tr1::shared_ptr<Repository> repo(ERepository::repository_factory_create(&env,
+ std::tr1::bind(from_keys, keys, std::tr1::placeholders::_1)));
+ env.package_database()->add_repository(1, repo);
+
+ const std::tr1::shared_ptr<const PackageID> id1(*env[selection::RequireExactlyOne(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec("=cat/flat_hash-bad-mtime-1",
+ &env, UserPackageDepSpecOptions()))))]->begin());
+
+ TEST_CHECK(id1->short_description_key());
+ TEST_CHECK_EQUAL(id1->short_description_key()->value(), "The Generated Description flat_hash-bad-mtime");
+ }
+ } test_metadata_flat_hash_bad_mtime;
+
struct MetadataFlatHashNoEAPITest : TestCase
{
MetadataFlatHashNoEAPITest() : TestCase("metadata flat_hash no EAPI") { }
@@ -1017,6 +1071,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_metadata_write;
@@ -1051,6 +1106,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_metadata_write_eclasses;
@@ -1086,6 +1142,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_metadata_write_exlibs;
}
diff --git a/paludis/repositories/e/ebuild_flat_metadata_cache_TEST_setup.sh b/paludis/repositories/e/ebuild_flat_metadata_cache_TEST_setup.sh
index 352bb73..5199114 100755
--- a/paludis/repositories/e/ebuild_flat_metadata_cache_TEST_setup.sh
+++ b/paludis/repositories/e/ebuild_flat_metadata_cache_TEST_setup.sh
@@ -285,7 +285,28 @@ END
mkdir cat/flat_hash-no-mtime
cat <<END > cat/flat_hash-no-mtime/flat_hash-no-mtime-1.ebuild || exit 1
-DESCRIPTION="The Generated Description flat_hash-no-mtime"
+END
+cat <<END > metadata/cache/cat/flat_hash-no-mtime-1 || exit 1
+DEPEND=the/depend
+RDEPEND=the/rdepend
+SLOT=the-slot
+SRC_URI=the-src-uri
+RESTRICT=the-restrict
+HOMEPAGE=the-homepage
+LICENSE=the-license
+DESCRIPTION=the-description-flat_hash-no-mtime
+KEYWORDS=the-keywords
+IUSE=the-iuse
+PDEPEND=the/pdepend
+PROVIDE=the/provide
+EAPI=0
+END
+TZ=UTC touch -t 197001010001 cat/flat_hash-no-mtime/flat_hash-no-mtime-1.ebuild || exit 2
+TZ=UTC touch -t 197001010001 metadata/cache/cat/flat_hash-no-mtime-1 || exit 2
+
+mkdir cat/flat_hash-no-mtime-stale
+cat <<END > cat/flat_hash-no-mtime-stale/flat_hash-no-mtime-stale-1.ebuild || exit 1
+DESCRIPTION="The Generated Description flat_hash-no-mtime-stale"
HOMEPAGE="http://example.com/"
SRC_URI=""
SLOT="0"
@@ -294,7 +315,36 @@ LICENSE="GPL-2"
KEYWORDS="test"
DEPEND=""
END
-cat <<END > metadata/cache/cat/flat_hash-no-mtime-1 || exit 1
+cat <<END > metadata/cache/cat/flat_hash-no-mtime-stale-1 || exit 1
+DEPEND=the/depend
+RDEPEND=the/rdepend
+SLOT=the-slot
+SRC_URI=the-src-uri
+RESTRICT=the-restrict
+HOMEPAGE=the-homepage
+LICENSE=the-license
+DESCRIPTION=The Stale Description
+KEYWORDS=the-keywords
+IUSE=the-iuse
+PDEPEND=the/pdepend
+PROVIDE=the/provide
+EAPI=0
+END
+TZ=UTC touch -t 197001010001 metadata/cache/cat/flat_hash-no-mtime-stale-1 || exit 2
+
+mkdir cat/flat_hash-bad-mtime
+cat <<END > cat/flat_hash-bad-mtime/flat_hash-bad-mtime-1.ebuild || exit 1
+DESCRIPTION="The Generated Description flat_hash-bad-mtime"
+HOMEPAGE="http://example.com/"
+SRC_URI=""
+SLOT="0"
+IUSE=""
+LICENSE="GPL-2"
+KEYWORDS="test"
+DEPEND=""
+END
+cat <<END > metadata/cache/cat/flat_hash-bad-mtime-1 || exit 1
+_mtime_=monkey
DEPEND=the/depend
RDEPEND=the/rdepend
SLOT=the-slot
@@ -309,6 +359,8 @@ PDEPEND=the/pdepend
PROVIDE=the/provide
EAPI=0
END
+TZ=UTC touch -t 197001010001 cat/flat_hash-bad-mtime/flat_hash-bad-mtime-1 || exit 2
+TZ=UTC touch -t 197001010001 metadata/cache/cat/flat_hash-bad-mtime-1 || exit 2
mkdir cat/flat_hash-no-eapi
cat <<END > cat/flat_hash-no-eapi/flat_hash-no-eapi-1.ebuild || exit 1