mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2025-12-11 20:15:30 +01:00
* Introducing sub path indexing for IndexerJob * Introducing shallow indexer job * Some feature flags to avoid warnings at pnpm prep * Many fixes at shallow indexer job * Changing how we implement the bookkeeping for file_path ids Now we're account for independent locations, and also integrating better with the LibraryContext, instead of using a static global * Making indexer job reentrant * Introducing shallow file identifier job And a bunch of minor refactors * Rust fmt * Removing light scan from getExplorerData query Light scan is a mutation, so we can call it on useEffect function from the Explorer component in the frontend, when a location_id or the explorer path changes * Handling job early finish on init for identifier * Only invalidate query if we have orphan paths * Introducing ShalowThumbnailerJob * Clippy warnings about `into_iter()` * Naming scheme for Prisma's selects and includes * Invalidating getExplorerData at thumbnailer * Small mistakes lol * Some nitpicks with pnpm prep * Rust fmt * Changing indexer's walk log to `trace!` * Not deleting all file_paths on location fullRescan * TS typecheck * Removing `file_path` selection just with id
83 lines
1.6 KiB
Rust
83 lines
1.6 KiB
Rust
use crate::{
|
|
job::JobError,
|
|
location::file_path_helper::file_path_with_object,
|
|
prisma::{file_path, location, PrismaClient},
|
|
};
|
|
|
|
use std::{ffi::OsStr, path::PathBuf};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
pub mod create;
|
|
|
|
pub mod copy;
|
|
pub mod cut;
|
|
|
|
pub mod decrypt;
|
|
pub mod delete;
|
|
pub mod encrypt;
|
|
|
|
pub mod error;
|
|
|
|
pub mod erase;
|
|
|
|
pub const BYTES_EXT: &str = ".bytes";
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
|
pub enum ObjectType {
|
|
File,
|
|
Directory,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct FsInfo {
|
|
pub path_data: file_path_with_object::Data,
|
|
pub fs_path: PathBuf,
|
|
}
|
|
|
|
pub fn osstr_to_string(os_str: Option<&OsStr>) -> Result<String, JobError> {
|
|
os_str
|
|
.and_then(OsStr::to_str)
|
|
.map(str::to_string)
|
|
.ok_or(JobError::OsStr)
|
|
}
|
|
|
|
pub async fn get_path_from_location_id(
|
|
db: &PrismaClient,
|
|
location_id: i32,
|
|
) -> Result<PathBuf, JobError> {
|
|
Ok(db
|
|
.location()
|
|
.find_unique(location::id::equals(location_id))
|
|
.exec()
|
|
.await?
|
|
.ok_or(JobError::MissingData {
|
|
value: String::from("location which matches location_id"),
|
|
})?
|
|
.path
|
|
.into())
|
|
}
|
|
|
|
pub async fn context_menu_fs_info(
|
|
db: &PrismaClient,
|
|
location_id: i32,
|
|
path_id: i32,
|
|
) -> Result<FsInfo, JobError> {
|
|
let path_data = db
|
|
.file_path()
|
|
.find_unique(file_path::location_id_id(location_id, path_id))
|
|
.include(file_path_with_object::include())
|
|
.exec()
|
|
.await?
|
|
.ok_or(JobError::MissingData {
|
|
value: String::from("file_path that matches both location id and path id"),
|
|
})?;
|
|
|
|
Ok(FsInfo {
|
|
fs_path: get_path_from_location_id(db, location_id)
|
|
.await?
|
|
.join(&path_data.materialized_path),
|
|
path_data,
|
|
})
|
|
}
|