1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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(), " ")));
}
|