mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-08 07:12:49 +00:00
attempt to move duplicate over to copy job
This commit is contained in:
parent
99440c4930
commit
508c6bdd6b
|
@ -129,10 +129,8 @@ pub(crate) fn mount() -> RouterBuilder {
|
|||
})
|
||||
})
|
||||
.library_mutation("duplicateFiles", |t| {
|
||||
t(|_, args: FileDuplicatorJobInit, library| async move {
|
||||
library
|
||||
.spawn_job(Job::new(args, FileDuplicatorJob {}))
|
||||
.await;
|
||||
t(|_, args: FileCopierJobInit, library| async move {
|
||||
library.spawn_job(Job::new(args, FileCopierJob {})).await;
|
||||
invalidate_query!(library, "locations.getExplorerData");
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -11,6 +11,7 @@ pub struct FileCopierJobState {
|
|||
pub target_path: PathBuf, // target dir prefix too
|
||||
pub source_path: PathBuf,
|
||||
pub root_type: ObjectType,
|
||||
pub target_file_name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Hash, Type)]
|
||||
|
@ -19,6 +20,7 @@ pub struct FileCopierJobInit {
|
|||
pub source_path_id: i32,
|
||||
pub target_location_id: i32,
|
||||
pub target_path: PathBuf,
|
||||
pub target_file_name_suffix: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
|
@ -50,10 +52,42 @@ impl StatefulJob for FileCopierJob {
|
|||
get_path_from_location_id(&ctx.library_ctx.db, state.init.target_location_id).await?;
|
||||
full_target_path.push(state.init.target_path.clone());
|
||||
|
||||
let target_file_name = state.init.target_file_name_suffix.clone().map_or_else(
|
||||
|| {
|
||||
source_fs_info
|
||||
.obj_path
|
||||
.clone()
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
},
|
||||
|s| {
|
||||
// should turn /root/x.tar.gz into /root/x.tar - clone.gz (file_prefix is still unstable :|)
|
||||
// need to get the original file name, add `s` onto it and preserve the extension fully
|
||||
source_fs_info
|
||||
.obj_path
|
||||
.clone()
|
||||
.file_stem()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string() + &s + source_fs_info
|
||||
.obj_path
|
||||
.clone()
|
||||
.extension()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
},
|
||||
);
|
||||
|
||||
state.data = Some(FileCopierJobState {
|
||||
target_path: full_target_path,
|
||||
source_path: source_fs_info.obj_path.clone(),
|
||||
root_type: source_fs_info.obj_type.clone(),
|
||||
target_file_name,
|
||||
});
|
||||
|
||||
state.steps = VecDeque::new();
|
||||
|
@ -79,11 +113,9 @@ impl StatefulJob for FileCopierJob {
|
|||
match info.obj_type {
|
||||
ObjectType::File => {
|
||||
let mut path = job_state.target_path.clone();
|
||||
path.push(job_state.source_path.clone().file_name().unwrap());
|
||||
path.push(job_state.target_file_name.clone());
|
||||
|
||||
if job_state.root_type == ObjectType::File {
|
||||
path.push(job_state.source_path.clone().file_name().unwrap());
|
||||
} else if job_state.root_type == ObjectType::Directory {
|
||||
if job_state.root_type == ObjectType::Directory {
|
||||
path.push(
|
||||
info.obj_path
|
||||
.strip_prefix(job_state.source_path.clone())
|
||||
|
@ -107,7 +139,7 @@ impl StatefulJob for FileCopierJob {
|
|||
});
|
||||
|
||||
let mut path = job_state.target_path.clone();
|
||||
path.push(job_state.source_path.clone().file_name().unwrap());
|
||||
path.push(job_state.target_file_name.clone());
|
||||
path.push(
|
||||
entry
|
||||
.path()
|
||||
|
|
|
@ -87,7 +87,7 @@ export type Procedures = {
|
|||
| { key: 'files.decryptFiles'; input: LibraryArgs<FileDecryptorJobInit>; result: null }
|
||||
| { key: 'files.delete'; input: LibraryArgs<number>; result: null }
|
||||
| { key: 'files.deleteFiles'; input: LibraryArgs<FileDeleterJobInit>; result: null }
|
||||
| { key: 'files.duplicateFiles'; input: LibraryArgs<FileDuplicatorJobInit>; result: null }
|
||||
| { key: 'files.duplicateFiles'; input: LibraryArgs<FileCopierJobInit>; result: null }
|
||||
| { key: 'files.encryptFiles'; input: LibraryArgs<FileEncryptorJobInit>; result: null }
|
||||
| { key: 'files.eraseFiles'; input: LibraryArgs<FileEraserJobInit>; result: null }
|
||||
| { key: 'files.setFavorite'; input: LibraryArgs<SetFavoriteArgs>; result: null }
|
||||
|
@ -188,6 +188,7 @@ export interface FileCopierJobInit {
|
|||
source_path_id: number;
|
||||
target_location_id: number;
|
||||
target_path: string;
|
||||
target_file_name_suffix: string | null;
|
||||
}
|
||||
|
||||
export interface FileCutterJobInit {
|
||||
|
@ -210,11 +211,6 @@ export interface FileDeleterJobInit {
|
|||
path_id: number;
|
||||
}
|
||||
|
||||
export interface FileDuplicatorJobInit {
|
||||
location_id: number;
|
||||
path_id: number;
|
||||
}
|
||||
|
||||
export interface FileEncryptorJobInit {
|
||||
location_id: number;
|
||||
path_id: number;
|
||||
|
|
|
@ -148,7 +148,8 @@ export function ExplorerContextMenu(props: PropsWithChildren) {
|
|||
source_location_id: store.cutCopyState.sourceLocationId,
|
||||
source_path_id: store.cutCopyState.sourcePathId,
|
||||
target_location_id: store.locationId,
|
||||
target_path: params.path
|
||||
target_path: params.path,
|
||||
target_file_name_suffix: null
|
||||
});
|
||||
} else {
|
||||
store.locationId &&
|
||||
|
@ -217,6 +218,7 @@ export function FileItemContextMenu({ ...props }: FileItemContextMenuProps) {
|
|||
mountedUuids.data !== undefined && mountedUuids.data.length > 0 ? true : false;
|
||||
|
||||
const duplicateFiles = useLibraryMutation('files.duplicateFiles');
|
||||
const copyFiles = useLibraryMutation('files.copyFiles');
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
|
@ -237,8 +239,13 @@ export function FileItemContextMenu({ ...props }: FileItemContextMenuProps) {
|
|||
keybind="⌘D"
|
||||
onClick={(e) => {
|
||||
expStore.locationId &&
|
||||
props.item.id &&
|
||||
duplicateFiles.mutate({ location_id: expStore.locationId, path_id: props.item.id });
|
||||
copyFiles.mutate({
|
||||
source_location_id: expStore.locationId,
|
||||
source_path_id: props.item.id,
|
||||
target_location_id: expStore.locationId,
|
||||
target_path: params.path,
|
||||
target_file_name_suffix: ' - Clone'
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
||||
|
|
Loading…
Reference in a new issue