From bc2ed11bb44634d283b3d522e44024d813fedbf5 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Sun, 18 Feb 2024 15:16:57 +0100 Subject: [PATCH] meta file content --- Cargo.lock | 1 + concept.md | 7 ++-- gdriver-common/Cargo.toml | 1 + gdriver-common/src/drive_structure.rs | 1 + gdriver-common/src/drive_structure/meta.rs | 41 ++++++++++++++++++++++ gdriver-common/src/ipc/gdriver_service.rs | 13 ++++++- 6 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 gdriver-common/src/drive_structure/meta.rs diff --git a/Cargo.lock b/Cargo.lock index 71a6c49..ff53a12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -432,6 +432,7 @@ dependencies = [ "futures", "lazy_static", "serde", + "serde_json", "tarpc", "thiserror", "tokio", diff --git a/concept.md b/concept.md index 09fe53e..cac3fbd 100644 --- a/concept.md +++ b/concept.md @@ -27,11 +27,8 @@ the filename being the file id with no extension. The metadata will be on a file the meta folder, this file will always be created (or updated), no matter if only the content or only the metadata was requested. -The meta file will be a simple UTF-8 file, containing a number from 0 to 2: - -- 0: only metadata was fetched, no content available -- 1: content was fetched to cache -- 2: content was fetched to downloads +The meta file will be a simple UTF-8 json-file, containing the metadata of the file and the download state +(MetadataOnly/Cached/Downloaded) --- diff --git a/gdriver-common/Cargo.toml b/gdriver-common/Cargo.toml index 5245780..7718525 100644 --- a/gdriver-common/Cargo.toml +++ b/gdriver-common/Cargo.toml @@ -15,5 +15,6 @@ confique={ version = "0.2" } thiserror = "1.0" anyhow = "1.0.79" directories = "5.0" +serde_json = "1.0.111" #[patch.crates-io] #confique = {path="~/Documents/git/OMGeeky/confique "} diff --git a/gdriver-common/src/drive_structure.rs b/gdriver-common/src/drive_structure.rs index 31aafdb..5ef6a77 100644 --- a/gdriver-common/src/drive_structure.rs +++ b/gdriver-common/src/drive_structure.rs @@ -1 +1,2 @@ pub mod drive_id; +pub mod meta; diff --git a/gdriver-common/src/drive_structure/meta.rs b/gdriver-common/src/drive_structure/meta.rs new file mode 100644 index 0000000..7ffe012 --- /dev/null +++ b/gdriver-common/src/drive_structure/meta.rs @@ -0,0 +1,41 @@ +use crate::prelude::*; +use serde::{Deserialize, Serialize}; +use std::collections::BTreeMap; +use std::fs::File; +use std::path::Path; +pub type TIMESTAMP = (i64, u32); +#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)] +pub struct Metadata { + pub state: FileState, + pub size: u64, + pub last_accessed: TIMESTAMP, + pub last_modified: TIMESTAMP, + pub last_metadata_changed: TIMESTAMP, + pub kind: FileKind, + pub mode: u16, + pub hardlinks: u32, + pub uid: u32, + pub gid: u32, + pub xattrs: BTreeMap, Vec>, +} +pub fn read_metadata_file(path: &Path) -> Result { + let reader = File::open(path)?; + Ok(serde_json::from_reader(reader)?) +} +pub fn write_metadata_file(path: &Path, metadata: &Metadata) -> Result<()> { + let reader = File::open(path)?; + Ok(serde_json::to_writer(reader, metadata)?) +} +#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Debug)] +pub enum FileState { + Downloaded, + Cached, + MetadataOnly, +} + +#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Debug)] +pub enum FileKind { + File, + Directory, + Symlink, +} diff --git a/gdriver-common/src/ipc/gdriver_service.rs b/gdriver-common/src/ipc/gdriver_service.rs index 65d3780..287d97c 100644 --- a/gdriver-common/src/ipc/gdriver_service.rs +++ b/gdriver-common/src/ipc/gdriver_service.rs @@ -1,6 +1,6 @@ use crate::prelude::*; use std::ffi::OsString; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use serde::{Deserialize, Serialize}; @@ -45,6 +45,17 @@ pub struct GDriverSettings { cache_path: PathBuf, downloaded_path: PathBuf, } +impl GDriverSettings { + pub fn metadata_path(&self) -> &Path { + &self.metadata_path + } + pub fn cache_path(&self) -> &Path { + &self.cache_path + } + pub fn downloaded_path(&self) -> &Path { + &self.downloaded_path + } +} impl Default for GDriverSettings { fn default() -> Self {