Last functionality added
This commit is contained in:
parent
038b2160bc
commit
886d27489c
55
src/main.rs
55
src/main.rs
@ -4,7 +4,7 @@ use std::io::Read;
|
|||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct Config {
|
struct Config {
|
||||||
@ -36,12 +36,14 @@ fn process_package(packages_path: &String, package_name: &String, url: &String)
|
|||||||
let folder_exists = folder_path. exists();
|
let folder_exists = folder_path. exists();
|
||||||
let repo_exists = folder_path. join(".git") . exists();
|
let repo_exists = folder_path. join(".git") . exists();
|
||||||
|
|
||||||
|
// Remove folder if it doesn't have a git repository
|
||||||
if folder_exists && !repo_exists {
|
if folder_exists && !repo_exists {
|
||||||
println!("Removing directory '{}' as it is not a valid git repository.", folder_path.clone().to_str().unwrap());
|
println!("Removing directory '{}' as it is not a valid git repository.", folder_path.clone().to_str().unwrap());
|
||||||
remove_dir_all(folder_path.clone()).unwrap();
|
remove_dir_all(folder_path.clone()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if !folder_exists {
|
// Clone the package
|
||||||
|
if !folder_exists || !repo_exists{
|
||||||
println!("Cloning package '{}' from '{}'.", package_name, url);
|
println!("Cloning package '{}' from '{}'.", package_name, url);
|
||||||
Command::new("git")
|
Command::new("git")
|
||||||
.arg("clone")
|
.arg("clone")
|
||||||
@ -51,15 +53,7 @@ fn process_package(packages_path: &String, package_name: &String, url: &String)
|
|||||||
.expect(&*format!("Could not clone '{}' to '{}'", url, package_name));
|
.expect(&*format!("Could not clone '{}' to '{}'", url, package_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// let status_information = Command::new("git")
|
// Clean the repository working tree, remove all untracked files
|
||||||
// .arg("-C")
|
|
||||||
// .arg(folder_path.clone().to_str().unwrap())
|
|
||||||
// .arg("status")
|
|
||||||
// .arg("--porcelain=v1")
|
|
||||||
// .output()
|
|
||||||
// .expect(&*format!("Could not get repository status for repository root at {}", folder_path.clone().to_str().unwrap()))
|
|
||||||
// .stdout;
|
|
||||||
|
|
||||||
Command::new("git")
|
Command::new("git")
|
||||||
.arg("-C")
|
.arg("-C")
|
||||||
.arg(folder_path.clone().to_str().unwrap())
|
.arg(folder_path.clone().to_str().unwrap())
|
||||||
@ -69,6 +63,7 @@ fn process_package(packages_path: &String, package_name: &String, url: &String)
|
|||||||
.output()
|
.output()
|
||||||
.expect(&*format!("Could not clean repository for repository root at {}", folder_path.clone().to_str().unwrap()));
|
.expect(&*format!("Could not clean repository for repository root at {}", folder_path.clone().to_str().unwrap()));
|
||||||
|
|
||||||
|
// Clean the repository working tree, restore all modified and deleted files
|
||||||
Command::new("git")
|
Command::new("git")
|
||||||
.arg("-C")
|
.arg("-C")
|
||||||
.arg(folder_path.clone().to_str().unwrap())
|
.arg(folder_path.clone().to_str().unwrap())
|
||||||
@ -77,24 +72,34 @@ fn process_package(packages_path: &String, package_name: &String, url: &String)
|
|||||||
.output()
|
.output()
|
||||||
.expect(&*format!("Could not clean repository for repository root at {}", folder_path.clone().to_str().unwrap()));
|
.expect(&*format!("Could not clean repository for repository root at {}", folder_path.clone().to_str().unwrap()));
|
||||||
|
|
||||||
// for file_status in std::str::from_utf8(&*status_information).unwrap().split('\n').into_iter() {
|
// Ensure PKGBUILD
|
||||||
// if file_status.len() < 3 {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// let status_code = file_status.chars().into_iter().take(2).collect::<String>();
|
|
||||||
// let status_path = file_status.chars().rev().into_iter().take(file_status.len() - 3).collect::<String>().chars().rev().collect::<String>();
|
|
||||||
//
|
|
||||||
// println!("{} {}", status_code, status_path);
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
if !folder_path.join("PKGBUILD").is_file() {
|
if !folder_path.join("PKGBUILD").is_file() {
|
||||||
return Err(format!("Package '{}' does not seem to have a PKGBUILD file, if this is a mistake, please delete/update the package manually.", package_name));
|
return Err(format!("Package '{}' does not seem to have a PKGBUILD file, if this is a mistake, please delete/update the package manually.", package_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("This package does {}have a folder and does {}have a repository.", if folder_exists { "" } else { "not " }, if repo_exists { "" } else { "not " });
|
// Git pull
|
||||||
|
let pull_output_u8 = Command::new("git")
|
||||||
|
.arg("-C")
|
||||||
|
.arg(folder_path.clone().to_str().unwrap())
|
||||||
|
.arg("pull")
|
||||||
|
.output()
|
||||||
|
.expect(&*format!("Could not clean repository for repository root at {}", folder_path.clone().to_str().unwrap()))
|
||||||
|
.stdout;
|
||||||
|
|
||||||
|
let pull_output = std::str::from_utf8(&*pull_output_u8).unwrap();
|
||||||
|
|
||||||
|
if !folder_exists || !repo_exists || !pull_output.starts_with("Already up to date.") {
|
||||||
|
// makepkg -sicC
|
||||||
|
println!("Package out-of-date; running `makepkg -sicC`");
|
||||||
|
Command::new("makepkg")
|
||||||
|
.arg("-sicC")
|
||||||
|
.current_dir(folder_path.clone().to_str().unwrap())
|
||||||
|
.stdin(Stdio::inherit())
|
||||||
|
.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.output()
|
||||||
|
.expect(&*format!("Could not clean repository for repository root at {}", folder_path.clone().to_str().unwrap()));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user