Skip to content
This repository was archived by the owner on May 2, 2024. It is now read-only.

Commit b3086fc

Browse files
committed
add: persistance system
1 parent 820f53e commit b3086fc

File tree

9 files changed

+591
-0
lines changed

9 files changed

+591
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ edition = "2021"
88
name = "libpacstall"
99

1010
[dependencies]
11+
chrono = { version = "0.4.22", features = ["serde"] }
12+
serde = "1.0.144"
13+
serde_derive = "1.0.144"
14+
serde_json = "1.0.85"

src/model.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod pacbuild;
2+
mod repository;
3+
4+
pub use crate::model::pacbuild::*;
5+
pub use crate::model::repository::Repository;

src/model/pacbuild.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use chrono::NaiveDateTime as DateTime;
2+
use serde_derive::{Deserialize, Serialize};
3+
4+
#[derive(Debug, Clone, Serialize, Deserialize)]
5+
pub struct PacBuild {
6+
pub name: PackageId,
7+
pub last_updated: DateTime,
8+
pub repository: URL,
9+
pub maintainer: String,
10+
pub package_name: String,
11+
pub description: String,
12+
pub homepage: URL,
13+
pub repology_version: Version,
14+
pub repology: URL,
15+
pub install_state: InstallState,
16+
pub dependencies: Vec<PackageId>,
17+
pub optional_dependencies: Vec<PackageId>,
18+
pub license: String,
19+
pub url: URL,
20+
pub kind: Kind,
21+
}
22+
23+
pub type Version = String;
24+
pub type PackageId = String;
25+
pub type URL = String;
26+
pub type Hash = String;
27+
28+
#[derive(Debug, Clone, Serialize, Deserialize)]
29+
pub enum InstallState {
30+
Direct(DateTime, Version),
31+
Indirect(DateTime, Version),
32+
None,
33+
}
34+
35+
impl InstallState {
36+
pub fn is_installed(&self) -> bool {
37+
match self {
38+
Self::None => false,
39+
_ => true,
40+
}
41+
}
42+
}
43+
44+
#[derive(Debug, Clone, Serialize, Deserialize)]
45+
pub enum Kind {
46+
AppImage(Hash),
47+
Binary(Hash),
48+
DebFile(Hash),
49+
GitBranch,
50+
GitRelease,
51+
}

src/model/repository.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use chrono::NaiveDateTime as DateTime;
2+
use serde_derive::{Deserialize, Serialize};
3+
4+
use crate::model::pacbuild::PacBuild;
5+
6+
#[derive(Debug, Clone, Serialize, Deserialize)]
7+
pub struct Repository {
8+
pub name: String,
9+
pub last_updated: DateTime,
10+
pub url: String,
11+
pub pacbuilds: Vec<PacBuild>,
12+
pub priority: u8,
13+
}

src/store.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use self::storable::Storable;
2+
3+
mod error;
4+
mod filesystem;
5+
pub mod filters;
6+
pub mod storable;
7+
8+
pub use error::StoreError;
9+
pub use filesystem::FileSystemStore;

src/store/error.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#[derive(Clone)]
2+
pub struct StoreError {
3+
pub message: String,
4+
}
5+
6+
impl StoreError {
7+
pub fn new(message: &str) -> StoreError {
8+
StoreError {
9+
message: message.to_string(),
10+
}
11+
}
12+
}
13+
14+
impl std::fmt::Display for StoreError {
15+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16+
write!(f, "Store error: {}", self.message)
17+
}
18+
}
19+
20+
impl std::fmt::Debug for StoreError {
21+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22+
write!(f, "[{}:{}] Store error: {}", file!(), line!(), self.message)
23+
}
24+
}

0 commit comments

Comments
 (0)