From 3c75f864c533de1da9c252a49ca2fb00ca680dba Mon Sep 17 00:00:00 2001 From: Jamie Pine Date: Thu, 14 Apr 2022 14:52:35 -0700 Subject: [PATCH] fixes, abolish underscores, folder restructure --- .vscode/settings.json | 1 + Cargo.lock | 2 +- core/src/encode/mod.rs | 1 + core/src/{file => encode}/thumb.rs | 0 core/src/encode/{video_thumb.rs => vthumb.rs} | 0 .../{video_thumbstrip.rs => vthumbstrip.rs} | 0 core/src/file/explorer/open.rs | 3 +- core/src/file/indexer/mod.rs | 36 +++++++++++++++++++ core/src/file/indexer/pathctx.rs | 13 +++++++ core/src/file/{indexer.rs => indexer/scan.rs} | 31 +--------------- core/src/file/mod.rs | 1 - core/src/lib.rs | 2 +- .../crdt/{property_operation.rs => propop.rs} | 0 13 files changed, 56 insertions(+), 34 deletions(-) rename core/src/{file => encode}/thumb.rs (100%) rename core/src/encode/{video_thumb.rs => vthumb.rs} (100%) rename core/src/encode/{video_thumbstrip.rs => vthumbstrip.rs} (100%) create mode 100644 core/src/file/indexer/mod.rs create mode 100644 core/src/file/indexer/pathctx.rs rename core/src/file/{indexer.rs => indexer/scan.rs} (90%) rename core/src/sync/crdt/{property_operation.rs => propop.rs} (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 319a86bb8..6d195a327 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "creationdate", "ipfs", "Keepsafe", + "pathctx", "quicktime", "repr", "tailwindcss" diff --git a/Cargo.lock b/Cargo.lock index 47d8469bb..2fef1c3a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5768,7 +5768,7 @@ checksum = "be91bcc43e73799dc46a6c194a55e7aae1d86cc867c860fd4a436019af21bd8c" [[package]] name = "prisma-client-rust" version = "0.3.1" -source = "git+https://github.com/Brendonovich/prisma-client-rust.git?rev=eb7a7804518f68933ce313ae6226b882b22b81f8#eb7a7804518f68933ce313ae6226b882b22b81f8" +source = "git+https://github.com/Brendonovich/prisma-client-rust.git?rev=3f742cc4fb4df9a77c6311d43183d5082cf32510#3f742cc4fb4df9a77c6311d43183d5082cf32510" dependencies = [ "chrono", "datamodel", diff --git a/core/src/encode/mod.rs b/core/src/encode/mod.rs index de5643fda..27ea94f34 100644 --- a/core/src/encode/mod.rs +++ b/core/src/encode/mod.rs @@ -1 +1,2 @@ pub mod metadata; +pub mod thumb; diff --git a/core/src/file/thumb.rs b/core/src/encode/thumb.rs similarity index 100% rename from core/src/file/thumb.rs rename to core/src/encode/thumb.rs diff --git a/core/src/encode/video_thumb.rs b/core/src/encode/vthumb.rs similarity index 100% rename from core/src/encode/video_thumb.rs rename to core/src/encode/vthumb.rs diff --git a/core/src/encode/video_thumbstrip.rs b/core/src/encode/vthumbstrip.rs similarity index 100% rename from core/src/encode/video_thumbstrip.rs rename to core/src/encode/vthumbstrip.rs diff --git a/core/src/file/explorer/open.rs b/core/src/file/explorer/open.rs index 12e80ae92..d0ea68686 100644 --- a/core/src/file/explorer/open.rs +++ b/core/src/file/explorer/open.rs @@ -1,7 +1,8 @@ use std::path::Path; use crate::{ - file::{thumb::THUMBNAIL_CACHE_DIR_NAME, DirectoryWithContents, FileError, FilePath}, + encode::thumb::THUMBNAIL_CACHE_DIR_NAME, + file::{DirectoryWithContents, FileError, FilePath}, prisma, state::client, sys::locations::get_location, diff --git a/core/src/file/indexer/mod.rs b/core/src/file/indexer/mod.rs new file mode 100644 index 000000000..01e13a1a3 --- /dev/null +++ b/core/src/file/indexer/mod.rs @@ -0,0 +1,36 @@ +use crate::job::{ + jobs::{Job, JobReportUpdate}, + worker::WorkerContext, +}; +use anyhow::Result; + +use self::scan::ScanProgress; +pub mod pathctx; +pub mod scan; + +pub use {pathctx::PathContext, scan::scan_path}; + +#[derive(Debug)] +pub struct IndexerJob { + pub path: String, +} + +#[async_trait::async_trait] +impl Job for IndexerJob { + async fn run(&self, ctx: WorkerContext) -> Result<()> { + let core_ctx = ctx.core_ctx.clone(); + scan_path(&core_ctx, self.path.as_str(), move |p| { + ctx.progress( + p.iter() + .map(|p| match p.clone() { + ScanProgress::ChunkCount(c) => JobReportUpdate::TaskCount(c), + ScanProgress::SavedChunks(p) => JobReportUpdate::CompletedTaskCount(p), + ScanProgress::Message(m) => JobReportUpdate::Message(m), + }) + .collect(), + ) + }) + .await?; + Ok(()) + } +} diff --git a/core/src/file/indexer/pathctx.rs b/core/src/file/indexer/pathctx.rs new file mode 100644 index 000000000..d329ed24c --- /dev/null +++ b/core/src/file/indexer/pathctx.rs @@ -0,0 +1,13 @@ +// PathContext provides the indexer with instruction to handle particular directory structures and identify rich context. +pub struct PathContext { + // an app specific key "com.github.repo" + pub key: String, + pub name: String, + pub is_dir: bool, + // possible file extensions for this path + pub extensions: Vec, + // sub-paths that must be found + pub must_contain_sub_paths: Vec, + // sub-paths that are ignored + pub always_ignored_sub_paths: Option, +} diff --git a/core/src/file/indexer.rs b/core/src/file/indexer/scan.rs similarity index 90% rename from core/src/file/indexer.rs rename to core/src/file/indexer/scan.rs index 7f7e5571b..20e01cea0 100644 --- a/core/src/file/indexer.rs +++ b/core/src/file/indexer/scan.rs @@ -1,7 +1,5 @@ -use crate::job::jobs::JobReportUpdate; -use crate::job::{jobs::Job, worker::WorkerContext}; +use crate::file::cas::checksum::partial_checksum; use crate::sys::locations::{create_location, LocationResource}; - use crate::CoreContext; use anyhow::{anyhow, Result}; use chrono::{DateTime, SecondsFormat, Utc}; @@ -10,33 +8,6 @@ use std::ffi::OsStr; use std::{collections::HashMap, fs, path::Path, path::PathBuf, time::Instant}; use walkdir::{DirEntry, WalkDir}; -use super::cas::checksum::partial_checksum; - -#[derive(Debug)] -pub struct IndexerJob { - pub path: String, -} - -#[async_trait::async_trait] -impl Job for IndexerJob { - async fn run(&self, ctx: WorkerContext) -> Result<()> { - let core_ctx = ctx.core_ctx.clone(); - scan_path(&core_ctx, self.path.as_str(), move |p| { - ctx.progress( - p.iter() - .map(|p| match p.clone() { - ScanProgress::ChunkCount(c) => JobReportUpdate::TaskCount(c), - ScanProgress::SavedChunks(p) => JobReportUpdate::CompletedTaskCount(p), - ScanProgress::Message(m) => JobReportUpdate::Message(m), - }) - .collect(), - ) - }) - .await?; - Ok(()) - } -} - #[derive(Clone)] pub enum ScanProgress { ChunkCount(usize), diff --git a/core/src/file/mod.rs b/core/src/file/mod.rs index f562f2170..f1a1acb2a 100644 --- a/core/src/file/mod.rs +++ b/core/src/file/mod.rs @@ -11,7 +11,6 @@ use crate::{ pub mod cas; pub mod explorer; pub mod indexer; -pub mod thumb; pub mod watcher; // A unique file diff --git a/core/src/lib.rs b/core/src/lib.rs index 5ebe525ed..357f49944 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -11,7 +11,7 @@ use tokio::sync::{ }; use ts_rs::TS; -use crate::file::thumb::ThumbnailJob; +use crate::encode::thumb::ThumbnailJob; // init modules pub mod client; diff --git a/core/src/sync/crdt/property_operation.rs b/core/src/sync/crdt/propop.rs similarity index 100% rename from core/src/sync/crdt/property_operation.rs rename to core/src/sync/crdt/propop.rs