pub struct Cache {
pub ptr: Rc<RefCell<UniquePtr<PkgCacheFile>>>,
pub records: Rc<RefCell<Records>>,
/* private fields */
}Expand description
The main struct for accessing any and all apt data.
Fields
ptr: Rc<RefCell<UniquePtr<PkgCacheFile>>>records: Rc<RefCell<Records>>Implementations
sourceimpl Cache
impl Cache
sourcepub fn new() -> Self
pub fn new() -> Self
Initialize the configuration system, open and return the cache.
This is the entry point for all operations of this crate.
sourcepub fn clear(&self)
pub fn clear(&self)
Clear the entire cache and start new.
This function would be used after cache.update
Or after do_install if you plan on making more changes
sourcepub fn update(
&self,
progress: &mut Box<dyn AcquireProgress>
) -> Result<(), Exception>
pub fn update(
&self,
progress: &mut Box<dyn AcquireProgress>
) -> Result<(), Exception>
Updates the package cache and returns a Result
Here is an example of how you may parse the Error messages.
use rust_apt::cache::Cache;
use rust_apt::progress::{AcquireProgress, AptAcquireProgress};
let cache = Cache::new();
let mut progress: Box<dyn AcquireProgress> = Box::new(AptAcquireProgress::new());
if let Err(error) = cache.update(&mut progress) {
for msg in error.what().split(';') {
if msg.starts_with("E:") {
println!("Error: {}", &msg[2..]);
}
if msg.starts_with("W:") {
println!("Warning: {}", &msg[2..]);
}
}
}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<(), Exception>
pub fn upgrade(&self, upgrade_type: &Upgrade) -> Result<(), Exception>
Mark all packages for upgrade
Example:
use rust_apt::cache::{Cache, Upgrade};
let cache = Cache::new();
cache.upgrade(&Upgrade::FullUpgrade).unwrap();sourcepub fn get_changes<'a>(
&'a self,
sort_name: bool
) -> impl Iterator<Item = Package<'_>> + '_
pub fn get_changes<'a>(
&'a self,
sort_name: bool
) -> impl Iterator<Item = Package<'_>> + '_
An iterator over the packages
that will be altered when cache.commit() is called.
sort_name:
sourcepub fn resolve(&self, fix_broken: bool) -> Result<(), Exception>
pub fn resolve(&self, fix_broken: bool) -> Result<(), Exception>
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::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 get_archives(
&self,
progress: &mut Box<dyn AcquireProgress>
) -> Result<(), Exception>
pub fn get_archives(
&self,
progress: &mut Box<dyn AcquireProgress>
) -> Result<(), Exception>
Fetch any archives needed to complete the transaction.
Returns:
Example:
use rust_apt::cache::Cache;
use rust_apt::package::Mark;
use rust_apt::progress::{AptAcquireProgress};
let cache = Cache::new();
let pkg = cache.get("neovim").unwrap();
let mut progress = AptAcquireProgress::new_box();
pkg.set(&Mark::Install).then_some(()).unwrap();
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 Box<dyn InstallProgress>
) -> Result<(), Exception>
pub fn do_install(
&self,
progress: &mut Box<dyn InstallProgress>
) -> Result<(), Exception>
Install, remove, and do any other actions requested by the cache.
Returns:
Example:
use rust_apt::cache::Cache;
use rust_apt::package::Mark;
use rust_apt::progress::{AptAcquireProgress, AptInstallProgress};
let cache = Cache::new();
let pkg = cache.get("neovim").unwrap();
let mut acquire_progress = AptAcquireProgress::new_box();
let mut install_progress = AptInstallProgress::new_box();
pkg.set(&Mark::Install).then_some(()).unwrap();
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 Box<dyn AcquireProgress>,
install_progress: &mut Box<dyn InstallProgress>
) -> Result<(), Exception>
pub fn commit(
&self,
progress: &mut Box<dyn AcquireProgress>,
install_progress: &mut Box<dyn InstallProgress>
) -> Result<(), Exception>
Handle get_archives and do_install in an easy wrapper.
Returns:
Example:
use rust_apt::cache::Cache;
use rust_apt::package::Mark;
use rust_apt::progress::{AptAcquireProgress, AptInstallProgress};
let cache = Cache::new();
let pkg = cache.get("neovim").unwrap();
let mut acquire_progress = AptAcquireProgress::new_box();
let mut install_progress = AptInstallProgress::new_box();
pkg.set(&Mark::Install).then_some(()).unwrap();
pkg.protect();
cache.resolve(true).unwrap();
// This needs root
// cache.commit(&mut acquire_progress, &mut install_progress).unwrap();sourcepub fn clear_marked(&self) -> Result<(), Exception>
pub fn clear_marked(&self) -> Result<(), Exception>
Clear any marked changes in the DepCache.
sourcepub fn sources(&self) -> impl Iterator<Item = SourceFile> + '_
pub fn sources(&self) -> impl Iterator<Item = SourceFile> + '_
Returns an iterator of SourceURIs.
These are the files that apt update will fetch.
sourcepub fn provides(
&self,
virt_pkg: &Package<'_>,
cand_only: bool
) -> impl Iterator<Item = Package<'_>> + '_
pub fn provides(
&self,
virt_pkg: &Package<'_>,
cand_only: bool
) -> impl Iterator<Item = Package<'_>> + '_
Returns an iterator of Packages that provide the virtual package.
NOTE: This function is ONLY designed to get the list of packages of
a virtual package. It also expects that you’ll be installing the
candidate version, and this likewise doesn’t return a specific version
to install. You probably want to use Package::rev_provides_list
instead.
sourcepub fn get<'a>(&'a self, name: &str) -> Option<Package<'a>>
pub fn get<'a>(&'a self, name: &str) -> Option<Package<'a>>
Get a single package.
cache.get("apt") Returns a Package object for the native arch.
cache.get("apt:i386") Returns a Package object for the i386 arch
sourcepub fn packages<'a>(
&'a self,
sort: &'a PackageSort
) -> impl Iterator<Item = Package<'_>> + '_
pub fn packages<'a>(
&'a self,
sort: &'a PackageSort
) -> impl Iterator<Item = Package<'_>> + '_
An iterator of packages in the cache.
sourcepub fn install_count(&self) -> u32
pub fn install_count(&self) -> u32
The number of packages marked for installation.
sourcepub fn delete_count(&self) -> u32
pub fn delete_count(&self) -> u32
The number of packages marked for removal.
sourcepub fn keep_count(&self) -> u32
pub fn keep_count(&self) -> u32
The number of packages marked for keep.
sourcepub fn broken_count(&self) -> u32
pub fn broken_count(&self) -> u32
The number of packages with broken dependencies in the cache.
sourcepub fn download_size(&self) -> u64
pub fn download_size(&self) -> u64
The size of all packages to be downloaded.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Cache
impl !Send for Cache
impl !Sync for Cache
impl Unpin for Cache
impl !UnwindSafe for Cache
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more