feat: fixed file management
This commit is contained in:
parent
36c782a564
commit
5083e2ba9b
12 changed files with 148 additions and 43 deletions
|
@ -1,5 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module type="CPP_MODULE" version="4">
|
<module type="CPP_MODULE" version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="Python" name="Python facet">
|
||||||
|
<configuration sdkName="Python 3.11" />
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/bootpkg/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/bootpkg/src" isTestSource="false" />
|
||||||
|
@ -13,5 +18,6 @@
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="Python 3.11 interpreter library" level="application" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
|
@ -8,5 +8,8 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
manifest = { path = "../manifest" }
|
manifest = { path = "../manifest" }
|
||||||
pkgfile = { path = "../pkgfile" }
|
pkgfile = { path = "../pkgfile" }
|
||||||
|
toml = { version = "0.7.6", features = [ "parse" ] }
|
||||||
|
serde = { version = "1.0.171", features = ["derive"] }
|
||||||
regex = "1.9.1"
|
regex = "1.9.1"
|
||||||
reqwest = { version = "0.11.18", features = ["blocking"] }
|
reqwest = { version = "0.11.18", features = ["blocking"] }
|
||||||
|
uuid = { version = "1.4.0", features = ["serde", "v4"] }
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
Strap,
|
Strap,
|
||||||
Unpack,
|
Unpack,
|
||||||
None
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for Command {
|
impl From<String> for Command {
|
||||||
|
@ -9,11 +9,10 @@ impl From<String> for Command {
|
||||||
match value.to_lowercase().as_str() {
|
match value.to_lowercase().as_str() {
|
||||||
"strap" => Command::Strap,
|
"strap" => Command::Strap,
|
||||||
"unpack" => Command::Unpack,
|
"unpack" => Command::Unpack,
|
||||||
_ => Command::None
|
_ => Command::None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
pub command: Command,
|
pub command: Command,
|
||||||
pub args: Vec<String>,
|
pub args: Vec<String>,
|
||||||
|
@ -23,7 +22,7 @@ impl From<Vec<String>> for Args {
|
||||||
fn from(value: Vec<String>) -> Self {
|
fn from(value: Vec<String>) -> Self {
|
||||||
Args {
|
Args {
|
||||||
command: Command::from(value[0].to_owned()),
|
command: Command::from(value[0].to_owned()),
|
||||||
args: value[1..].to_owned()
|
args: value[1..].to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,15 @@
|
||||||
use std::env;
|
|
||||||
use std::process::exit;
|
|
||||||
use pkgfile::PKGFile;
|
|
||||||
use crate::args::{Args, Command};
|
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 args;
|
||||||
|
mod prelude;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::from(env::args().collect::<Vec<String>>()[1..].to_owned());
|
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,
|
Ok(p) => p,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("!! Could not interpret PKGFile...");
|
println!("!! Could not interpret PKGFile...");
|
||||||
|
@ -41,8 +46,33 @@ fn main() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
},
|
let mani = prelude::mani_from_str(&pkg.manifest);
|
||||||
Command::Unpack => todo!(),
|
|
||||||
|
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.");
|
println!("Unsupported command, allowed commands: strap/unpack.");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
@ -1,22 +1,33 @@
|
||||||
use std::collections::HashMap;
|
use manifest::{self, Manifest};
|
||||||
use manifest::Manifest;
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{collections::HashMap, str::FromStr};
|
||||||
|
use toml;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct PKGR {
|
pub struct PKGR {
|
||||||
pub bootstrap: Option<Bootstrap>,
|
pub bootstrap: Option<Bootstrap>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Bootstrap {}
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct Bootstrap {
|
||||||
pub fn def_manifest() {
|
check_installed_commands: Vec<String>,
|
||||||
Manifest::<Option<PKGR>> {
|
commands: Vec<String>
|
||||||
package: manifest::package::Package::default(),
|
}
|
||||||
bin: None,
|
|
||||||
build: None,
|
#[derive(Serialize, Deserialize)]
|
||||||
dependencies: HashMap::default(),
|
pub struct BadManifest {
|
||||||
fs: manifest::fs::FS {
|
pkgr: Option<PKGR>,
|
||||||
config: None,
|
}
|
||||||
data: None,
|
|
||||||
},
|
pub fn mani_from_str(s: &str) -> Manifest<Option<PKGR>> {
|
||||||
pkgr: Some(PKGR { bootstrap: None }),
|
let mani = Manifest::from_str(s).unwrap();
|
||||||
};
|
let bmani = toml::from_str::<BadManifest>(s).unwrap();
|
||||||
|
Manifest::<Option<PKGR>> {
|
||||||
|
package: mani.package,
|
||||||
|
dependencies: mani.dependencies,
|
||||||
|
fs: mani.fs,
|
||||||
|
bin: mani.bin,
|
||||||
|
build: mani.build,
|
||||||
|
pkgr: bmani.pkgr
|
||||||
|
}
|
||||||
}
|
}
|
3
docs/pkgr/flow.md
Normal file
3
docs/pkgr/flow.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Install flow
|
||||||
|
|
||||||
|
pkgr keeps track of installed files and therefore we have a CTREE.
|
|
@ -1,7 +1,8 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Bin {
|
pub struct Bin {
|
||||||
pub root: String,
|
pub root: String,
|
||||||
|
pub checksums: HashMap<String, String>
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::{collections::HashMap, str::FromStr};
|
||||||
|
|
||||||
pub mod package;
|
pub mod package;
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
|
@ -18,6 +18,22 @@ pub struct Manifest<P = Option<pkgr::PKGR>> {
|
||||||
pub pkgr: P
|
pub pkgr: P
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Manifest<T> {
|
||||||
|
pub fn valid(&self) -> bool {
|
||||||
|
if self.bin.is_none() && self.build.is_none() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for Manifest {
|
||||||
|
type Err = toml::de::Error;
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
toml::from_str(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for Manifest {
|
impl Default for Manifest {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Manifest {
|
Manifest {
|
||||||
|
|
22
mock-pkg.py
Normal file
22
mock-pkg.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import tarfile, os
|
||||||
|
|
||||||
|
with open("./package.toml", mode='r') as mani:
|
||||||
|
data = mani.read()
|
||||||
|
with open("./mock.pkg", mode='wb') as pkg:
|
||||||
|
print("building header...")
|
||||||
|
pkg.write(bytes([0x01, (len(data) >> 8) & 0xFF, len(data) & 0xFF]))
|
||||||
|
print("writing manifest into pkg...")
|
||||||
|
pkg.write(data.encode("utf-8"))
|
||||||
|
with tarfile.TarFile("/tmp/pkgtar", 'w') as pkgtar:
|
||||||
|
for root, dirs, files in os.walk("."):
|
||||||
|
for file in files:
|
||||||
|
print(f"\33[2Kadd: {file}", end="\r", flush=True)
|
||||||
|
pkgtar.add(os.path.join(root, file))
|
||||||
|
with open("/tmp/pkgtar", 'rb') as pkgtar:
|
||||||
|
print("appending pkgtar to pkg...")
|
||||||
|
pkg.write(pkgtar.read())
|
||||||
|
print("deleting /tmp/pkgtar...")
|
||||||
|
os.unlink("/tmp/pkgtar")
|
||||||
|
print("closing write stream")
|
||||||
|
pkg.close()
|
||||||
|
|
19
package.toml
19
package.toml
|
@ -18,10 +18,7 @@ version = 1 # this can automatically be incremented when publishing by running `
|
||||||
# previous version will lose this tag
|
# previous version will lose this tag
|
||||||
# - oldest
|
# - oldest
|
||||||
# assigned to the first version.
|
# assigned to the first version.
|
||||||
tags = [
|
tags = [ "prod", "pkgr-spec-1" ]
|
||||||
"prod",
|
|
||||||
"pkgr-spec-1"
|
|
||||||
]
|
|
||||||
|
|
||||||
## package.type
|
## package.type
|
||||||
# Supported types:
|
# Supported types:
|
||||||
|
@ -39,7 +36,7 @@ arch = "x86_64" # this is automatically filled by `pkgr publish ...`
|
||||||
# you may use the following syntax
|
# you may use the following syntax
|
||||||
# "<version/tag>" or "<version/tag>,<version/tag>,..."
|
# "<version/tag>" or "<version/tag>,<version/tag>,..."
|
||||||
[dependencies]
|
[dependencies]
|
||||||
example = { arch = "x86_64", tags = [ "stable" ], version = "v1" }
|
#example = { arch = "x86_64", tags = [ "stable" ], version = "v1" }
|
||||||
exnmbr2 = "v1,stable"
|
exnmbr2 = "v1,stable"
|
||||||
|
|
||||||
## fs
|
## fs
|
||||||
|
@ -97,14 +94,12 @@ base = "latest,stable" # selected by default
|
||||||
# This exists so that packager is easy to install on anything!
|
# This exists so that packager is easy to install on anything!
|
||||||
# and only 1 release channel for pkgr
|
# and only 1 release channel for pkgr
|
||||||
[pkgr.bootstrap]
|
[pkgr.bootstrap]
|
||||||
# any non-zero = installed
|
## any non-zero = installed
|
||||||
check_installed_commands = [
|
check_installed_commands = [ "/scripts/check_installed" ]
|
||||||
"/scripts/check_installed"
|
|
||||||
]
|
|
||||||
|
|
||||||
# any non-zero = fail
|
# any non-zero = fail
|
||||||
commands = [
|
commands = [
|
||||||
"/scripts/bootstrap/download_latest @version /tmp/pkgr.pkg",
|
"/scripts/bootstrap/download_latest @version /tmp/pkgr.pkg",
|
||||||
"/scripts/bootstrap/dirty_install /tmp/pkgr.pkg",
|
"/scripts/bootstrap/dirty_install /tmp/pkgr.pkg",
|
||||||
"/scripts/bootstrap/check_install"
|
"/scripts/bootstrap/check_install"
|
||||||
]
|
]
|
||||||
|
|
7
pkg/scripts/bootstrap/download_latest
Normal file
7
pkg/scripts/bootstrap/download_latest
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
fetch_latest_version() {
|
||||||
|
}
|
||||||
|
|
||||||
|
download_file() {
|
||||||
|
}
|
|
@ -20,17 +20,29 @@ impl TryFrom<Vec<u8>> for PKGFile {
|
||||||
Ok(PKGFile {
|
Ok(PKGFile {
|
||||||
manifest: match String::from_utf8(
|
manifest: match String::from_utf8(
|
||||||
value[
|
value[
|
||||||
3..(manifest_size as usize)
|
3..(manifest_size as usize + 3)
|
||||||
].to_vec()
|
].to_vec()
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
_ => return Err(())
|
_ => return Err(())
|
||||||
},
|
},
|
||||||
data: value[(manifest_size as usize)..].to_vec(),
|
data: value[(manifest_size as usize + 3)..].to_vec(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
_ => Err(())
|
_ => Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Into<Vec<u8>> for PKGFile {
|
||||||
|
fn into(self) -> Vec<u8> {
|
||||||
|
let mut bytes = vec![0x01];
|
||||||
|
let manifest_bytes = self.manifest.into_bytes();
|
||||||
|
bytes.push((manifest_bytes.len() >> 8) as u8);
|
||||||
|
bytes.push((manifest_bytes.len() | 0xFF) as u8);
|
||||||
|
bytes.extend(manifest_bytes);
|
||||||
|
bytes.extend(self.data);
|
||||||
|
bytes
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue