mirror of
https://github.com/OMGeeky/gdriver2.git
synced 2026-02-23 15:38:32 +01:00
meta file content
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -432,6 +432,7 @@ dependencies = [
|
|||||||
"futures",
|
"futures",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"tarpc",
|
"tarpc",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|||||||
@@ -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
|
the meta folder, this file will always be created (or updated), no matter if only the content or only the metadata was
|
||||||
requested.
|
requested.
|
||||||
|
|
||||||
The meta file will be a simple UTF-8 file, containing a number from 0 to 2:
|
The meta file will be a simple UTF-8 json-file, containing the metadata of the file and the download state
|
||||||
|
(MetadataOnly/Cached/Downloaded)
|
||||||
- 0: only metadata was fetched, no content available
|
|
||||||
- 1: content was fetched to cache
|
|
||||||
- 2: content was fetched to downloads
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -15,5 +15,6 @@ confique={ version = "0.2" }
|
|||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
anyhow = "1.0.79"
|
anyhow = "1.0.79"
|
||||||
directories = "5.0"
|
directories = "5.0"
|
||||||
|
serde_json = "1.0.111"
|
||||||
#[patch.crates-io]
|
#[patch.crates-io]
|
||||||
#confique = {path="~/Documents/git/OMGeeky/confique "}
|
#confique = {path="~/Documents/git/OMGeeky/confique "}
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
pub mod drive_id;
|
pub mod drive_id;
|
||||||
|
pub mod meta;
|
||||||
|
|||||||
41
gdriver-common/src/drive_structure/meta.rs
Normal file
41
gdriver-common/src/drive_structure/meta.rs
Normal 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,
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@@ -45,6 +45,17 @@ pub struct GDriverSettings {
|
|||||||
cache_path: PathBuf,
|
cache_path: PathBuf,
|
||||||
downloaded_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 {
|
impl Default for GDriverSettings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
|||||||
Reference in New Issue
Block a user