aboutsummaryrefslogtreecommitdiff
path: root/paludis/legacy/uninstall_list.hh
blob: f2add28fa0d5ba62e487a44ddc0d5f939f7f527c (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
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011 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
 */

#ifndef PALUDIS_GUARD_PALUDIS_UNUSED_LIST_HH
#define PALUDIS_GUARD_PALUDIS_UNUSED_LIST_HH 1

#include <paludis/util/pimp.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/named_value.hh>
#include <paludis/package_id-fwd.hh>
#include <paludis/dep_tag-fwd.hh>

/** \file
 * Declarations for UninstallList and related classes.
 *
 * \ingroup g_dep_list
 *
 * \section Examples
 *
 * - None at this time. Use UninstallTask if you need to uninstall things.
 */

namespace paludis
{
#include <paludis/legacy/uninstall_list-se.hh>

    namespace n
    {
        typedef Name<struct name_kind> kind;
        typedef Name<struct name_package_id> package_id;
        typedef Name<struct name_tags> tags;
        typedef Name<struct name_with_dependencies_as_errors> with_dependencies_as_errors;
        typedef Name<struct name_with_dependencies_included> with_dependencies_included;
        typedef Name<struct name_with_unused_dependencies> with_unused_dependencies;
    }

    /**
     * Parameters for an UninstallList.
     *
     * \see UninstallList
     * \ingroup g_dep_list
     * \nosubgrouping
     */
    struct UninstallListOptions
    {
        NamedValue<n::with_dependencies_as_errors, bool> with_dependencies_as_errors;
        NamedValue<n::with_dependencies_included, bool> with_dependencies_included;
        NamedValue<n::with_unused_dependencies, bool> with_unused_dependencies;
    };

    /**
     * An entry in an UninstallList.
     *
     * \see UninstallList
     * \ingroup g_dep_list
     * \nosubgrouping
     */
    struct UninstallListEntry
    {
        NamedValue<n::kind, UninstallListEntryKind> kind;
        NamedValue<n::package_id, std::shared_ptr<const PackageID> > package_id;
        NamedValue<n::tags, std::shared_ptr<Set<std::shared_ptr<DepTag> > > > tags;
    };

    class Environment;

    /**
     * Work out uninstall ordering for packages.
     *
     * \ingroup g_dep_list
     * \nosubgrouping
     */
    class PALUDIS_VISIBLE UninstallList
    {
        private:
            Pimp<UninstallList> _imp;

            void add_package(const std::shared_ptr<const PackageID> &, const std::shared_ptr<DepTag> &,
                    const UninstallListEntryKind k);
            void real_add(const std::shared_ptr<const PackageID> &,
                    const std::shared_ptr<DepTag> &, const bool);
            void move_package_to_end(const std::shared_ptr<const PackageID> &);
            void add_unused_dependencies();
            void add_dependencies(const PackageID &, const bool);

            std::shared_ptr<const PackageIDSet> collect_depped_upon(
                    const std::shared_ptr<const PackageIDSet> targets) const;

            std::shared_ptr<const PackageIDSet> collect_all_installed() const;

            std::shared_ptr<const PackageIDSet> collect_world() const;

            std::shared_ptr<const PackageIDSet> collect_used() const;

        public:
            ///\name Basic operations
            ///\{

            UninstallList(const Environment * const, const UninstallListOptions &);
            virtual ~UninstallList();

            UninstallList(const UninstallList &) = delete;
            UninstallList & operator= (const UninstallList &) = delete;

            ///\}

            /**
             * Our options.
             */
            UninstallListOptions & options;

            /**
             * Add a package, optionally with a reason.
             */
            void add(const std::shared_ptr<const PackageID> &,
                    const std::shared_ptr<DepTag> & = std::shared_ptr<DepTag>());

            /**
             * Add errors for any package on our uninstall list that is required by system.
             */
            void add_errors_for_system();

            /**
             * Add any unused packages that are dependencies of packages to uninstall.
             */
            void add_unused();

            /**
             * Whether we have any errors.
             */
            bool has_errors() const;

            ///\name Iterate over our items to remove
            ///\{

            struct UninstallListTag;
            typedef WrappedForwardIterator<UninstallListTag, const UninstallListEntry> ConstIterator;
            ConstIterator begin() const;
            ConstIterator end() const;

            ///\}
    };

    extern template class WrappedForwardIterator<UninstallList::UninstallListTag, const UninstallListEntry>;
}

#endif