feat: file management and tempdir management
This commit is contained in:
		
							parent
							
								
									68bb6822ed
								
							
						
					
					
						commit
						6182032799
					
				
					 8 changed files with 32 additions and 14 deletions
				
			
		|  | @ -1,13 +1,15 @@ | ||||||
| use crate::args::{Args, Command}; |  | ||||||
| use pkgfile::PKGFile; |  | ||||||
| use std::env; | use std::env; | ||||||
| use std::env::temp_dir; | 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::io::Write; | ||||||
| use std::path::PathBuf; |  | ||||||
| use std::process::exit; | use std::process::exit; | ||||||
|  | 
 | ||||||
| use uuid::Uuid; | use uuid::Uuid; | ||||||
| 
 | 
 | ||||||
|  | use pkgfile::PKGFile; | ||||||
|  | 
 | ||||||
|  | use crate::args::{Args, Command}; | ||||||
|  | 
 | ||||||
| mod args; | mod args; | ||||||
| mod prelude; | mod prelude; | ||||||
| 
 | 
 | ||||||
|  | @ -30,6 +32,7 @@ fn main() { | ||||||
|                     .expect("Could not turn file into bytes.") |                     .expect("Could not turn file into bytes.") | ||||||
|                     .to_vec() |                     .to_vec() | ||||||
|             } else { |             } else { | ||||||
|  |                 println!("** reading data..."); | ||||||
|                 if let Ok(d) = std::fs::read(uri) { |                 if let Ok(d) = std::fs::read(uri) { | ||||||
|                     d |                     d | ||||||
|                 } else { |                 } else { | ||||||
|  | @ -38,6 +41,7 @@ fn main() { | ||||||
|                 } |                 } | ||||||
|             }; |             }; | ||||||
| 
 | 
 | ||||||
|  |             println!("** parsing pkgfile..."); | ||||||
|             let pkg = match PKGFile::try_from(data) { |             let pkg = match PKGFile::try_from(data) { | ||||||
|                 Ok(p) => p, |                 Ok(p) => p, | ||||||
|                 Err(_) => { |                 Err(_) => { | ||||||
|  | @ -48,7 +52,10 @@ fn main() { | ||||||
| 
 | 
 | ||||||
|             let mani = prelude::mani_from_str(&pkg.manifest); |             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() { |             if !mani.valid() { | ||||||
|                 println!("!!! Manifest is not valid."); |                 println!("!!! Manifest is not valid."); | ||||||
|  | @ -61,16 +68,22 @@ fn main() { | ||||||
|                 .expect("Could not create tmp dir."); |                 .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"); |                     .expect("Could not create tmp pkgtar file"); | ||||||
| 
 | 
 | ||||||
|                 file.write(&pkg.data) |                 file.write(&pkg.data) | ||||||
|                     .expect("Could not write pkgtar to tmp file"); |                     .expect("Could not write pkgtar to tmp file"); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|             // TODO: untar
 |             // TODO: untar
 | ||||||
|             // TODO: cd into pkg
 |             // TODO: cd into pkg
 | ||||||
|             // TODO: run bootstrap commands
 |             // 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 => {} |         Command::Unpack => {} | ||||||
|         _ => { |         _ => { | ||||||
|  |  | ||||||
|  | @ -1,8 +1,10 @@ | ||||||
| use manifest::{self, Manifest}; | use std::str::FromStr; | ||||||
|  | 
 | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| use std::{collections::HashMap, str::FromStr}; |  | ||||||
| use toml; | use toml; | ||||||
| 
 | 
 | ||||||
|  | use manifest::{self, Manifest}; | ||||||
|  | 
 | ||||||
| #[derive(Serialize, Deserialize)] | #[derive(Serialize, Deserialize)] | ||||||
| pub struct PKGR { | pub struct PKGR { | ||||||
|     pub bootstrap: Option<Bootstrap>, |     pub bootstrap: Option<Bootstrap>, | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
| use serde::{Serialize, Deserialize}; | 
 | ||||||
|  | use serde::{Deserialize, Serialize}; | ||||||
| 
 | 
 | ||||||
| #[derive(Serialize, Deserialize)] | #[derive(Serialize, Deserialize)] | ||||||
| pub struct Bin { | pub struct Bin { | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
| 
 | 
 | ||||||
| use serde::{Serialize, Deserialize}; | use serde::{Deserialize, Serialize}; | ||||||
| 
 | 
 | ||||||
| #[derive(Serialize, Deserialize)] | #[derive(Serialize, Deserialize)] | ||||||
| pub struct Build { | pub struct Build { | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| use serde::{Deserialize, Serialize}; |  | ||||||
| use std::{collections::HashMap, str::FromStr}; | use std::{collections::HashMap, str::FromStr}; | ||||||
| 
 | 
 | ||||||
|  | use serde::{Deserialize, Serialize}; | ||||||
|  | 
 | ||||||
| pub mod package; | pub mod package; | ||||||
| pub mod fs; | pub mod fs; | ||||||
| pub mod bin; | pub mod bin; | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| use std::str::FromStr; | use std::str::FromStr; | ||||||
| 
 | 
 | ||||||
| use serde::{Serialize, Deserialize}; | use serde::{Deserialize, Serialize}; | ||||||
| 
 | 
 | ||||||
| #[derive(Serialize, Deserialize, Debug)] | #[derive(Serialize, Deserialize, Debug)] | ||||||
| pub enum PackageType { | pub enum PackageType { | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| use serde::{Serialize, Deserialize}; | use serde::{Deserialize, Serialize}; | ||||||
| 
 | 
 | ||||||
| #[derive(Serialize, Deserialize)] | #[derive(Serialize, Deserialize)] | ||||||
| pub struct PKGR {} | pub struct PKGR {} | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| import tarfile, os | import os | ||||||
|  | import tarfile | ||||||
| 
 | 
 | ||||||
| with open("./package.toml", mode='r') as mani: | with open("./package.toml", mode='r') as mani: | ||||||
|     data = mani.read() |     data = mani.read() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue