Debian Codegraph @

apt-pkg-c/depcache.h

raw symbols SCIP
1 #pragma once
2 #include <apt-pkg/cachefile.h>
3 #include <apt-pkg/upgrade.h>
4 #include <memory>
5 #include "package.h"
6 #include "util.h"
7
8 #include "progress.h"
9
10 using ActionGroup = pkgDepCache::ActionGroup;
11
12 struct PkgDepCache {
13 pkgDepCache* ptr;
14
15 // Maybe we use this if we don't want pin_mut() all over the place in Rust.
16 PkgDepCache* unconst() const { return const_cast<PkgDepCache*>(this); }
17
18 UniquePtr<ActionGroup> action_group() const { return std::make_unique<ActionGroup>(*ptr); }
19
20 bool is_upgradable(const PkgIterator& pkg) const { return (*ptr)[pkg].Upgradable(); }
21
22 bool fix_broken() const { return pkgFixBroken(*ptr); }
23
24 /// Is the Package auto installed? Packages marked as auto installed are usually dependencies.
25 bool is_auto_installed(const PkgIterator& pkg) const {
26 pkgDepCache::StateCache state = (*ptr)[pkg];
27 return state.Flags & pkgCache::Flag::Auto;
28 }
29
30 /// Is the Package able to be auto removed?
31 bool is_garbage(const PkgIterator& pkg) const { return (*ptr)[pkg].Garbage; }
32
33 /// Is the Package marked for install?
34 bool marked_install(const PkgIterator& pkg) const { return (*ptr)[pkg].NewInstall(); }
35
36 /// Is the Package marked for upgrade?
37 bool marked_upgrade(const PkgIterator& pkg) const { return (*ptr)[pkg].Upgrade(); }
38
39 /// Is the Package marked to be purged?
40 bool marked_purge(const PkgIterator& pkg) const { return (*ptr)[pkg].Purge(); }
41
42 /// Is the Package marked for removal?
43 bool marked_delete(const PkgIterator& pkg) const { return (*ptr)[pkg].Delete(); }
44
45 /// Is the Package marked for keep?
46 bool marked_keep(const PkgIterator& pkg) const { return (*ptr)[pkg].Keep(); }
47
48 /// Is the Package marked for downgrade?
49 bool marked_downgrade(const PkgIterator& pkg) const { return (*ptr)[pkg].Downgrade(); }
50
51 /// Is the Package marked for reinstall?
52 bool marked_reinstall(const PkgIterator& pkg) const { return (*ptr)[pkg].ReInstall(); }
53
54 /// Mark a package as automatically installed.
55 ///
56 /// MarkAuto = true will mark the package as automatically installed and false will mark it as
57 /// manual
58 void mark_auto(const PkgIterator& pkg, bool mark_auto) const { ptr->MarkAuto(pkg, mark_auto); }
59
60 /// Mark a package for keep.
61 ///
62 /// This means that the package will not be changed from its current version.
63 /// This will not stop a reinstall, but will stop removal, upgrades and downgrades
64 ///
65 /// Soft:
66 /// True = will mark for keep
67 /// False = will unmark for keep
68 ///
69 /// We don't believe that there is any reason to unmark packages for keep.
70 /// If someone has a reason, and would like it implemented, please put in a feature request.
71 ///
72 /// FromUser:
73 /// This is only ever True in apt underneath `MarkInstall`,
74 /// and the bool is passed from `MarkInstall` itselfconst .
75 /// I don't believe anyone needs access to this boolconst .
76 ///
77 /// Depth:
78 /// Recursion tracker and is only used for printing Debug statements.
79 /// No one needs access to this. Additionally Depth cannot be over 3000.
80 bool mark_keep(const PkgIterator& pkg) const { return ptr->MarkKeep(pkg, false, false); }
81
82 /// Mark a package for removal.
83 ///
84 /// MarkPurge:
85 /// True the package will be purged.
86 /// False the package will not be purged.
87 ///
88 /// Depth:
89 /// Recursion tracker and is only used for printing Debug statements.
90 /// No one needs access to this. Additionally Depth cannot be over 3000.
91 ///
92 /// FromUser:
93 /// True if the user requested this.
94 /// False the User did not request this.
95 ///
96 /// Typically You would always use from user.
97 /// False here appears to be more of an implementation detail.
98 bool mark_delete(const PkgIterator& pkg, bool purge) const {
99 return ptr->MarkDelete(pkg, purge);
100 }
101
102 /// Mark a package for installation.
103 ///
104 /// AutoInst: true = Auto Install dependencies of the package.
105 ///
106 /// FromUser: true = Mark the package as installed from the User.
107 ///
108 /// Depth:
109 /// Recursion tracker and is only used for printing Debug statements.
110 /// No one needs access to this. Additionally Depth cannot be over 3000.
111 ///
112 /// ForceImportantDeps = TODO: Study what this does.
113 bool mark_install(const PkgIterator& pkg, bool auto_inst, bool from_user) const {
114 return ptr->MarkInstall(pkg, auto_inst, 0, from_user, false);
115 }
116
117 /// Set a version to be the candidate of it's package.
118 void set_candidate_version(const VerIterator& ver) const { ptr->SetCandidateVersion(ver); }
119
120 /// Return the candidate version of the package.
121 UniquePtr<VerIterator> candidate_version(const PkgIterator& pkg) const {
122 return std::make_unique<VerIterator>(ptr->GetCandidateVersion(pkg));
123 }
124
125 /// Returns the installed version if it exists.
126 /// * If a version is marked for install this will return the version to be
127 /// installed.
128 /// * If an installed package is marked for removal, this will return [`None`].
129 UniquePtr<VerIterator> install_version(const PkgIterator& pkg) const {
130 pkgCache& cache = ptr->GetCache();
131
132 return std::make_unique<VerIterator>((*ptr)[pkg].InstVerIter(cache));
133 }
134
135 /// Returns the state of the dependency as u8
136 u8 dep_state(const DepIterator& dep) const { return (*ptr)[dep]; }
137
138 /// Checks if the dependency is important.
139 ///
140 /// Depends, PreDepends, Conflicts, Obsoletes, Breaks
141 /// will return [true].
142 ///
143 /// Suggests, Recommends will return [true] if they are
144 /// configured to be installed.
145 bool is_important_dep(const DepIterator& dep) const { return ptr->IsImportantDep(dep); }
146
147 /// Mark a package for reinstallation
148 ///
149 /// To:
150 /// True = The package will be marked for reinstall
151 /// False = The package will be unmarked for reinstall
152 void mark_reinstall(const PkgIterator& pkg, bool reinstall) const {
153 ptr->SetReInstall(pkg, reinstall);
154 }
155
156 /// Is the installed Package broken?
157 bool is_now_broken(const PkgIterator& pkg) const { return (*ptr)[pkg].NowBroken(); }
158
159 /// Is the Package to be installed broken?
160 bool is_inst_broken(const PkgIterator& pkg) const { return (*ptr)[pkg].InstBroken(); }
161
162 /// The number of packages marked for installation.
163 u32 install_count() const { return ptr->InstCount(); }
164
165 /// The number of packages marked for removal.
166 u32 delete_count() const { return ptr->DelCount(); }
167
168 /// The number of packages marked for keep.
169 u32 keep_count() const { return ptr->KeepCount(); }
170
171 /// The number of packages with broken dependencies in the cache.
172 u32 broken_count() const { return ptr->BrokenCount(); }
173
174 /// The size of all packages to be downloaded.
175 u64 download_size() const { return ptr->DebSize(); }
176
177 /// The amount of space required for installing/removing the packages,"
178 ///
179 /// i.e. the Installed-Size of all packages marked for installation"
180 /// minus the Installed-Size of all packages for removal."
181 i64 disk_size() const { return ptr->UsrSize(); }
182
183 /// Perform a Full Upgrade. Remove and install new packages if necessary.
184 void upgrade(OperationProgress& callback, int upgrade_mode) const {
185 OpProgressWrapper op_progress(callback);
186 // It is currently unclear if we should return a bool here. I think Result should be fine.
187 APT::Upgrade::Upgrade(*ptr, upgrade_mode, &op_progress);
188 handle_errors();
189 }
190
191 /// Clear any marked changes in the DepCache.
192 void init(OperationProgress& callback) const {
193 OpProgressWrapper op_progress(callback);
194
195 ptr->Init(&op_progress);
196 // pkgApplyStatus(*cache->GetDepCache());
197 handle_errors();
198 }
199
200 PkgDepCache(pkgDepCache* DepCache) : ptr(DepCache){};
201 };