pub struct Cache { /* private fields */ }
Expand description
The main struct for accessing any and all apt
data.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn new<T: AsRef<str>>(local_files: &[T]) -> Result<Cache, AptErrors>
pub fn new<T: AsRef<str>>(local_files: &[T]) -> Result<Cache, AptErrors>
Initialize the configuration system, open and return the cache. This is the entry point for all operations of this crate.
local_files
allows you to temporarily add local files to the cache, as
long as they are one of the following:
*.deb
or*.ddeb
filesPackages
andSources
files from apt repositories. These files can be compressed.*.dsc
or*.changes
files- A valid directory containing the file
./debian/control
This function returns an AptErrors
if any of the files cannot
be found or are invalid.
Note that if you run Cache::commit
or Cache::update
,
You will be required to make a new cache to perform any further changes
Sourcepub fn raw_pkgs(&self) -> impl Iterator<Item = UniquePtr<PkgIterator>>
pub fn raw_pkgs(&self) -> impl Iterator<Item = UniquePtr<PkgIterator>>
Internal Method for generating the package list.
Sourcepub fn records(&self) -> &PackageRecords
pub fn records(&self) -> &PackageRecords
Get the PkgRecords
Sourcepub fn pkg_manager(&self) -> &PackageManager
pub fn pkg_manager(&self) -> &PackageManager
Get the PkgManager
Sourcepub fn resolver(&self) -> &ProblemResolver
pub fn resolver(&self) -> &ProblemResolver
Get the ProblemResolver
Sourcepub fn packages(&self, sort: &PackageSort) -> impl Iterator<Item = Package<'_>>
pub fn packages(&self, sort: &PackageSort) -> impl Iterator<Item = Package<'_>>
An iterator of packages in the cache.
Sourcepub fn update(self, progress: &mut AcquireProgress<'_>) -> Result<(), AptErrors>
pub fn update(self, progress: &mut AcquireProgress<'_>) -> Result<(), AptErrors>
Updates the package cache and returns a Result
Here is an example of how you may parse the Error messages.
use rust_apt::new_cache;
use rust_apt::progress::AcquireProgress;
let cache = new_cache!().unwrap();
let mut progress = AcquireProgress::apt();
if let Err(e) = cache.update(&mut progress) {
for error in e.iter() {
if error.is_error {
println!("Error: {}", error.msg);
} else {
println!("Warning: {}", error.msg);
}
}
}
§Known Errors:
- E:Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
- E:Unable to lock directory /var/lib/apt/lists/
Sourcepub fn upgrade(&self, upgrade_type: Upgrade) -> Result<(), AptErrors>
pub fn upgrade(&self, upgrade_type: Upgrade) -> Result<(), AptErrors>
Mark all packages for upgrade
§Example:
use rust_apt::new_cache;
use rust_apt::cache::Upgrade;
let cache = new_cache!().unwrap();
cache.upgrade(Upgrade::FullUpgrade).unwrap();
Sourcepub fn resolve(&self, fix_broken: bool) -> Result<(), AptErrors>
pub fn resolve(&self, fix_broken: bool) -> Result<(), AptErrors>
Resolve dependencies with the changes marked on all packages. This marks additional packages for installation/removal to satisfy the dependency chain.
Note that just running a mark_*
function on a package doesn’t
guarantee that the selected state will be kept during dependency
resolution. If you need such, make sure to run
crate::Package::protect
after marking your requested
modifications.
If fix_broken
is set to true
, the library will try to repair
broken dependencies of installed packages.
Returns Err
if there was an error reaching dependency resolution.
Sourcepub fn fix_broken(&self) -> bool
pub fn fix_broken(&self) -> bool
Autoinstall every broken package and run the problem resolver Returns false if the problem resolver fails.
§Example:
use rust_apt::new_cache;
let cache = new_cache!().unwrap();
cache.fix_broken();
for pkg in cache.get_changes(false) {
println!("Pkg Name: {}", pkg.name())
}
Sourcepub fn get_archives(
&self,
progress: &mut AcquireProgress<'_>,
) -> Result<(), Exception>
pub fn get_archives( &self, progress: &mut AcquireProgress<'_>, ) -> Result<(), Exception>
Fetch any archives needed to complete the transaction.
§Returns:
§Example:
use rust_apt::new_cache;
use rust_apt::progress::AcquireProgress;
let cache = new_cache!().unwrap();
let pkg = cache.get("neovim").unwrap();
let mut progress = AcquireProgress::apt();
pkg.mark_install(true, true);
pkg.protect();
cache.resolve(true).unwrap();
cache.get_archives(&mut progress).unwrap();
§Known Errors:
- W:Problem unlinking the file /var/cache/apt/archives/partial/neofetch_7.1.0-4_all.deb - PrepareFiles (13: Permission denied)
- W:Problem unlinking the file /var/cache/apt/archives/partial/neofetch_7.1.0-4_all.deb - PrepareFiles (13: Permission denied)
- W:Problem unlinking the file /var/cache/apt/archives/partial/neofetch_7.1.0-4_all.deb - PrepareFiles (13: Permission denied)
- W:Problem unlinking the file /var/cache/apt/archives/partial/neofetch_7.1.0-4_all.deb - PrepareFiles (13: Permission denied)
- W:Problem unlinking the file /var/cache/apt/archives/partial/neofetch_7.1.0-4_all.deb - PrepareFiles (13: Permission denied)
- W:Problem unlinking the file /var/log/apt/eipp.log.xz - FileFd::Open (13: Permission denied)
- W:Could not open file /var/log/apt/eipp.log.xz - open (17: File exists)
- W:Could not open file ‘/var/log/apt/eipp.log.xz’ - EIPP::OrderInstall (17: File exists)
- E:Internal Error, ordering was unable to handle the media swap“
Sourcepub fn do_install(
self,
progress: &mut InstallProgress<'_>,
) -> Result<(), AptErrors>
pub fn do_install( self, progress: &mut InstallProgress<'_>, ) -> Result<(), AptErrors>
Install, remove, and do any other actions requested by the cache.
§Returns:
§Example:
use rust_apt::new_cache;
use rust_apt::progress::{AcquireProgress, InstallProgress};
let cache = new_cache!().unwrap();
let pkg = cache.get("neovim").unwrap();
let mut acquire_progress = AcquireProgress::apt();
let mut install_progress = InstallProgress::apt();
pkg.mark_install(true, true);
pkg.protect();
cache.resolve(true).unwrap();
// These need root
// cache.get_archives(&mut acquire_progress).unwrap();
// cache.do_install(&mut install_progress).unwrap();
§Known Errors:
- W:Problem unlinking the file /var/log/apt/eipp.log.xz - FileFd::Open (13: Permission denied)
- W:Could not open file /var/log/apt/eipp.log.xz - open (17: File exists)
- W:Could not open file ‘/var/log/apt/eipp.log.xz’ - EIPP::OrderInstall (17: File exists)
- E:Could not create temporary file for /var/lib/apt/extended_states - mkstemp (13: Permission denied)
- E:Failed to write temporary StateFile /var/lib/apt/extended_states
- W:Could not open file ‘/var/log/apt/term.log’ - OpenLog (13: Permission denied)
- E:Sub-process /usr/bin/dpkg returned an error code (2)
- W:Problem unlinking the file /var/cache/apt/pkgcache.bin - pkgDPkgPM::Go (13: Permission denied)
Sourcepub fn commit(
self,
progress: &mut AcquireProgress<'_>,
install_progress: &mut InstallProgress<'_>,
) -> Result<(), AptErrors>
pub fn commit( self, progress: &mut AcquireProgress<'_>, install_progress: &mut InstallProgress<'_>, ) -> Result<(), AptErrors>
Handle get_archives and do_install in an easy wrapper.
§Returns:
§Example:
use rust_apt::new_cache;
use rust_apt::progress::{AcquireProgress, InstallProgress};
let cache = new_cache!().unwrap();
let pkg = cache.get("neovim").unwrap();
let mut acquire_progress = AcquireProgress::apt();
let mut install_progress = InstallProgress::apt();
pkg.mark_install(true, true);
pkg.protect();
cache.resolve(true).unwrap();
// This needs root
// cache.commit(&mut acquire_progress, &mut install_progress).unwrap();
Methods from Deref<Target = PkgCacheFile>§
Sourcepub fn update(&self, progress: Pin<&mut AcqTextStatus>) -> Result<(), Exception>
pub fn update(&self, progress: Pin<&mut AcqTextStatus>) -> Result<(), Exception>
Update the package lists, handle errors and return a Result.
Sourcepub fn get_indexes(&self, fetcher: &PkgAcquire) -> bool
pub fn get_indexes(&self, fetcher: &PkgAcquire) -> bool
Loads the index files into PkgAcquire.
Used to get to source list uris.
It’s not clear if this returning a bool is useful.
Sourcepub unsafe fn create_depcache(&self) -> UniquePtr<PkgDepCache>
pub unsafe fn create_depcache(&self) -> UniquePtr<PkgDepCache>
Sourcepub unsafe fn create_records(&self) -> UniquePtr<PkgRecords>
pub unsafe fn create_records(&self) -> UniquePtr<PkgRecords>
Sourcepub fn priority(&self, version: &VerIterator) -> i32
pub fn priority(&self, version: &VerIterator) -> i32
The priority of the Version as shown in apt policy
.
Sourcepub unsafe fn find_index(&self, file: &PkgFileIterator) -> UniquePtr<IndexFile>
pub unsafe fn find_index(&self, file: &PkgFileIterator) -> UniquePtr<IndexFile>
Lookup the IndexFile of the Package file
§Safety
The IndexFile can not outlive PkgCacheFile.
The returned UniquePtr cannot outlive the cache.
Sourcepub unsafe fn find_pkg(&self, name: &str) -> UniquePtr<PkgIterator>
pub unsafe fn find_pkg(&self, name: &str) -> UniquePtr<PkgIterator>
Return a package by name and optionally architecture.
§Safety
If the Internal Pkg Pointer is NULL, operations can segfault.
You should call make_safe()
asap to convert it to an Option.
The returned UniquePtr cannot outlive the cache.
Sourcepub unsafe fn begin(&self) -> UniquePtr<PkgIterator>
pub unsafe fn begin(&self) -> UniquePtr<PkgIterator>
Return the pointer to the start of the PkgIterator.
§Safety
If the Internal Pkg Pointer is NULL, operations can segfault.
You should call raw_iter()
asap.
The returned UniquePtr cannot outlive the cache.