aboutsummaryrefslogtreecommitdiff
path: root/paludis/environment_implementation.cc
blob: 8718ff8cbba551694cde7c179c5a73fe6fe27a88 (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2005, 2006, 2007 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 <paludis/environment_implementation.hh>
#include <paludis/package_id.hh>
#include <paludis/metadata_key.hh>
#include <paludis/package_database.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/log.hh>
#include <paludis/util/save.hh>
#include <paludis/util/set.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/system.hh>
#include <paludis/hook.hh>
#include <paludis/distribution.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>
#include <libwrapiter/libwrapiter_output_iterator.hh>
#include <algorithm>
#include "config.h"

using namespace paludis;

EnvironmentImplementation::~EnvironmentImplementation()
{
}


tr1::shared_ptr<const FSEntrySequence>
EnvironmentImplementation::bashrc_files() const
{
    return make_shared_ptr(new FSEntrySequence);
}

tr1::shared_ptr<const FSEntrySequence>
EnvironmentImplementation::syncers_dirs() const
{
    tr1::shared_ptr<FSEntrySequence> result(new FSEntrySequence);
    result->push_back(FSEntry(DATADIR "/paludis/syncers"));
    result->push_back(FSEntry(LIBEXECDIR "/paludis/syncers"));
    return result;
}

tr1::shared_ptr<const FSEntrySequence>
EnvironmentImplementation::fetchers_dirs() const
{
    tr1::shared_ptr<FSEntrySequence> result(new FSEntrySequence);
    std::string fetchers_dir(getenv_with_default("PALUDIS_FETCHERS_DIR", ""));
    if (fetchers_dir.empty())
    {
        result->push_back(FSEntry(DATADIR "/paludis/fetchers"));
        result->push_back(FSEntry(LIBEXECDIR "/paludis/fetchers"));
    }
    else
        result->push_back(FSEntry(fetchers_dir));
    return result;
}

tr1::shared_ptr<const DestinationsSet>
EnvironmentImplementation::default_destinations() const
{
    tr1::shared_ptr<DestinationsSet> result(new DestinationsSet);

    for (PackageDatabase::RepositoryIterator r(package_database()->begin_repositories()),
            r_end(package_database()->end_repositories()) ;
            r != r_end ; ++r)
        if ((*r)->destination_interface)
            if ((*r)->destination_interface->is_default_destination())
                result->insert(*r);

    return result;
}

tr1::shared_ptr<SetSpecTree::ConstItem>
EnvironmentImplementation::set(const SetName & s) const
{
    {
        tr1::shared_ptr<SetSpecTree::ConstItem> l(local_set(s));
        if (l)
        {
            Log::get_instance()->message(ll_debug, lc_context) << "Set '" << s << "' is a local set";
            return l;
        }
    }

    tr1::shared_ptr<ConstTreeSequence<SetSpecTree, AllDepSpec> > result;

    /* these sets always exist, even if empty */
    if (s.data() == "everything" || s.data() == "system" || s.data() == "world" || s.data() == "security")
    {
        Log::get_instance()->message(ll_debug, lc_context) << "Set '" << s << "' is a standard set";
        result.reset(new ConstTreeSequence<SetSpecTree, AllDepSpec>(tr1::shared_ptr<AllDepSpec>(new AllDepSpec)));
    }

    for (PackageDatabase::RepositoryIterator r(package_database()->begin_repositories()),
            r_end(package_database()->end_repositories()) ;
            r != r_end ; ++r)
    {
        if (! (*r)->sets_interface)
            continue;

        tr1::shared_ptr<SetSpecTree::ConstItem> add((*r)->sets_interface->package_set(s));
        if (add)
        {
            Log::get_instance()->message(ll_debug, lc_context) << "Set '" << s << "' found in '" << (*r)->name() << "'";
            if (! result)
                result.reset(new ConstTreeSequence<SetSpecTree, AllDepSpec>(tr1::shared_ptr<AllDepSpec>(new AllDepSpec)));
            result->add(add);
        }

        if ("everything" == s.data() || "world" == s.data())
        {
            add = (*r)->sets_interface->package_set(SetName("system"));
            if (add)
                result->add(add);
        }
    }

    if (! result)
        Log::get_instance()->message(ll_debug, lc_context) << "No match for set '" << s << "'";
    return result;
}

bool
EnvironmentImplementation::query_use(const UseFlagName & f, const PackageID & e) const
{
    if (e.repository()->use_interface)
    {
        if (e.repository()->use_interface->query_use_mask(f, e))
            return false;
        if (e.repository()->use_interface->query_use_force(f, e))
            return true;

        switch (e.repository()->use_interface->query_use(f, e))
        {
            case use_disabled:
            case use_unspecified:
                return false;

            case use_enabled:
                return true;

            case last_use:
                ;
        }

        throw InternalError(PALUDIS_HERE, "bad state");
    }
    else
        return false;
}

std::string
EnvironmentImplementation::default_distribution() const
{
    static const std::string result(getenv_with_default("PALUDIS_DISTRIBUTION", DEFAULT_DISTRIBUTION));
    return result;
}

tr1::shared_ptr<const SetNameSet>
EnvironmentImplementation::set_names() const
{
    return make_shared_ptr(new SetNameSet);
}

bool
EnvironmentImplementation::is_paludis_package(const QualifiedPackageName & n) const
{
    return stringify(n) == DistributionData::get_instance()->distribution_from_string(default_distribution())->paludis_package;
}