Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/actions/package/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ impl Action for PackageInstall {

// If the provider isn't available, see if we can bootstrap it
if !provider.available() {
if provider.bootstrap().is_empty() {
if provider.bootstrap().unwrap().is_empty() {
error!(
"Package Provider, {}, isn't available. Skipping action",
provider.name()
);
return vec![];
}

atoms.append(&mut provider.bootstrap());
atoms.append(&mut provider.bootstrap().unwrap());
}

if let Some(ref _repo) = variant.repository {
if !provider.has_repository(&variant) {
atoms.append(&mut provider.add_repository(&variant));
atoms.append(&mut provider.add_repository(&variant).unwrap());
}
}

atoms.append(&mut provider.install(&variant));
atoms.append(&mut provider.install(&variant).unwrap());

span.exit();

Expand Down
28 changes: 14 additions & 14 deletions src/actions/package/providers/aptitude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ impl PackageProvider for Aptitude {
}
}

fn bootstrap(&self) -> Vec<Step> {
vec![Step {
fn bootstrap(&self) -> Option<Vec<Step>> {
Some(vec![Step {
atom: Box::new(Exec {
command: String::from("apt"),
arguments: vec![
Expand All @@ -50,16 +50,16 @@ impl PackageProvider for Aptitude {
}),
initializers: vec![],
finalizers: vec![],
}]
}])
}

fn has_repository(&self, _package: &PackageVariant) -> bool {
false
}

fn add_repository(&self, package: &PackageVariant) -> Vec<Step> {
fn add_repository(&self, package: &PackageVariant) -> Option<Vec<Step>> {
if package.repository.is_none() {
return vec![];
return None;
}

let mut steps: Vec<Step> = vec![];
Expand Down Expand Up @@ -106,15 +106,15 @@ impl PackageProvider for Aptitude {
},
]);

steps
Some(steps)
}

fn query(&self, package: &PackageVariant) -> Vec<String> {
package.packages()
fn query(&self, package: &PackageVariant) -> Option<Vec<String>> {
Some(package.packages())
}

fn install(&self, package: &PackageVariant) -> Vec<Step> {
vec![Step {
fn install(&self, package: &PackageVariant) -> Option<Vec<Step>> {
Some(vec![Step {
atom: Box::new(Exec {
command: String::from("apt"),
arguments: vec![String::from("install"), String::from("--yes")]
Expand All @@ -128,7 +128,7 @@ impl PackageProvider for Aptitude {
}),
initializers: vec![],
finalizers: vec![],
}]
}])
}
}

Expand All @@ -150,7 +150,7 @@ mod test {
let aptitude = Aptitude {};
let steps = aptitude.add_repository(&package);

assert_eq!(steps.len(), 0);
assert_eq!(steps.unwrap().len(), 0);
}

#[test]
Expand All @@ -164,7 +164,7 @@ mod test {
let aptitude = Aptitude {};
let steps = aptitude.add_repository(&package);

assert_eq!(steps.len(), 2);
assert_eq!(steps.unwrap().len(), 2);
}

#[test]
Expand All @@ -179,6 +179,6 @@ mod test {
let aptitude = Aptitude {};
let steps = aptitude.add_repository(&package);

assert_eq!(steps.len(), 3);
assert_eq!(steps.unwrap().len(), 3);
}
}
20 changes: 10 additions & 10 deletions src/actions/package/providers/bsdpkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl PackageProvider for BsdPkg {
}

#[instrument(name = "bootstrap", level = "info", skip(self))]
fn bootstrap(&self) -> Vec<Step> {
vec![Step {
fn bootstrap(&self) -> Option<Vec<Step>> {
Some(vec![Step {
atom: Box::new(Exec {
command: String::from("/usr/sbin/pkg"),
arguments: vec![String::from("bootstrap")],
Expand All @@ -43,25 +43,25 @@ impl PackageProvider for BsdPkg {
}),
initializers: vec![],
finalizers: vec![],
}]
}])
}

fn has_repository(&self, _package: &PackageVariant) -> bool {
false
}

fn add_repository(&self, _package: &PackageVariant) -> Vec<Step> {
vec![]
fn add_repository(&self, _package: &PackageVariant) -> Option<Vec<Step>> {
None
}

fn query(&self, package: &PackageVariant) -> Vec<String> {
fn query(&self, package: &PackageVariant) -> Option<Vec<String>> {
// Install all packages for now, don't get smart about which
// already are
package.packages()
Some(package.packages())
}

fn install(&self, package: &PackageVariant) -> Vec<Step> {
vec![
fn install(&self, package: &PackageVariant) -> Option<Vec<Step>> {
Some(vec![
Step {
atom: Box::new(Exec {
command: String::from("/usr/sbin/pkg"),
Expand Down Expand Up @@ -90,6 +90,6 @@ impl PackageProvider for BsdPkg {
initializers: vec![],
finalizers: vec![],
},
]
])
}
}
75 changes: 41 additions & 34 deletions src/actions/package/providers/homebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ impl PackageProvider for Homebrew {
which("brew").is_ok()
}

fn bootstrap(&self) -> Vec<Step> {
vec![Step { atom: Box::new(Exec {
fn bootstrap(&self) -> Option<Vec<Step>> {
Some(vec![Step { atom: Box::new(Exec {
command: String::from("bash"),
arguments: vec![
String::from("-c"),
String::from("$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)")
],
..Default::default()
}), initializers: vec![], finalizers: vec![] },]
}), initializers: vec![], finalizers: vec![] },])
}

fn has_repository(&self, _: &PackageVariant) -> bool {
Expand All @@ -36,21 +36,21 @@ impl PackageProvider for Homebrew {
false
}

fn add_repository(&self, package: &PackageVariant) -> Vec<Step> {
fn add_repository(&self, package: &PackageVariant) -> Option<Vec<Step>> {
let repository = package.repository.clone().unwrap();

vec![Step {
Some(vec![Step {
atom: Box::new(Exec {
command: String::from("brew"),
arguments: vec![String::from("tap"), repository],
..Default::default()
}),
initializers: vec![],
finalizers: vec![],
}]
}])
}

fn query(&self, package: &PackageVariant) -> Vec<String> {
fn query(&self, package: &PackageVariant) -> Option<Vec<String>> {
let prefix = String::from_utf8(
Command::new("brew")
.arg("--prefix")
Expand All @@ -65,36 +65,43 @@ impl PackageProvider for Homebrew {
let cellar = Path::new(&prefix).join("Cellar");
let caskroom = Path::new(&prefix).join("Caskroom");

package
.packages()
.into_iter()
.filter(|p| {
if cellar.join(&p).is_dir() {
trace!("{}: found in Cellar", p);
false
} else if caskroom.join(&p).is_dir() {
trace!("{}: found in Caskroom", p);
false
} else {
debug!("{}: doesn't appear to be installed", p);
true
}
})
.map(|p| match &package.repository {
Some(repository) => format!("{}/{}", repository, p),
None => p,
})
.collect()
Some(
package
.packages()
.into_iter()
.filter(|p| {
if cellar.join(&p).is_dir() {
trace!("{}: found in Cellar", p);
false
} else if caskroom.join(&p).is_dir() {
trace!("{}: found in Caskroom", p);
false
} else {
debug!("{}: doesn't appear to be installed", p);
true
}
})
.map(|p| match &package.repository {
Some(repository) => format!("{}/{}", repository, p),
None => p,
})
.collect(),
)
}

fn install(&self, package: &PackageVariant) -> Vec<Step> {
let need_installed = self.query(package);
fn install(&self, package: &PackageVariant) -> Option<Vec<Step>> {
// let need_installed = self.query(package);

// if need_installed.unwrap().is_empty() {
// return None;
// }

if need_installed.is_empty() {
return vec![];
}
let need_installed: Vec<String> = match self.query(package) {
Some(packages) => packages,
None => return None,
};

vec![Step {
Some(vec![Step {
atom: Box::new(Exec {
command: String::from("brew"),
arguments: [
Expand All @@ -107,6 +114,6 @@ impl PackageProvider for Homebrew {
}),
initializers: vec![],
finalizers: vec![],
}]
}])
}
}
8 changes: 4 additions & 4 deletions src/actions/package/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ impl Default for PackageProviders {
pub trait PackageProvider {
fn name(&self) -> &str;
fn available(&self) -> bool;
fn bootstrap(&self) -> Vec<Step>;
fn bootstrap(&self) -> Option<Vec<Step>>;
fn has_repository(&self, package: &PackageVariant) -> bool;
fn add_repository(&self, package: &PackageVariant) -> Vec<Step>;
fn query(&self, package: &PackageVariant) -> Vec<String>;
fn install(&self, package: &PackageVariant) -> Vec<Step>;
fn add_repository(&self, package: &PackageVariant) -> Option<Vec<Step>>;
fn query(&self, package: &PackageVariant) -> Option<Vec<String>>;
fn install(&self, package: &PackageVariant) -> Option<Vec<Step>>;
}
20 changes: 11 additions & 9 deletions src/actions/package/providers/pkgin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,30 @@ impl PackageProvider for Pkgin {
}

#[instrument(name = "bootstrap", level = "info", skip(self))]
fn bootstrap(&self) -> Vec<Step> {
fn bootstrap(&self) -> Option<Vec<Step>> {
// TODO: Adjust for boot strapping pkgin
vec![]
// vec![]
None
}

fn has_repository(&self, _package: &PackageVariant) -> bool {
false
}

fn add_repository(&self, _package: &PackageVariant) -> Vec<Step> {
vec![]
fn add_repository(&self, _package: &PackageVariant) -> Option<Vec<Step>> {
// vec![]
None
}

// TODO: Handle query pkgs with pkgin search
fn query(&self, package: &PackageVariant) -> Vec<String> {
fn query(&self, package: &PackageVariant) -> Option<Vec<String>> {
// Install all packages for now, don't get smart about which
// already are
package.packages()
Some(package.packages())
}

fn install(&self, package: &PackageVariant) -> Vec<Step> {
vec![
fn install(&self, package: &PackageVariant) -> Option<Vec<Step>> {
Some(vec![
Step {
atom: Box::new(Exec {
command: String::from("/usr/pkg/bin/pkgin"),
Expand Down Expand Up @@ -77,6 +79,6 @@ impl PackageProvider for Pkgin {
initializers: vec![],
finalizers: vec![],
},
]
])
}
}
Loading