feat: file management and tempdir management

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

View file

@ -1,13 +1,15 @@
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::fs::{create_dir_all, File, remove_dir_all};
use std::io::Write;
use std::path::PathBuf;
use std::process::exit;
use uuid::Uuid;
use pkgfile::PKGFile;
use crate::args::{Args, Command};
mod args;
mod prelude;
@ -30,6 +32,7 @@ fn main() {
.expect("Could not turn file into bytes.")
.to_vec()
} else {
println!("** reading data...");
if let Ok(d) = std::fs::read(uri) {
d
} else {
@ -38,6 +41,7 @@ fn main() {
}
};
println!("** parsing pkgfile...");
let pkg = match PKGFile::try_from(data) {
Ok(p) => p,
Err(_) => {
@ -48,7 +52,10 @@ fn main() {
let mani = prelude::mani_from_str(&pkg.manifest);
println!("!! Package: {}", &mani.package.name);
println!("-- Package: {}", &mani.package.name);
println!("-- Description: {}", &mani.package.description);
println!("-- Version: {}", &mani.package.version);
println!("-- Tags: {}", &mani.package.tags.join(", "));
if !mani.valid() {
println!("!!! Manifest is not valid.");
@ -61,16 +68,22 @@ fn main() {
.expect("Could not create tmp dir.");
{
let mut file = File::create(format!("{}/pkgtar", tmp_dir.to_str().unwrap()))
println!("** writing tar to tmp file...");
let mut file = File::create(format!("{}/pkgtar", tmp_dir.to_str().unwrap_or("/tmp")))
.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
println!("** removing temporary directory...");
remove_dir_all(&tmp_dir)
.expect(&*format!("Could not remove tmp dir: {}", &tmp_dir.to_str().unwrap()));
}
Command::Unpack => {}
_ => {

View file

@ -1,8 +1,10 @@
use manifest::{self, Manifest};
use std::str::FromStr;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, str::FromStr};
use toml;
use manifest::{self, Manifest};
#[derive(Serialize, Deserialize)]
pub struct PKGR {
pub bootstrap: Option<Bootstrap>,

View file

@ -1,5 +1,6 @@
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct Bin {

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct Build {

View file

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, str::FromStr};
use serde::{Deserialize, Serialize};
pub mod package;
pub mod fs;
pub mod bin;

View file

@ -1,6 +1,6 @@
use std::str::FromStr;
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub enum PackageType {

View file

@ -1,4 +1,4 @@
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct PKGR {}

View file

@ -1,4 +1,5 @@
import tarfile, os
import os
import tarfile
with open("./package.toml", mode='r') as mani:
data = mani.read()