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 820f53e commit b3086fc
Show file tree
Hide file tree
Showing 9 changed files with 591 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ edition = "2021"
name = "libpacstall"

[dependencies]
chrono = { version = "0.4.22", features = ["serde"] }
serde = "1.0.144"
serde_derive = "1.0.144"
serde_json = "1.0.85"
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 b3086fc

Please sign in to comment.