aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/e/exndbam_id.cc
blob: b78ba5c329634be50e8b3f03862d8a2c8fdac8d9 (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
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 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
 */

#include <paludis/repositories/e/exndbam_id.hh>
#include <paludis/util/mutex.hh>
#include <paludis/util/tr1_functional.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/contents.hh>
#include <paludis/ndbam.hh>

using namespace paludis;
using namespace paludis::erepository;

namespace
{
    void create_file(Contents & c, const FSEntry & f)
    {
        c.add(make_shared_ptr(new ContentsFileEntry(stringify(f))));
    }

    void create_dir(Contents & c, const FSEntry & f)
    {
        c.add(make_shared_ptr(new ContentsDirEntry(stringify(f))));
    }

    void create_sym(Contents & c, const FSEntry & f, const FSEntry & t)
    {
        c.add(make_shared_ptr(new ContentsSymEntry(stringify(f), stringify(t))));
    }

    class ExndbamContentsKey :
        public MetadataValueKey<tr1::shared_ptr<const Contents> > 
    {
        private:
            const PackageID * const _id;
            const NDBAM * const _db;
            mutable Mutex _mutex;
            mutable tr1::shared_ptr<Contents> _v;

        public:
            ExndbamContentsKey(const PackageID * const i, const NDBAM * const d) :
                MetadataValueKey<tr1::shared_ptr<const Contents> > ("contents", "Contents", mkt_internal),
                _id(i),
                _db(d)
            {
            }

            const tr1::shared_ptr<const Contents> value() const
            {
                Lock l(_mutex);
                if (_v)
                    return _v;

                using namespace tr1::placeholders;
                _v.reset(new Contents);
                _db->parse_contents(*_id,
                        tr1::bind(&create_file, tr1::ref(*_v), _1),
                        tr1::bind(&create_dir, tr1::ref(*_v), _1),
                        tr1::bind(&create_sym, tr1::ref(*_v), _1, _2)
                        );
                return _v;
            }
    };
}

ExndbamID::ExndbamID(const QualifiedPackageName & q, const VersionSpec & v,
        const Environment * const e,
        const tr1::shared_ptr<const Repository> & r,
        const FSEntry & f, const NDBAM * const n) :
    EInstalledRepositoryID(q, v, e, r, f),
    _ndbam(n)
{
}

std::string
ExndbamID::fs_location_raw_name() const
{
    return "EXNDBAMDIR";
}

std::string
ExndbamID::fs_location_human_name() const
{
    return "Exndbam Directory";
}

std::string
ExndbamID::contents_filename() const
{
    return "contents";
}

tr1::shared_ptr<MetadataValueKey<tr1::shared_ptr<const Contents> > >
ExndbamID::make_contents_key() const
{
    return make_shared_ptr(new ExndbamContentsKey(this, _ndbam));
}