meta file content

This commit is contained in:
OMGeeky
2024-02-18 15:16:57 +01:00
parent dccb864342
commit bc2ed11bb4
6 changed files with 58 additions and 6 deletions

View File

@@ -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 "}

View File

@@ -1 +1,2 @@
pub mod drive_id;
pub mod meta;

View File

@@ -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<u8>, Vec<u8>>,
}
pub fn read_metadata_file(path: &Path) -> Result<Metadata> {
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,
}

View File

@@ -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 {