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

Commit

Permalink
add: persistance system
Browse files Browse the repository at this point in the history
  • Loading branch information
saenai255 committed Sep 1, 2022
1 parent d6b843b commit 9a6a054
Show file tree
Hide file tree
Showing 9 changed files with 590 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ name = "libpacstall"
figment = { version = "0.10.6", features = ["env", "test", "toml" ] }
num_cpus = "1.13.1"
serde = { version = "1.0.144", features = ["derive"] }
chrono = { version = "0.4.22", features = ["serde"] }
serde_derive = "1.0.144"
serde_json = "1.0.85"

[dev-dependencies]
rstest = "0.15.0"
5 changes: 5 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod pacbuild;
mod repository;

pub use crate::model::pacbuild::*;
pub use crate::model::repository::Repository;
51 changes: 51 additions & 0 deletions src/model/pacbuild.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use chrono::NaiveDateTime as DateTime;
use serde_derive::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PacBuild {
pub name: PackageId,
pub last_updated: DateTime,
pub repository: URL,
pub maintainer: String,
pub package_name: String,
pub description: String,
pub homepage: URL,
pub repology_version: Version,
pub repology: URL,
pub install_state: InstallState,
pub dependencies: Vec<PackageId>,
pub optional_dependencies: Vec<PackageId>,
pub license: String,
pub url: URL,
pub kind: Kind,
}

pub type Version = String;
pub type PackageId = String;
pub type URL = String;
pub type Hash = String;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum InstallState {
Direct(DateTime, Version),
Indirect(DateTime, Version),
None,
}

impl InstallState {
pub fn is_installed(&self) -> bool {
match self {
Self::None => false,
_ => true,
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Kind {
AppImage(Hash),
Binary(Hash),
DebFile(Hash),
GitBranch,
GitRelease,
}
13 changes: 13 additions & 0 deletions src/model/repository.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use chrono::NaiveDateTime as DateTime;
use serde_derive::{Deserialize, Serialize};

use crate::model::pacbuild::PacBuild;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Repository {
pub name: String,
pub last_updated: DateTime,
pub url: String,
pub pacbuilds: Vec<PacBuild>,
pub priority: u8,
}
9 changes: 9 additions & 0 deletions src/store.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use self::storable::Storable;

mod error;
mod filesystem;
pub mod filters;
pub mod storable;

pub use error::StoreError;
pub use filesystem::FileSystemStore;
24 changes: 24 additions & 0 deletions src/store/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#[derive(Clone)]
pub struct StoreError {
pub message: String,
}

impl StoreError {
pub fn new(message: &str) -> StoreError {
StoreError {
message: message.to_string(),
}
}
}

impl std::fmt::Display for StoreError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Store error: {}", self.message)
}
}

impl std::fmt::Debug for StoreError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "[{}:{}] Store error: {}", file!(), line!(), self.message)
}
}
Loading

0 comments on commit 9a6a054

Please sign in to comment.