| 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 |
|
| 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 |
|
| 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 |
|
| 31 |
bool is_garbage(const PkgIterator& pkg) const { return (*ptr)[pkg].Garbage; } |
| 32 |
|
| 33 |
|
| 34 |
bool marked_install(const PkgIterator& pkg) const { return (*ptr)[pkg].NewInstall(); } |
| 35 |
|
| 36 |
|
| 37 |
bool marked_upgrade(const PkgIterator& pkg) const { return (*ptr)[pkg].Upgrade(); } |
| 38 |
|
| 39 |
|
| 40 |
bool marked_purge(const PkgIterator& pkg) const { return (*ptr)[pkg].Purge(); } |
| 41 |
|
| 42 |
|
| 43 |
bool marked_delete(const PkgIterator& pkg) const { return (*ptr)[pkg].Delete(); } |
| 44 |
|
| 45 |
|
| 46 |
bool marked_keep(const PkgIterator& pkg) const { return (*ptr)[pkg].Keep(); } |
| 47 |
|
| 48 |
|
| 49 |
bool marked_downgrade(const PkgIterator& pkg) const { return (*ptr)[pkg].Downgrade(); } |
| 50 |
|
| 51 |
|
| 52 |
bool marked_reinstall(const PkgIterator& pkg) const { return (*ptr)[pkg].ReInstall(); } |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
void mark_auto(const PkgIterator& pkg, bool mark_auto) const { ptr->MarkAuto(pkg, mark_auto); } |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
bool mark_keep(const PkgIterator& pkg) const { return ptr->MarkKeep(pkg, false, false); } |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
bool mark_delete(const PkgIterator& pkg, bool purge) const { |
| 99 |
return ptr->MarkDelete(pkg, purge); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 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 |
|
| 118 |
void set_candidate_version(const VerIterator& ver) const { ptr->SetCandidateVersion(ver); } |
| 119 |
|
| 120 |
|
| 121 |
UniquePtr<VerIterator> candidate_version(const PkgIterator& pkg) const { |
| 122 |
return std::make_unique<VerIterator>(ptr->GetCandidateVersion(pkg)); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 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 |
|
| 136 |
u8 dep_state(const DepIterator& dep) const { return (*ptr)[dep]; } |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
bool is_important_dep(const DepIterator& dep) const { return ptr->IsImportantDep(dep); } |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
void mark_reinstall(const PkgIterator& pkg, bool reinstall) const { |
| 153 |
ptr->SetReInstall(pkg, reinstall); |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
bool is_now_broken(const PkgIterator& pkg) const { return (*ptr)[pkg].NowBroken(); } |
| 158 |
|
| 159 |
|
| 160 |
bool is_inst_broken(const PkgIterator& pkg) const { return (*ptr)[pkg].InstBroken(); } |
| 161 |
|
| 162 |
|
| 163 |
u32 install_count() const { return ptr->InstCount(); } |
| 164 |
|
| 165 |
|
| 166 |
u32 delete_count() const { return ptr->DelCount(); } |
| 167 |
|
| 168 |
|
| 169 |
u32 keep_count() const { return ptr->KeepCount(); } |
| 170 |
|
| 171 |
|
| 172 |
u32 broken_count() const { return ptr->BrokenCount(); } |
| 173 |
|
| 174 |
|
| 175 |
u64 download_size() const { return ptr->DebSize(); } |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
i64 disk_size() const { return ptr->UsrSize(); } |
| 182 |
|
| 183 |
|
| 184 |
void upgrade(OperationProgress& callback, int upgrade_mode) const { |
| 185 |
OpProgressWrapper op_progress(callback); |
| 186 |
|
| 187 |
APT::Upgrade::Upgrade(*ptr, upgrade_mode, &op_progress); |
| 188 |
handle_errors(); |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
void init(OperationProgress& callback) const { |
| 193 |
OpProgressWrapper op_progress(callback); |
| 194 |
|
| 195 |
ptr->Init(&op_progress); |
| 196 |
|
| 197 |
handle_errors(); |
| 198 |
} |
| 199 |
|
| 200 |
PkgDepCache(pkgDepCache* DepCache) : ptr(DepCache){}; |
| 201 |
}; |