mirror of
https://github.com/OMGeeky/gdriver2.git
synced 2026-02-23 15:38:32 +01:00
some tracing & general restructure
This commit is contained in:
@@ -1,2 +1,9 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod drive_id;
|
||||
pub mod meta;
|
||||
#[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Serialize, Deserialize, Clone, Hash)]
|
||||
pub struct DriveObject {
|
||||
pub id: drive_id::DriveId,
|
||||
pub metadata: meta::Metadata,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::fmt::{Display, Formatter};
|
||||
lazy_static! {
|
||||
pub static ref ROOT_ID: DriveId = DriveId(String::from("root"));
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Serialize, Deserialize, Clone, Hash)]
|
||||
pub struct DriveId(pub String);
|
||||
|
||||
impl<T> From<T> for DriveId
|
||||
|
||||
@@ -3,8 +3,10 @@ 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)]
|
||||
|
||||
#[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Serialize, Deserialize, Clone, Hash)]
|
||||
pub struct Metadata {
|
||||
pub state: FileState,
|
||||
pub size: u64,
|
||||
@@ -26,14 +28,14 @@ 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)]
|
||||
#[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Serialize, Deserialize, Clone, Hash)]
|
||||
pub enum FileState {
|
||||
Downloaded,
|
||||
Cached,
|
||||
MetadataOnly,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Debug)]
|
||||
#[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Serialize, Deserialize, Clone, Hash)]
|
||||
pub enum FileKind {
|
||||
File,
|
||||
Directory,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
pub mod gdriver_service;
|
||||
pub mod gdriver_settings;
|
||||
pub mod sample;
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
use crate::prelude::*;
|
||||
use std::ffi::OsString;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::drive_structure::drive_id::DriveId;
|
||||
use crate::drive_structure::meta::FileKind;
|
||||
use crate::ipc::gdriver_settings::GDriverSettings;
|
||||
use crate::prelude::*;
|
||||
use errors::*;
|
||||
use lazy_static::lazy_static;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[tarpc::service]
|
||||
pub trait GDriverService {
|
||||
async fn get_settings() -> StdResult<GDriverSettings, GetSettingsError>;
|
||||
async fn get_file_by_name(
|
||||
name: OsString,
|
||||
parent: DriveId,
|
||||
@@ -17,7 +18,13 @@ pub trait GDriverService {
|
||||
async fn write_local_change(id: DriveId) -> StdResult<(), WriteLocalChangeError>;
|
||||
async fn get_metadata_for_file(id: DriveId) -> StdResult<(), GetMetadataError>;
|
||||
async fn download_content_for_file(id: DriveId) -> StdResult<(), GetContentError>;
|
||||
async fn list_files_in_directory(id: DriveId) -> StdResult<(), GetFileListError>;
|
||||
async fn list_files_in_directory(
|
||||
id: DriveId,
|
||||
) -> StdResult<Vec<ReadDirResult>, GetFileListError>;
|
||||
async fn list_files_in_directory_with_offset(
|
||||
id: DriveId,
|
||||
offset: u64,
|
||||
) -> StdResult<Vec<ReadDirResult>, GetFileListError>;
|
||||
async fn mark_file_as_deleted(id: DriveId) -> StdResult<(), MarkFileAsDeletedError>;
|
||||
async fn mark_file_for_keeping_local(
|
||||
id: DriveId,
|
||||
@@ -39,49 +46,10 @@ pub enum BackendActionRequest {
|
||||
StartLong,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct GDriverSettings {
|
||||
metadata_path: PathBuf,
|
||||
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
|
||||
}
|
||||
|
||||
pub fn get_metadata_file_path(&self, id: &DriveId) -> PathBuf {
|
||||
self.metadata_path.join(id.as_ref()).with_extension("meta")
|
||||
}
|
||||
pub fn get_downloaded_file_path(&self, id: &DriveId) -> PathBuf {
|
||||
self.downloaded_path.join(id.as_ref())
|
||||
}
|
||||
pub fn get_cache_file_path(&self, id: &DriveId) -> PathBuf {
|
||||
self.cache_path.join(id.as_ref())
|
||||
}
|
||||
lazy_static! {
|
||||
pub static ref SETTINGS: GDriverSettings = GDriverSettings::default();
|
||||
}
|
||||
|
||||
impl Default for GDriverSettings {
|
||||
fn default() -> Self {
|
||||
let p = directories::ProjectDirs::from("com", "OMGeeky", "gdriver2").expect(
|
||||
"Getting the Project dir needs to work (on all platforms) otherwise nothing will work as expected. \
|
||||
This is where all files will be stored, so there is not much use for this app without it.",
|
||||
);
|
||||
Self {
|
||||
metadata_path: p.data_dir().join("meta"),
|
||||
downloaded_path: p.data_dir().join("downloads"),
|
||||
cache_path: p.cache_dir().to_path_buf(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use errors::*;
|
||||
pub mod errors {
|
||||
use super::*;
|
||||
#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
|
||||
@@ -125,10 +93,26 @@ pub mod errors {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
|
||||
pub enum GetFileByPathError {}
|
||||
pub enum GetFileByPathError {
|
||||
#[error("Other")]
|
||||
Other,
|
||||
#[error("The Specified name is invalid")]
|
||||
InvalidName,
|
||||
#[error("Could not find name specified")]
|
||||
NotFound,
|
||||
#[error("Could not update drive info")]
|
||||
Update(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
|
||||
pub enum UpdateChangesError {}
|
||||
pub enum UpdateChangesError {
|
||||
#[error("Other")]
|
||||
Other,
|
||||
#[error("Remote error")]
|
||||
Remote,
|
||||
#[error("Already running")]
|
||||
Running,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
|
||||
pub enum WriteLocalChangeError {
|
||||
@@ -143,22 +127,47 @@ pub mod errors {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
|
||||
pub enum GetMetadataError {}
|
||||
pub enum GetMetadataError {
|
||||
#[error("Other")]
|
||||
Other,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
|
||||
pub enum GetContentError {}
|
||||
pub enum GetContentError {
|
||||
#[error("Other")]
|
||||
Other,
|
||||
}
|
||||
|
||||
//#[derive(Debug, Serialize, Deserialize)]
|
||||
//pub enum GetContentError {}
|
||||
#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
|
||||
pub enum GetFileListError {}
|
||||
pub enum GetFileListError {
|
||||
#[error("Other")]
|
||||
Other,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
|
||||
pub enum MarkFileAsDeletedError {}
|
||||
pub enum MarkFileAsDeletedError {
|
||||
#[error("Other")]
|
||||
Other,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
|
||||
pub enum MarkFileForKeepingLocalError {}
|
||||
pub enum MarkFileForKeepingLocalError {
|
||||
#[error("Other")]
|
||||
Other,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, thiserror::Error)]
|
||||
pub enum UnmarkFileForKeepingLocalError {}
|
||||
pub enum UnmarkFileForKeepingLocalError {
|
||||
#[error("Other")]
|
||||
Other,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Ord, PartialOrd, Eq, PartialEq, Debug, Serialize, Deserialize, Clone, Hash)]
|
||||
pub struct ReadDirResult {
|
||||
pub id: DriveId,
|
||||
pub kind: FileKind,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
53
gdriver-common/src/ipc/gdriver_settings.rs
Normal file
53
gdriver-common/src/ipc/gdriver_settings.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use crate::prelude::DriveId;
|
||||
use crate::project_dirs::PROJECT_DIRS;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct GDriverSettings {
|
||||
metadata_path: PathBuf,
|
||||
cache_path: PathBuf,
|
||||
downloaded_path: PathBuf,
|
||||
data_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
|
||||
}
|
||||
pub fn data_path(&self) -> &Path {
|
||||
&self.data_path
|
||||
}
|
||||
|
||||
pub fn get_changes_file_path(&self) -> PathBuf {
|
||||
self.data_path.join("changes.txt")
|
||||
}
|
||||
|
||||
pub fn get_metadata_file_path(&self, id: &DriveId) -> PathBuf {
|
||||
self.metadata_path.join(id.as_ref()).with_extension("meta")
|
||||
}
|
||||
pub fn get_downloaded_file_path(&self, id: &DriveId) -> PathBuf {
|
||||
self.downloaded_path.join(id.as_ref())
|
||||
}
|
||||
pub fn get_cache_file_path(&self, id: &DriveId) -> PathBuf {
|
||||
self.cache_path.join(id.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GDriverSettings {
|
||||
fn default() -> Self {
|
||||
let p = &PROJECT_DIRS;
|
||||
Self {
|
||||
metadata_path: p.data_dir().join("meta"),
|
||||
downloaded_path: p.data_dir().join("downloads"),
|
||||
cache_path: p.cache_dir().to_path_buf(),
|
||||
data_path: p.data_dir().join("data"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,4 +5,5 @@ pub mod prelude;
|
||||
pub mod config;
|
||||
pub mod drive_structure;
|
||||
pub mod ipc;
|
||||
pub mod project_dirs;
|
||||
pub mod tracing_setup;
|
||||
|
||||
7
gdriver-common/src/project_dirs.rs
Normal file
7
gdriver-common/src/project_dirs.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
use lazy_static::lazy_static;
|
||||
lazy_static!(
|
||||
pub static ref PROJECT_DIRS: directories::ProjectDirs = directories::ProjectDirs::from("com", "OMGeeky", "gdriver2").expect(
|
||||
"Getting the Project dir needs to work (on all platforms) otherwise nothing will work as expected. \
|
||||
This is where all files will be stored, so there is not much use for this app without it.",
|
||||
);
|
||||
);
|
||||
Reference in New Issue
Block a user