File: depcache.h

package info (click to toggle)
rust-rust-apt 0.7.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 524 kB
  • sloc: cpp: 773; makefile: 8
file content (257 lines) | stat: -rw-r--r-- 9,321 bytes parent folder | download
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#pragma once
#include <apt-pkg/cachefile.h>
#include <apt-pkg/upgrade.h>
#include <memory>
#include "rust/cxx.h"

#include "rust-apt/src/raw/depcache.rs"

/// Clear any marked changes in the DepCache.
inline void DepCache::init(DynOperationProgress& callback) const {
	OpProgressWrapper op_progress(callback);

	(*ptr)->Init(&op_progress);
	// pkgApplyStatus(*cache->GetDepCache());
	handle_errors();
}

/// Autoinstall every broken package and run the problem resolver
/// Returns false if the problem resolver fails.
inline bool DepCache::fix_broken() const noexcept { return pkgFixBroken(**ptr); }

inline ActionGroup DepCache::action_group() const noexcept {
	return ActionGroup{std::make_unique<PkgActionGroup>(**ptr)};
}

inline void ActionGroup::release() const noexcept { ptr->release(); }

/// Is the Package upgradable?
///
/// `skip_depcache = true` increases performance by skipping the pkgDepCache
/// Skipping the depcache is very unnecessary if it's already been
/// initialized If you're not sure, set `skip_depcache = false`
inline bool DepCache::is_upgradable(const Package& pkg) const noexcept {
	return (**ptr)[*pkg.ptr].Upgradable();
}

/// Is the Package auto installed? Packages marked as auto installed are usually dependencies.
inline bool DepCache::is_auto_installed(const Package& pkg) const noexcept {
	pkgDepCache::StateCache state = (**ptr)[*pkg.ptr];
	return state.Flags & pkgCache::Flag::Auto;
}

/// Is the Package able to be auto removed?
inline bool DepCache::is_garbage(const Package& pkg) const noexcept {
	return (**ptr)[*pkg.ptr].Garbage;
}

/// Is the Package marked for install?
inline bool DepCache::marked_install(const Package& pkg) const noexcept {
	return (**ptr)[*pkg.ptr].NewInstall();
}

/// Is the Package marked for upgrade?
inline bool DepCache::marked_upgrade(const Package& pkg) const noexcept {
	return (**ptr)[*pkg.ptr].Upgrade();
}

/// Is the Package marked to be purged?
inline bool DepCache::marked_purge(const Package& pkg) const noexcept {
	return (**ptr)[*pkg.ptr].Purge();
}

/// Is the Package marked for removal?
inline bool DepCache::marked_delete(const Package& pkg) const noexcept {
	return (**ptr)[*pkg.ptr].Delete();
}

/// Is the Package marked for keep?
inline bool DepCache::marked_keep(const Package& pkg) const noexcept {
	return (**ptr)[*pkg.ptr].Keep();
}

/// Is the Package marked for downgrade?
inline bool DepCache::marked_downgrade(const Package& pkg) const noexcept {
	return (**ptr)[*pkg.ptr].Downgrade();
}

/// Is the Package marked for reinstall?
inline bool DepCache::marked_reinstall(const Package& pkg) const noexcept {
	return (**ptr)[*pkg.ptr].ReInstall();
}

/// Mark a package as automatically installed.
///
/// MarkAuto = true will mark the package as automatically installed and false will mark it as
/// manual
inline void DepCache::mark_auto(const Package& pkg, bool mark_auto) const noexcept {
	(*ptr)->MarkAuto(*pkg.ptr, mark_auto);
}

/// Mark a package for keep.
///
///     This means that the package will not be changed from its current version.
///     This will not stop a reinstall, but will stop removal, upgrades and downgrades
///
/// Soft:
///     True = will mark for keep
///     False = will unmark for keep
///
///     We don't believe that there is any reason to unmark packages for keep.
///     If someone has a reason, and would like it implemented, please put in a feature request.
///
/// FromUser:
///     This is only ever True in apt underneath `MarkInstall`,
///     and the bool is passed from `MarkInstall` itselfconst .
///     I don't believe anyone needs access to this boolconst .
///
/// Depth:
///     Recursion tracker and is only used for printing Debug statements.
///     No one needs access to this. Additionally Depth cannot be over 3000.
inline bool DepCache::mark_keep(const Package& pkg) const noexcept {
	return (*ptr)->MarkKeep(*pkg.ptr, false, false);
}

/// Mark a package for removal.
///
/// MarkPurge:
///     True the package will be purged.
///     False the package will not be purged.
///
/// Depth:
///     Recursion tracker and is only used for printing Debug statements.
///     No one needs access to this. Additionally Depth cannot be over 3000.
///
/// FromUser:
///     True if the user requested this.
///     False the User did not request this.
///
///     Typically You would always use from user.
///     False here appears to be more of an implementation detail.
inline bool DepCache::mark_delete(const Package& pkg, bool purge) const noexcept {
	return (*ptr)->MarkDelete(*pkg.ptr, purge);
}

/// Mark a package for installation.
///
/// AutoInst: true = Auto Install dependencies of the package.
///
/// FromUser: true = Mark the package as installed from the User.
///
/// Depth:
///     Recursion tracker and is only used for printing Debug statements.
///     No one needs access to this. Additionally Depth cannot be over 3000.
///
/// ForceImportantDeps = TODO: Study what this does.
inline bool DepCache::mark_install(const Package& pkg, bool auto_inst, bool from_user)
	const noexcept {
	return (*ptr)->MarkInstall(*pkg.ptr, auto_inst, 0, from_user, false);
}

/// Set a version to be the candidate of it's package.
inline void DepCache::set_candidate_version(const Version& ver) const noexcept {
	(*ptr)->SetCandidateVersion(*ver.ptr);
}

/// Return the candidate version of the package.
/// Ptr will be NULL if there isn't a candidate.
inline Version DepCache::unsafe_candidate_version(const Package& pkg) const noexcept {
	return Version{std::make_unique<VerIterator>((*ptr)->GetCandidateVersion(*pkg.ptr))};
}

/// Returns the installed version if it exists.
/// * If a version is marked for install this will return the version to be
///   installed.
/// * If an installed package is marked for removal, this will return [`None`].
inline Version DepCache::unsafe_install_version(const Package& pkg) const noexcept {
	pkgCache& cache = (*ptr)->GetCache();

	return Version{std::make_unique<VerIterator>((**ptr)[*pkg.ptr].InstVerIter(cache))};
}

/// Returns the state of the dependency as u8
inline uint8_t DepCache::dep_state(const Dependency& dep) const noexcept {
	return (**ptr)[*dep.ptr];
}

/// Checks if the dependency is important.
///
/// Depends, PreDepends, Conflicts, Obsoletes, Breaks
/// will return [true].
///
/// Suggests, Recommends will return [true] if they are
/// configured to be installed.
inline bool DepCache::is_important_dep(const Dependency& dep) const noexcept {
	return (*ptr)->IsImportantDep(*dep.ptr);
}

/// Mark a package for reinstallation
///
/// To:
///     True = The package will be marked for reinstall
///     False = The package will be unmarked for reinstall
inline void DepCache::mark_reinstall(const Package& pkg, bool reinstall) const noexcept {
	(*ptr)->SetReInstall(*pkg.ptr, reinstall);
}

/// Is the installed Package broken?
inline bool DepCache::is_now_broken(const Package& pkg) const noexcept {
	return (**ptr)[*pkg.ptr].NowBroken();
}

/// Is the Package to be installed broken?
inline bool DepCache::is_inst_broken(const Package& pkg) const noexcept {
	return (**ptr)[*pkg.ptr].InstBroken();
}

/// The number of packages marked for installation.
inline u_int32_t DepCache::install_count() const noexcept { return (*ptr)->InstCount(); }

/// The number of packages marked for removal.
inline u_int32_t DepCache::delete_count() const noexcept { return (*ptr)->DelCount(); }

/// The number of packages marked for keep.
inline u_int32_t DepCache::keep_count() const noexcept { return (*ptr)->KeepCount(); }

/// The number of packages with broken dependencies in the cache.
inline u_int32_t DepCache::broken_count() const noexcept { return (*ptr)->BrokenCount(); }

/// The size of all packages to be downloaded.
inline u_int64_t DepCache::download_size() const noexcept { return (*ptr)->DebSize(); }

/// The amount of space required for installing/removing the packages,"
///
/// i.e. the Installed-Size of all packages marked for installation"
/// minus the Installed-Size of all packages for removal."
inline int64_t DepCache::disk_size() const noexcept { return (*ptr)->UsrSize(); }

/// Perform a Full Upgrade. Remove and install new packages if necessary.
inline void DepCache::full_upgrade(DynOperationProgress& callback) const {
	OpProgressWrapper op_progress(callback);

	// This is equivalent to `apt full-upgrade` and `apt-get dist-upgrade`
	// It is currently unclear if we should return a bool here. I think Result should be fine.
	APT::Upgrade::Upgrade(**ptr, APT::Upgrade::ALLOW_EVERYTHING, &op_progress);
	handle_errors();
}

/// Perform a Safe Upgrade. Neither remove or install new packages.
inline void DepCache::safe_upgrade(DynOperationProgress& callback) const {
	OpProgressWrapper op_progress(callback);

	// This is equivalent to `apt-get upgrade`
	APT::Upgrade::Upgrade(
		**ptr, APT::Upgrade::FORBID_REMOVE_PACKAGES | APT::Upgrade::FORBID_INSTALL_NEW_PACKAGES,
		&op_progress
	);
	handle_errors();
}

/// Perform an Install Upgrade. New packages will be installed but nothing will be removed.
inline void DepCache::install_upgrade(DynOperationProgress& callback) const {
	OpProgressWrapper op_progress(callback);

	// This is equivalent to `apt upgrade`
	APT::Upgrade::Upgrade(**ptr, APT::Upgrade::FORBID_REMOVE_PACKAGES, &op_progress);
	handle_errors();
}