r_package_installer/
lib.rs1#![deny(unsafe_code, missing_docs)]
7
8mod archive;
9mod cache;
10mod error;
11mod fsutil;
12mod library;
13mod metadata;
14mod model;
15mod platform;
16mod source;
17mod transaction;
18
19pub use cache::Cache;
20pub use error::{Error, Result};
21pub use library::{recover_package, remove_package, scan_library};
22pub use model::{
23 ArchiveLimits, Artifact, BinaryArtifact, CacheEntry, CacheKey, CacheLockPolicy,
24 CancellationToken, Digest, ExpectedPackage, InstallOutcome, InstalledPackage, InstallerOptions,
25 LibraryEntry, LockMetadata, LockPolicy, PackageMetadata, PrepareRequest, RecoveryAction,
26 RecoveryPlan, RemovalOutcome, SourceArtifact, SourceOptions,
27};
28
29use std::path::Path;
30
31#[derive(Debug, Clone)]
33pub struct Installer {
34 cache: Cache,
35 options: InstallerOptions,
36}
37
38impl Installer {
39 pub fn new(cache_root: impl Into<std::path::PathBuf>) -> Self {
41 Self {
42 cache: Cache::new(cache_root),
43 options: InstallerOptions::default(),
44 }
45 }
46
47 pub fn with_options(
49 cache_root: impl Into<std::path::PathBuf>,
50 options: InstallerOptions,
51 ) -> Self {
52 Self {
53 cache: Cache::new(cache_root),
54 options,
55 }
56 }
57
58 pub const fn cache(&self) -> &Cache {
60 &self.cache
61 }
62
63 pub fn prepare(&self, request: &PrepareRequest) -> Result<CacheEntry> {
65 self.cache.prepare(request, &self.options)
66 }
67
68 pub fn materialize(&self, entry: &CacheEntry, library: &Path) -> Result<InstallOutcome> {
70 transaction::materialize(entry, library, &self.options)
71 }
72
73 pub fn install(&self, request: &PrepareRequest, library: &Path) -> Result<InstallOutcome> {
75 let entry = self.prepare(request)?;
76 self.materialize(&entry, library)
77 }
78
79 pub fn remove(&self, library: &Path, package: &str) -> Result<RemovalOutcome> {
81 remove_package(library, package, &self.options)
82 }
83}