This commit is contained in:
parent
d1882114c7
commit
bd589d8b45
15 changed files with 221 additions and 12 deletions
25
.idea/jsonSchemas.xml
Normal file
25
.idea/jsonSchemas.xml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JsonSchemaMappingsProjectConfiguration">
|
||||||
|
<state>
|
||||||
|
<map>
|
||||||
|
<entry key="Woodpecker pipeline config">
|
||||||
|
<value>
|
||||||
|
<SchemaInfo>
|
||||||
|
<option name="name" value="Woodpecker pipeline config" />
|
||||||
|
<option name="relativePathToSchema" value="https://raw.githubusercontent.com/woodpecker-ci/woodpecker/master/pipeline/schema/schema.json" />
|
||||||
|
<option name="applicationDefined" value="true" />
|
||||||
|
<option name="patterns">
|
||||||
|
<list>
|
||||||
|
<Item>
|
||||||
|
<option name="path" value=".woodpecker.yml" />
|
||||||
|
</Item>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</SchemaInfo>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</state>
|
||||||
|
</component>
|
||||||
|
</project>
|
2
build
2
build
|
@ -3,7 +3,7 @@
|
||||||
build_pkgr() {
|
build_pkgr() {
|
||||||
cd pkgr
|
cd pkgr
|
||||||
mkdir -p dist/root/{usr/bin,etc/pkgr}
|
mkdir -p dist/root/{usr/bin,etc/pkgr}
|
||||||
echo -e "You can't use pkgr to update pkgr because the file will be in use while updating.\nuse bootpkg" > dist/root/etc/pkgr/YOU-CAN-NOT-USE-PKGR-TO-UPDATE-PKGR.txt
|
echo -e "You can't use pkgr to update pkgr because the file will be in use while updating.\nuse bootpkg" > dist/root/etc/pkgr.d/YOU-CAN-NOT-USE-PKGR-TO-UPDATE-PKGR.txt
|
||||||
|
|
||||||
# for bin
|
# for bin
|
||||||
cargo build -r
|
cargo build -r
|
||||||
|
|
|
@ -25,4 +25,5 @@ reqwest = { version = "0.11.18", features = ["blocking"] }
|
||||||
tar = "0.4.39"
|
tar = "0.4.39"
|
||||||
humantime = "2.1.0"
|
humantime = "2.1.0"
|
||||||
expanduser = "1.2.2"
|
expanduser = "1.2.2"
|
||||||
url = { version = "2.4.0", features = ["serde"] }
|
url = { version = "2.4.0", features = ["serde"] }
|
||||||
|
dns-lookup = "2.0.3"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
[repo.main]
|
[repo.main]
|
||||||
name = "Main"
|
name = "Main"
|
||||||
url = "tcp://pkgs.ixvd.net:1050"
|
url = "tcp://pkgs.ixvd.net:1050"
|
||||||
|
|
||||||
|
|
|
@ -3,4 +3,5 @@ tmp_dir = "/tmp/pkgr"
|
||||||
|
|
||||||
[storage]
|
[storage]
|
||||||
repo_file = "/etc/pkgr.d/repos.toml"
|
repo_file = "/etc/pkgr.d/repos.toml"
|
||||||
data_dir = "/var/lib/pkgr/packages"
|
data_dir = "/var/lib/pkgr/packages"
|
||||||
|
index_dir = "/var/lib/pkgr/indexes"
|
20
pkgr/skel/var/lib/pkgr/indexes/repo.toml
Normal file
20
pkgr/skel/var/lib/pkgr/indexes/repo.toml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
[index.main]
|
||||||
|
last_update = "1610219288"
|
||||||
|
[index.main.packager]
|
||||||
|
versions = [1, 2, 3]
|
||||||
|
tags = ["tag"]
|
||||||
|
|
||||||
|
## rust
|
||||||
|
# IndexedPackage
|
||||||
|
# - name -> packager
|
||||||
|
# - origin_repo -> main
|
||||||
|
# - versions -> [1,2,3]
|
||||||
|
# - tags -> ["tag"]
|
||||||
|
# - get_package() -> Package
|
||||||
|
|
||||||
|
## rust
|
||||||
|
# Repo
|
||||||
|
# - name -> main
|
||||||
|
# - last_update -> 1610219288
|
||||||
|
# - update_repo() -> io::Result<()>
|
||||||
|
# - searchIndex(p: PackageIdentifier) -> IndexedPackage
|
0
pkgr/src/api/client.rs
Normal file
0
pkgr/src/api/client.rs
Normal file
|
@ -1,42 +1,60 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use serde;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
enum Query {
|
pub mod client;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub enum Query {
|
||||||
|
#[serde(rename = "pull")]
|
||||||
Pull {
|
Pull {
|
||||||
name: String,
|
name: String,
|
||||||
version: Option<u128>,
|
version: Option<u128>,
|
||||||
tags: Vec<String>
|
tags: Vec<String>
|
||||||
},
|
},
|
||||||
|
#[serde(rename = "push")]
|
||||||
Push {
|
Push {
|
||||||
|
// todo: review me pls
|
||||||
_data: Vec<u8>
|
_data: Vec<u8>
|
||||||
|
},
|
||||||
|
#[serde(rename = "index")]
|
||||||
|
Index {
|
||||||
|
request_update: bool,
|
||||||
|
fetch: bool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Request {
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct Request {
|
||||||
version: u32,
|
version: u32,
|
||||||
id: String,
|
id: String,
|
||||||
token: Option<String>,
|
token: Option<String>,
|
||||||
query: HashMap<String, Query>
|
query: HashMap<String, Query>
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DataErrorDetails {
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct DataErrorDetails {
|
||||||
actor: String,
|
actor: String,
|
||||||
detailed_cause: String,
|
detailed_cause: String,
|
||||||
recovery_options: Vec<String>,
|
recovery_options: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DataError {
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct DataError {
|
||||||
name: String,
|
name: String,
|
||||||
cause: Option<String>,
|
cause: Option<String>,
|
||||||
details: Option<DataErrorDetails>
|
details: Option<DataErrorDetails>
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Data {
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub enum Data {
|
||||||
Pull {
|
Pull {
|
||||||
_data: Option<Vec<u8>>,
|
_data: Option<Vec<u8>>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Response {
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct Response {
|
||||||
version: u32,
|
version: u32,
|
||||||
id: String,
|
id: String,
|
||||||
reply_to: String,
|
reply_to: String,
|
||||||
|
|
|
@ -22,4 +22,16 @@ impl Default for Repo {
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
pub struct RepoFile {
|
pub struct RepoFile {
|
||||||
pub repos: HashMap<String, Repo>
|
pub repos: HashMap<String, Repo>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RepoFile {
|
||||||
|
pub fn from_path(path: &str) -> Result<RepoFile, String> {
|
||||||
|
match std::fs::read_to_string(path) {
|
||||||
|
Ok(s) => match toml::from_str(&s) {
|
||||||
|
Ok(c) => Ok(c),
|
||||||
|
Err(e) => Err(format!("failed to parse config: {}", e)),
|
||||||
|
},
|
||||||
|
Err(e) => Err(format!("failed to read config: {}", e)),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -7,7 +7,10 @@ pub struct Storage {
|
||||||
pub repo_file: String,
|
pub repo_file: String,
|
||||||
/// Where to store pkgs data
|
/// Where to store pkgs data
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub data_dir: String
|
pub data_dir: String,
|
||||||
|
/// Where to store repo indexes
|
||||||
|
#[serde(default)]
|
||||||
|
pub index_dir: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Storage {
|
impl Default for Storage {
|
||||||
|
@ -15,6 +18,7 @@ impl Default for Storage {
|
||||||
Storage {
|
Storage {
|
||||||
repo_file: String::from("/etc/pkgr.d/repos.toml"),
|
repo_file: String::from("/etc/pkgr.d/repos.toml"),
|
||||||
data_dir: String::from("/var/lib/pkgr/packages"),
|
data_dir: String::from("/var/lib/pkgr/packages"),
|
||||||
|
index_dir: String::from("/var/lib/pkgr/indexes"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ mod commands;
|
||||||
mod logging;
|
mod logging;
|
||||||
/// Package and helpers.
|
/// Package and helpers.
|
||||||
mod package;
|
mod package;
|
||||||
|
/// Repo and helpers
|
||||||
|
mod repo;
|
||||||
/// Process wrapper with logging wrapper.
|
/// Process wrapper with logging wrapper.
|
||||||
mod process;
|
mod process;
|
||||||
/// tmpfs wrapper.
|
/// tmpfs wrapper.
|
||||||
|
|
18
pkgr/src/repo/index/index_package.rs
Normal file
18
pkgr/src/repo/index/index_package.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
use std::io;
|
||||||
|
use std::path::Path;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use url::Url;
|
||||||
|
use pkgfile::PKGFile;
|
||||||
|
use crate::api::Query;
|
||||||
|
use crate::CONFIG;
|
||||||
|
use crate::package::Package;
|
||||||
|
use crate::repo::index::RepoIndex;
|
||||||
|
|
||||||
|
/// This struct solely exists for indexing and has no real functionality.
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct IndexPackage {
|
||||||
|
name: String,
|
||||||
|
versions: Vec<u32>,
|
||||||
|
tags: Vec<String>,
|
||||||
|
uri: Url
|
||||||
|
}
|
58
pkgr/src/repo/index/mod.rs
Normal file
58
pkgr/src/repo/index/mod.rs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::io;
|
||||||
|
use std::path::Path;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use crate::api::Request;
|
||||||
|
use crate::CONFIG;
|
||||||
|
use crate::repo::index::index_package::IndexPackage;
|
||||||
|
use crate::repo::Repo;
|
||||||
|
use crate::types::fetch::{Fetch, TryFetch};
|
||||||
|
use crate::util::create_uuid;
|
||||||
|
|
||||||
|
pub mod index_package;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct RepoIndex {
|
||||||
|
origin_repo: String,
|
||||||
|
packages: HashMap<String, IndexPackage>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RepoIndex {
|
||||||
|
// /// Fetch existing index or create a new one.
|
||||||
|
// pub fn from_repo(repo: Repo) -> Self {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /// Create new index.
|
||||||
|
// pub fn create_with_repo(repo: Repo) -> Self {
|
||||||
|
// }
|
||||||
|
|
||||||
|
/// Get repo
|
||||||
|
pub fn get_repo(&self) -> io::Result<Repo> {
|
||||||
|
Ok(Repo::from_name(&self.origin_repo)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_path(path: &str) -> Result<RepoIndex, String> {
|
||||||
|
match std::fs::read_to_string(path) {
|
||||||
|
Ok(s) => match toml::from_str(&s) {
|
||||||
|
Ok(c) => Ok(c),
|
||||||
|
Err(e) => Err(format!("failed to parse config: {}", e)),
|
||||||
|
},
|
||||||
|
Err(e) => Err(format!("failed to read config: {}", e)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFetch<Repo> for RepoIndex {
|
||||||
|
type Error = ();
|
||||||
|
/// Fetch
|
||||||
|
fn try_fetch(query: Repo) -> Result<Self, Self::Error> {
|
||||||
|
let path = CONFIG.with(|c| c.storage.index_dir.clone()) + query.uri.as_str() + ".toml";
|
||||||
|
if Path::new(path.as_str()).exists() {
|
||||||
|
RepoIndex::from_path(path.as_str())
|
||||||
|
.map_err(|_| ())
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
pkgr/src/repo/mod.rs
Normal file
42
pkgr/src/repo/mod.rs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
use std::io;
|
||||||
|
use std::io::{Error, ErrorKind};
|
||||||
|
use std::path::Path;
|
||||||
|
use url::Url;
|
||||||
|
use crate::CONFIG;
|
||||||
|
use crate::config::repos::RepoFile;
|
||||||
|
|
||||||
|
/// Indexed repos
|
||||||
|
pub mod index;
|
||||||
|
|
||||||
|
pub struct Repo {
|
||||||
|
name: String,
|
||||||
|
uri: Url,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Repo {
|
||||||
|
pub fn from_name(name: &String) -> io::Result<Repo> {
|
||||||
|
let r = RepoFile::from_path(CONFIG.with(|c| c.storage.repo_file.clone()).as_str())
|
||||||
|
.map_err(|e| Error::new(ErrorKind::Other, e))?;
|
||||||
|
let r = r
|
||||||
|
.repos
|
||||||
|
.get(name)
|
||||||
|
.ok_or(Error::new(ErrorKind::InvalidData, "Could not get repo"))?;
|
||||||
|
Ok(Repo {
|
||||||
|
name: r.name.clone(),
|
||||||
|
uri: r.uri.clone()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_name(&self) -> String {
|
||||||
|
self.name.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_uri(&self) -> Url {
|
||||||
|
self.uri.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch indexed repo
|
||||||
|
pub fn get_index(&self) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,2 +1,9 @@
|
||||||
pub mod prompts;
|
pub mod prompts;
|
||||||
pub mod fs;
|
/// Helpers for fs
|
||||||
|
pub mod fs;
|
||||||
|
|
||||||
|
/// Create a UUID
|
||||||
|
pub fn create_uuid() -> String {
|
||||||
|
// TODO
|
||||||
|
String::from("rand")
|
||||||
|
}
|
Loading…
Reference in a new issue