diff options
Diffstat (limited to '0.8.0/paludis/tasks/sync_task.cc')
-rw-r--r-- | 0.8.0/paludis/tasks/sync_task.cc | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/0.8.0/paludis/tasks/sync_task.cc b/0.8.0/paludis/tasks/sync_task.cc new file mode 100644 index 000000000..f3f0a9586 --- /dev/null +++ b/0.8.0/paludis/tasks/sync_task.cc @@ -0,0 +1,104 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org> + * + * 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 "sync_task.hh" +#include <paludis/environment.hh> +#include <paludis/syncer.hh> +#include <list> + +using namespace paludis; + +namespace paludis +{ + template<> + struct Implementation<SyncTask> : + InternalCounted<Implementation<SyncTask> > + { + Environment * const env; + std::list<RepositoryName> targets; + + Implementation(Environment * const e) : + env(e) + { + } + }; +} + +SyncTask::SyncTask(Environment * const env) : + PrivateImplementationPattern<SyncTask>(new Implementation<SyncTask>(env)) +{ +} + +SyncTask::~SyncTask() +{ +} + +void +SyncTask::add_target(const std::string & t) +{ + Context context("When adding sync target '" + t + "':"); + _imp->targets.push_back(RepositoryName(t)); +} + +void +SyncTask::execute() +{ + Context context("When executing sync task:"); + + if (_imp->targets.empty()) + for (PackageDatabase::RepositoryIterator r(_imp->env->package_database()->begin_repositories()), + r_end(_imp->env->package_database()->end_repositories()) ; r != r_end ; ++r) + _imp->targets.push_back((*r)->name()); + + _imp->env->perform_hook(Hook("sync_all_pre")("TARGETS", join(_imp->targets.begin(), + _imp->targets.end(), " "))); + on_sync_all_pre(); + + for (std::list<RepositoryName>::const_iterator r(_imp->targets.begin()), r_end(_imp->targets.end()) ; + r != r_end ; ++r) + { + Context context_local("When syncing repository '" + stringify(*r) + "':"); + + _imp->env->perform_hook(Hook("sync_pre")("TARGET", stringify(*r))); + on_sync_pre(*r); + + try + { + Repository::ConstPointer rr(_imp->env->package_database()->fetch_repository(*r)); + + if (rr->syncable_interface && rr->syncable_interface->sync()) + on_sync_succeed(*r); + else + on_sync_skip(*r); + } + catch (const SyncFailedError & e) + { + _imp->env->perform_hook(Hook("sync_fail")("TARGET", stringify(*r))); + on_sync_fail(*r, e); + } + + on_sync_post(*r); + _imp->env->perform_hook(Hook("sync_post")("TARGET", stringify(*r))); + } + + on_sync_all_post(); + _imp->env->perform_hook(Hook("sync_all_post")("TARGETS", join(_imp->targets.begin(), + _imp->targets.end(), " "))); +} + |