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
|
#pragma once
#include <apt-pkg/cachefile.h>
#include <apt-pkg/debfile.h>
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/indexfile.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/policy.h>
#include <apt-pkg/sourcelist.h>
#include <apt-pkg/update.h>
#include "rust/cxx.h"
// Defines the callbacks code that's generated for progress
#include "rust-apt/src/acquire.rs"
#include "depcache.h"
#include "records.h"
#include "types.h"
struct PkgCacheFile : public pkgCacheFile {
// Maybe we use this if we don't want pin_mut() all over the place in Rust.
PkgCacheFile* unconst() const { return const_cast<PkgCacheFile*>(this); }
/// Update the package lists, handle errors and return a Result.
void update(AcqTextStatus& progress) const {
ListUpdate(
progress, *this->unconst()->GetSourceList(), progress.callback->pulse_interval()
);
handle_errors();
}
// Return a package by name.
UniquePtr<PkgIterator> find_pkg(str name) const {
return std::make_unique<PkgIterator>(
this->unconst()->GetPkgCache()->FindPkg(std::string_view(name.begin(), name.length()))
);
}
UniquePtr<PkgIterator> begin() const {
return std::make_unique<PkgIterator>(this->unconst()->GetPkgCache()->PkgBegin());
}
/// The priority of the package as shown in `apt policy`.
int32_t priority(const VerIterator& ver) const {
return this->unconst()->GetPolicy()->GetPriority(ver);
}
UniquePtr<PkgDepCache> create_depcache() const {
return std::make_unique<PkgDepCache>(this->unconst()->GetDepCache());
}
UniquePtr<PkgRecords> create_records() const {
return std::make_unique<PkgRecords>(this->unconst());
}
UniquePtr<IndexFile> find_index(const PkgFileIterator& file) const {
pkgIndexFile* index;
if (!this->unconst()->GetSourceList()->FindIndex(file, index)) {
_system->FindIndex(file, index);
}
return std::make_unique<IndexFile>(index);
}
bool get_indexes(const PkgAcquire& fetcher) const {
return this->unconst()->GetSourceList()->GetIndexes(fetcher.ptr, true);
}
PkgCacheFile() : pkgCacheFile(){};
};
inline UniquePtr<PkgCacheFile> create_cache(rust::Slice<const str> volatile_files) {
UniquePtr<PkgCacheFile> cache = std::make_unique<PkgCacheFile>();
for (auto file_str : volatile_files) {
std::string file_string(file_str);
// Add the file to the cache.
if (!cache->GetSourceList()->AddVolatileFile(file_string)) {
_error->Error("%s", ("Couldn't add '" + file_string + "' to the cache.").c_str());
}
}
// Building the pkg caches can cause an error that might not
// Get propagated until you get a pkg which shouldn't have errors.
// See https://gitlab.com/volian/rust-apt/-/issues/24
cache->GetPkgCache();
handle_errors();
return cache;
}
|