aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-04-27 22:24:32 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-04-27 22:24:32 +0100
commitc3e8cf81afbed97fddb6d653b1c5c608a34713eb (patch)
tree845f6f68e37ff52ceed2027d920874ea601aa9cb
parentdd166c6563ad44ad6b75c0fcb13d13789580ca15 (diff)
downloadpaludis-c3e8cf81afbed97fddb6d653b1c5c608a34713eb.tar.gz
paludis-c3e8cf81afbed97fddb6d653b1c5c608a34713eb.tar.xz
Only invalidate expired write cache entries
-rw-r--r--hooks/Makefile.am.m46
-rwxr-xr-xhooks/write_cache_clean.bash41
-rw-r--r--paludis/repositories/e/e_installed_repository_id.cc5
-rw-r--r--paludis/repositories/e/e_installed_repository_id.hh2
-rw-r--r--paludis/repositories/e/e_repository.cc66
-rw-r--r--paludis/repositories/e/e_repository.hh2
-rw-r--r--paludis/repositories/e/e_repository_id.hh4
-rw-r--r--paludis/repositories/e/ebuild_entries.cc2
-rw-r--r--paludis/repositories/e/ebuild_flat_metadata_cache.cc7
-rw-r--r--paludis/repositories/e/ebuild_flat_metadata_cache.hh4
-rw-r--r--paludis/repositories/e/ebuild_id.cc25
-rw-r--r--paludis/repositories/e/ebuild_id.hh2
-rw-r--r--paludis/repository.cc5
-rw-r--r--paludis/repository.hh5
-rw-r--r--paludis/sync_task.cc7
-rw-r--r--src/clients/cave/cmd_sync.cc7
16 files changed, 136 insertions, 54 deletions
diff --git a/hooks/Makefile.am.m4 b/hooks/Makefile.am.m4
index b9eefb7..772078d 100644
--- a/hooks/Makefile.am.m4
+++ b/hooks/Makefile.am.m4
@@ -18,8 +18,7 @@ installhookcommonprog_SCRIPTS = \
eselect_env_update.bash \
log.bash \
installable_cache_regen.bash \
- installed_cache_regen.bash \
- write_cache_clean.bash
+ installed_cache_regen.bash
installhookautoprog_SCRIPTS = \
news.hook \
@@ -48,7 +47,6 @@ EXTRA_DIST = \
log.bash \
installable_cache_regen.bash \
installed_cache_regen.bash \
- write_cache_clean.bash \
news.hook.in \
find_config_updates.hook \
$(installhookinstallpost_SCRIPTS) \
@@ -260,7 +258,6 @@ install-data-local :
ln -sf ../common/log.bash $(DESTDIR)/$(libexecdir)/paludis/hooks/sync_pre/
ln -sf ../common/log.bash $(DESTDIR)/$(libexecdir)/paludis/hooks/sync_post/
ln -sf ../common/installable_cache_regen.bash $(DESTDIR)/$(libexecdir)/paludis/hooks/sync_all_post/
- ln -sf ../common/write_cache_clean.bash $(DESTDIR)/$(libexecdir)/paludis/hooks/sync_all_post/
ln -sf ../common/installed_cache_regen.bash $(DESTDIR)/$(libexecdir)/paludis/hooks/install_post/
ln -sf ../common/installed_cache_regen.bash $(DESTDIR)/$(libexecdir)/paludis/hooks/uninstall_post/
ln -sf ../common/installed_cache_regen.bash $(DESTDIR)/$(libexecdir)/paludis/hooks/clean_post/
@@ -269,7 +266,6 @@ uninstall-local :
rm -f $(DESTDIR)/$(libexecdir)/paludis/hooks/*/gnu_info_index.bash
rm -f $(DESTDIR)/$(libexecdir)/paludis/hooks/*/eselect_env_update.bash
rm -f $(DESTDIR)/$(libexecdir)/paludis/hooks/*/log.bash
- rm -f $(DESTDIR)/$(libexecdir)/paludis/hooks/*/write_cache_clean.bash
Makefile.am : Makefile.am.m4
$(top_srcdir)/misc/do_m4.bash Makefile.am
diff --git a/hooks/write_cache_clean.bash b/hooks/write_cache_clean.bash
deleted file mode 100755
index ab02e86..0000000
--- a/hooks/write_cache_clean.bash
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/env bash
-# vim: set et sw=4 sts=4 :
-
-# Copyright (c) 2007, 2008 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
-
-export PATH="$(${PALUDIS_EBUILD_DIR}/utils/canonicalise ${PALUDIS_EBUILD_DIR}/utils/ ):${PATH}"
-source ${PALUDIS_ECHO_FUNCTIONS_DIR:-${PALUDIS_EBUILD_DIR}}/echo_functions.bash
-
-[[ -n "${PALUDIS_NO_WRITE_CACHE_CLEAN}" ]] && exit 0
-
-echo
-einfo_unhooked "Cleaning write cache for ebuild format repositories..."
-
-while read repo ; do
- wcloc=$(${PALUDIS_COMMAND} --configuration-variable ${repo} write_cache )
-
- [[ $(canonicalise ${wcloc} ) == "/var/empty" ]] && continue
- wcloc="${wcloc}/${repo}"
-
- [[ $(echo "${wcloc}"/* ) != "${wcloc}/*" ]] || continue
- echo rm -fr "${wcloc}/*"
- rm -fr "${wcloc}"/* || eerror "Couldn't clear cache for ${repo} at ${wcloc}"
-
-done < <(${PALUDIS_COMMAND} --list-repositories --repository-format ebuild | \
- sed -n -e '/^\*/s,^\*\s*,,p' )
-
-einfo_unhooked "Done cleaning write cache for ebuild format repositories"
-
diff --git a/paludis/repositories/e/e_installed_repository_id.cc b/paludis/repositories/e/e_installed_repository_id.cc
index 7ccb910..a653e48 100644
--- a/paludis/repositories/e/e_installed_repository_id.cc
+++ b/paludis/repositories/e/e_installed_repository_id.cc
@@ -1001,3 +1001,8 @@ EInstalledRepositoryID::add_build_options(const std::tr1::shared_ptr<Choices> &)
{
}
+void
+EInstalledRepositoryID::purge_invalid_cache() const
+{
+}
+
diff --git a/paludis/repositories/e/e_installed_repository_id.hh b/paludis/repositories/e/e_installed_repository_id.hh
index d7f8880..cb5f3b7 100644
--- a/paludis/repositories/e/e_installed_repository_id.hh
+++ b/paludis/repositories/e/e_installed_repository_id.hh
@@ -110,6 +110,8 @@ namespace paludis
const bool, const std::string &, const bool) const;
virtual void add_build_options(const std::tr1::shared_ptr<Choices> &) const;
+
+ virtual void purge_invalid_cache() const;
};
}
}
diff --git a/paludis/repositories/e/e_repository.cc b/paludis/repositories/e/e_repository.cc
index 60ed666..6f42b9e 100644
--- a/paludis/repositories/e/e_repository.cc
+++ b/paludis/repositories/e/e_repository.cc
@@ -31,6 +31,7 @@
#include <paludis/repositories/e/e_repository_exceptions.hh>
#include <paludis/repositories/e/e_repository_entries.hh>
#include <paludis/repositories/e/eapi.hh>
+#include <paludis/repositories/e/eclass_mtimes.hh>
#include <paludis/repositories/e/extra_distribution_data.hh>
#include <paludis/repositories/e/use_desc.hh>
#include <paludis/repositories/e/layout.hh>
@@ -802,6 +803,71 @@ ERepository::invalidate()
}
void
+ERepository::purge_invalid_cache() const
+{
+ Context context("When purging invalid write_cache:");
+
+ FSEntry write_cache(_imp->params.write_cache());
+ if (write_cache == FSEntry("/var/empty") || ! write_cache.is_directory_or_symlink_to_directory())
+ return;
+
+ if (_imp->params.append_repository_name_to_write_cache())
+ write_cache /= stringify(name());
+
+ const std::tr1::shared_ptr<const EAPI> eapi(EAPIData::get_instance()->eapi_from_string(
+ _imp->params.eapi_when_unknown()));
+
+ std::tr1::shared_ptr<EclassMtimes> eclass_mtimes(new EclassMtimes(this, _imp->params.eclassdirs()));
+ 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();
+
+ for (DirIterator dc(write_cache, DirIteratorOptions() + dio_inode_sort), dc_end ; dc != dc_end ; ++dc)
+ {
+ if (! dc->is_directory_or_symlink_to_directory())
+ continue;
+
+ for (DirIterator dp(*dc, DirIteratorOptions() + dio_inode_sort), dp_end ; dp != dp_end ; ++dp)
+ {
+ if (! dp->is_regular_file_or_symlink_to_regular_file())
+ continue;
+
+ try
+ {
+ CategoryNamePart cnp(dc->basename());
+ std::string pv(dp->basename());
+ VersionSpec v(elike_get_remove_trailing_version(pv, eapi->supported()->version_spec_options()));
+ PackageNamePart p(pv);
+
+ std::tr1::shared_ptr<const PackageIDSequence> ids(_imp->layout->package_ids(cnp + p));
+ bool found(false);
+ for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ;
+ i != i_end ; ++i)
+ {
+ /* 00 is *not* equal to 0 here */
+ if (stringify((*i)->version()) != stringify(v))
+ continue;
+
+ std::tr1::static_pointer_cast<const ERepositoryID>(*i)->purge_invalid_cache();
+
+ found = true;
+ break;
+ }
+
+ if (! found)
+ FSEntry(*dp).unlink();
+ }
+ catch (const Exception & e)
+ {
+ Log::get_instance()->message("e.ebuild.purge_write_cache.ignoring", ll_warning, lc_context)
+ << "Ignoring exception '" << e.message() << "' (" << e.what() << ") when purging invalid write_cache entries";
+ }
+ }
+ }
+}
+
+void
ERepository::invalidate_masks()
{
_imp->layout->invalidate_masks();
diff --git a/paludis/repositories/e/e_repository.hh b/paludis/repositories/e/e_repository.hh
index 3d81f92..5977a2b 100644
--- a/paludis/repositories/e/e_repository.hh
+++ b/paludis/repositories/e/e_repository.hh
@@ -88,6 +88,8 @@ namespace paludis
virtual void invalidate_masks();
+ virtual void purge_invalid_cache() const;
+
/* RepositoryMirrorsInterface */
virtual MirrorsConstIterator begin_mirrors(const std::string & s) const
diff --git a/paludis/repositories/e/e_repository_id.hh b/paludis/repositories/e/e_repository_id.hh
index fa15212..b755fe5 100644
--- a/paludis/repositories/e/e_repository_id.hh
+++ b/paludis/repositories/e/e_repository_id.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 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
@@ -52,6 +52,8 @@ namespace paludis
const PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
virtual void add_build_options(const std::tr1::shared_ptr<Choices> &) const = 0;
+
+ virtual void purge_invalid_cache() const = 0;
};
}
}
diff --git a/paludis/repositories/e/ebuild_entries.cc b/paludis/repositories/e/ebuild_entries.cc
index eb100a9..5a28504 100644
--- a/paludis/repositories/e/ebuild_entries.cc
+++ b/paludis/repositories/e/ebuild_entries.cc
@@ -56,6 +56,8 @@
#include <paludis/util/instantiation_policy-impl.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/make_named_values.hh>
+#include <paludis/util/dir_iterator.hh>
+#include <paludis/util/options.hh>
#include <paludis/output_manager.hh>
#include <tr1/functional>
#include <list>
diff --git a/paludis/repositories/e/ebuild_flat_metadata_cache.cc b/paludis/repositories/e/ebuild_flat_metadata_cache.cc
index c3b1940..48398d9 100644
--- a/paludis/repositories/e/ebuild_flat_metadata_cache.cc
+++ b/paludis/repositories/e/ebuild_flat_metadata_cache.cc
@@ -296,7 +296,7 @@ EbuildFlatMetadataCache::~EbuildFlatMetadataCache()
}
bool
-EbuildFlatMetadataCache::load(const std::tr1::shared_ptr<const EbuildID> & id)
+EbuildFlatMetadataCache::load(const std::tr1::shared_ptr<const EbuildID> & id, const bool silent_on_stale)
{
using namespace std::tr1::placeholders;
@@ -495,8 +495,9 @@ EbuildFlatMetadataCache::load(const std::tr1::shared_ptr<const EbuildID> & id)
if (! ok)
{
- Log::get_instance()->message("e.cache.stale", ll_warning, lc_no_context)
- << "Stale cache file at '" << _imp->filename << "'";
+ if (! silent_on_stale)
+ Log::get_instance()->message("e.cache.stale", ll_warning, lc_no_context)
+ << "Stale cache file at '" << _imp->filename << "'";
return false;
}
}
diff --git a/paludis/repositories/e/ebuild_flat_metadata_cache.hh b/paludis/repositories/e/ebuild_flat_metadata_cache.hh
index 629cb59..7fb1a2f 100644
--- a/paludis/repositories/e/ebuild_flat_metadata_cache.hh
+++ b/paludis/repositories/e/ebuild_flat_metadata_cache.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2006, 2007, 2008, 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
@@ -55,7 +55,7 @@ namespace paludis
///\name Cache operations
///\{
- bool load(const std::tr1::shared_ptr<const EbuildID> &);
+ bool load(const std::tr1::shared_ptr<const EbuildID> &, const bool silent_on_stale);
void save(const std::tr1::shared_ptr<const EbuildID> &);
///\}
diff --git a/paludis/repositories/e/ebuild_id.cc b/paludis/repositories/e/ebuild_id.cc
index e77773c..1d73f4e 100644
--- a/paludis/repositories/e/ebuild_id.cc
+++ b/paludis/repositories/e/ebuild_id.cc
@@ -193,7 +193,7 @@ EbuildID::need_keys_added() const
if (_imp->repository->params().cache().basename() != "empty")
{
EbuildFlatMetadataCache metadata_cache(_imp->environment, cache_file, _imp->ebuild, _imp->master_mtime, _imp->eclass_mtimes, false);
- if (metadata_cache.load(shared_from_this()))
+ if (metadata_cache.load(shared_from_this(), false))
ok = true;
}
@@ -201,7 +201,7 @@ EbuildID::need_keys_added() const
{
EbuildFlatMetadataCache write_metadata_cache(_imp->environment,
write_cache_file, _imp->ebuild, _imp->master_mtime, _imp->eclass_mtimes, true);
- if (write_metadata_cache.load(shared_from_this()))
+ if (write_metadata_cache.load(shared_from_this(), false))
ok = true;
else if (write_cache_file.exists())
{
@@ -1366,3 +1366,24 @@ EbuildID::add_build_options(const std::tr1::shared_ptr<Choices> & choices) const
}
}
+void
+EbuildID::purge_invalid_cache() const
+{
+ FSEntry write_cache_file(_imp->repository->params().write_cache());
+ if (_imp->repository->params().append_repository_name_to_write_cache())
+ write_cache_file /= stringify(repository()->name());
+ write_cache_file /= stringify(name().category());
+ write_cache_file /= stringify(name().package()) + "-" + stringify(version());
+
+ if (write_cache_file.exists())
+ {
+ if (_imp->repository->params().write_cache().basename() != "empty")
+ {
+ EbuildFlatMetadataCache write_metadata_cache(_imp->environment,
+ write_cache_file, _imp->ebuild, _imp->master_mtime, _imp->eclass_mtimes, true);
+ if (! write_metadata_cache.load(shared_from_this(), true))
+ write_cache_file.unlink();
+ }
+ }
+}
+
diff --git a/paludis/repositories/e/ebuild_id.hh b/paludis/repositories/e/ebuild_id.hh
index bef876a..e7284cb 100644
--- a/paludis/repositories/e/ebuild_id.hh
+++ b/paludis/repositories/e/ebuild_id.hh
@@ -156,6 +156,8 @@ namespace paludis
const bool, const std::string &, const bool) const;
virtual void add_build_options(const std::tr1::shared_ptr<Choices> &) const;
+
+ virtual void purge_invalid_cache() const;
};
}
}
diff --git a/paludis/repository.cc b/paludis/repository.cc
index ba1d1e9..671907c 100644
--- a/paludis/repository.cc
+++ b/paludis/repository.cc
@@ -180,6 +180,11 @@ Repository::regenerate_cache() const
{
}
+void
+Repository::purge_invalid_cache() const
+{
+}
+
RepositorySetsInterface::~RepositorySetsInterface()
{
}
diff --git a/paludis/repository.hh b/paludis/repository.hh
index 7068a74..f415676 100644
--- a/paludis/repository.hh
+++ b/paludis/repository.hh
@@ -391,6 +391,11 @@ namespace paludis
*/
virtual void regenerate_cache() const;
+ /**
+ * Purge any invalid on-disk cache entries.
+ */
+ virtual void purge_invalid_cache() const;
+
///\}
};
diff --git a/paludis/sync_task.cc b/paludis/sync_task.cc
index a08177d..cfbcf12 100644
--- a/paludis/sync_task.cc
+++ b/paludis/sync_task.cc
@@ -189,6 +189,13 @@ SyncTask::execute()
else
std::for_each(_imp->targets.begin(), _imp->targets.end(), std::tr1::bind(&ItemSyncer::sync, &s, _1));
+ for (PackageDatabase::RepositoryConstIterator r(_imp->env->package_database()->begin_repositories()),
+ r_end(_imp->env->package_database()->end_repositories()) ; r != r_end ; ++r)
+ {
+ (*r)->invalidate();
+ (*r)->purge_invalid_cache();
+ }
+
on_sync_all_post();
if (0 !=
_imp->env->perform_hook(Hook("sync_all_post")("TARGETS", join(_imp->targets.begin(),
diff --git a/src/clients/cave/cmd_sync.cc b/src/clients/cave/cmd_sync.cc
index e84bba1..71b2f1e 100644
--- a/src/clients/cave/cmd_sync.cc
+++ b/src/clients/cave/cmd_sync.cc
@@ -349,6 +349,13 @@ SyncCommand::run(
std::tr1::ref(active), std::tr1::ref(done)));
}
+ for (PackageDatabase::RepositoryConstIterator r(env->package_database()->begin_repositories()),
+ r_end(env->package_database()->end_repositories()) ; r != r_end ; ++r)
+ {
+ (*r)->invalidate();
+ (*r)->purge_invalid_cache();
+ }
+
if (0 != env->perform_hook(Hook("sync_all_post")
("TARGETS", join(repos.begin(), repos.end(), " ")
)).max_exit_status())