fmt and prune fix

main
jan Michal 3 years ago
parent 3f23cfd6dc
commit 0c7046425a
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

@ -1,6 +1,6 @@
use std::env;
use std::path::Path;
use std::process::Command;
use std::{env, fs};
use crate::internal::{crash, info};
use crate::repository::create_config;
@ -158,54 +158,7 @@ fn main() {
}
if let true = matches.is_present("prune") {
let config = read_cfg();
if &config.mode != "repository" {
panic!("Cannot build packages in workspace mode")
}
let mut packages = vec![];
for untrimmed_repo in &config.repo {
pub fn trim_repo(a: String) -> String {
(a.split('/')
.map(|s| s.to_string())
.collect::<Vec<String>>()
.last()
.unwrap())
.to_string()
}
packages.push(trim_repo(untrimmed_repo.to_string()));
}
let mut packages_to_del = vec![];
for pkg in packages {
let dups = Command::new("bash")
.args(&["-c", &format!("ls out/{}*.tar.* -w 1 | sort -r", pkg)])
.output()
.unwrap()
.stdout
.to_ascii_lowercase();
let duplicates = String::from_utf8_lossy(&dups);
let duplicates_lines = duplicates.lines().collect::<Vec<&str>>();
let variable_hell = duplicates_lines.iter().skip(1).collect::<Vec<&&str>>();
if !variable_hell.is_empty() {
for var in variable_hell {
packages_to_del.push(var.to_string());
}
}
}
if !packages_to_del.is_empty() {
info(format!(
"Pruning duplicates: {}",
packages_to_del.join(", ")
));
}
for pkg in packages_to_del {
fs::remove_file(pkg).unwrap();
}
operations::prune();
}
if let true = matches.is_present("config") {

@ -3,6 +3,7 @@ use clap::ArgMatches;
mod build;
mod config;
mod init;
mod prune;
mod pull;
pub fn reinit() {
@ -24,3 +25,7 @@ pub fn pull(matches: &ArgMatches) {
pub fn config() {
config::config();
}
pub fn prune() {
prune::prune();
}

@ -0,0 +1,61 @@
use crate::{info, read_cfg};
use std::fs;
use std::process::Command;
pub fn prune() {
let config = read_cfg();
if &config.mode != "repository" {
panic!("Cannot build packages in workspace mode")
}
let mut packages = vec![];
for untrimmed_repo in &config.repo {
pub fn trim_repo(a: String) -> String {
(a.split('/')
.map(|s| s.to_string())
.collect::<Vec<String>>()
.last()
.unwrap())
.to_string()
}
packages.push(trim_repo(untrimmed_repo.to_string()));
}
let mut packages_to_del = vec![];
for pkg in packages {
let dups = Command::new("bash")
.args(&[
"-c",
&format!(
"ls out/{}*.tar.* -w 1 | grep .sig | sed 's/.sig//g' | sort -r",
pkg
),
])
.output()
.unwrap()
.stdout
.to_ascii_lowercase();
let duplicates = String::from_utf8_lossy(&dups);
let duplicates_lines = duplicates.lines().collect::<Vec<&str>>();
let variable_hell = duplicates_lines.iter().skip(1).collect::<Vec<&&str>>();
if !variable_hell.is_empty() {
for var in variable_hell {
packages_to_del.push(var.to_string());
}
}
}
if !packages_to_del.is_empty() {
info(format!(
"Pruning duplicates: {}",
packages_to_del.join(", ")
));
}
for pkg in packages_to_del {
fs::remove_file(&pkg).unwrap();
let _ = fs::remove_file(format!("{}.sig", pkg));
}
}
Loading…
Cancel
Save