feat: fixed file management

This commit is contained in:
Strix 2023-10-14 22:39:39 +02:00
parent 36c782a564
commit 5083e2ba9b
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
12 changed files with 148 additions and 43 deletions

View file

@ -8,5 +8,8 @@ edition = "2021"
[dependencies]
manifest = { path = "../manifest" }
pkgfile = { path = "../pkgfile" }
toml = { version = "0.7.6", features = [ "parse" ] }
serde = { version = "1.0.171", features = ["derive"] }
regex = "1.9.1"
reqwest = { version = "0.11.18", features = ["blocking"] }
uuid = { version = "1.4.0", features = ["serde", "v4"] }

View file

@ -1,7 +1,7 @@
pub enum Command {
Strap,
Unpack,
None
None,
}
impl From<String> for Command {
@ -9,11 +9,10 @@ impl From<String> for Command {
match value.to_lowercase().as_str() {
"strap" => Command::Strap,
"unpack" => Command::Unpack,
_ => Command::None
_ => Command::None,
}
}
}
pub struct Args {
pub command: Command,
pub args: Vec<String>,
@ -23,7 +22,7 @@ impl From<Vec<String>> for Args {
fn from(value: Vec<String>) -> Self {
Args {
command: Command::from(value[0].to_owned()),
args: value[1..].to_owned()
args: value[1..].to_owned(),
}
}
}
}

View file

@ -1,10 +1,15 @@
use std::env;
use std::process::exit;
use pkgfile::PKGFile;
use crate::args::{Args, Command};
use pkgfile::PKGFile;
use std::env;
use std::env::temp_dir;
use std::fs::{create_dir, create_dir_all, File};
use std::io::Write;
use std::path::PathBuf;
use std::process::exit;
use uuid::Uuid;
mod prelude;
mod args;
mod prelude;
fn main() {
let args = Args::from(env::args().collect::<Vec<String>>()[1..].to_owned());
@ -33,7 +38,7 @@ fn main() {
}
};
let p = match PKGFile::try_from(data) {
let pkg = match PKGFile::try_from(data) {
Ok(p) => p,
Err(_) => {
println!("!! Could not interpret PKGFile...");
@ -41,8 +46,33 @@ fn main() {
}
};
},
Command::Unpack => todo!(),
let mani = prelude::mani_from_str(&pkg.manifest);
println!("!! Package: {}", &mani.package.name);
if !mani.valid() {
println!("!!! Manifest is not valid.");
exit(1);
}
let mut tmp_dir = temp_dir();
tmp_dir.push(format!("{}", Uuid::new_v4()));
create_dir_all(&tmp_dir)
.expect("Could not create tmp dir.");
{
let mut file = File::create(format!("{}/pkgtar", tmp_dir.to_str().unwrap()))
.expect("Could not create tmp pkgtar file");
file.write(&pkg.data)
.expect("Could not write pkgtar to tmp file");
}
// TODO: untar
// TODO: cd into pkg
// TODO: run bootstrap commands
}
Command::Unpack => {}
_ => {
println!("Unsupported command, allowed commands: strap/unpack.");
exit(1);

View file

@ -1,22 +1,33 @@
use std::collections::HashMap;
use manifest::Manifest;
use manifest::{self, Manifest};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, str::FromStr};
use toml;
#[derive(Serialize, Deserialize)]
pub struct PKGR {
pub bootstrap: Option<Bootstrap>,
}
pub struct Bootstrap {}
#[derive(Serialize, Deserialize)]
pub struct Bootstrap {
check_installed_commands: Vec<String>,
commands: Vec<String>
}
pub fn def_manifest() {
#[derive(Serialize, Deserialize)]
pub struct BadManifest {
pkgr: Option<PKGR>,
}
pub fn mani_from_str(s: &str) -> Manifest<Option<PKGR>> {
let mani = Manifest::from_str(s).unwrap();
let bmani = toml::from_str::<BadManifest>(s).unwrap();
Manifest::<Option<PKGR>> {
package: manifest::package::Package::default(),
bin: None,
build: None,
dependencies: HashMap::default(),
fs: manifest::fs::FS {
config: None,
data: None,
},
pkgr: Some(PKGR { bootstrap: None }),
};
}
package: mani.package,
dependencies: mani.dependencies,
fs: mani.fs,
bin: mani.bin,
build: mani.build,
pkgr: bmani.pkgr
}
}