Last functionality added

This commit is contained in:
Daniel_I_Am 2021-02-16 16:13:25 +01:00
parent 038b2160bc
commit 886d27489c
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84

View File

@ -4,7 +4,7 @@ use std::io::Read;
use serde_derive::Deserialize;
use std::collections::HashMap;
use std::path::Path;
use std::process::Command;
use std::process::{Command, Stdio};
#[derive(Deserialize, Debug)]
struct Config {
@ -36,12 +36,14 @@ fn process_package(packages_path: &String, package_name: &String, url: &String)
let folder_exists = folder_path. exists();
let repo_exists = folder_path. join(".git") . exists();
// Remove folder if it doesn't have a git repository
if folder_exists && !repo_exists {
println!("Removing directory '{}' as it is not a valid git repository.", folder_path.clone().to_str().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);
Command::new("git")
.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));
}
// let status_information = Command::new("git")
// .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;
// Clean the repository working tree, remove all untracked files
Command::new("git")
.arg("-C")
.arg(folder_path.clone().to_str().unwrap())
@ -69,6 +63,7 @@ fn process_package(packages_path: &String, package_name: &String, url: &String)
.output()
.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")
.arg("-C")
.arg(folder_path.clone().to_str().unwrap())
@ -77,24 +72,34 @@ fn process_package(packages_path: &String, package_name: &String, url: &String)
.output()
.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() {
// 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);
//
//
// }
// Ensure PKGBUILD
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));
}
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(())
}