mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-18 16:39:11 +00:00
cleanup duplicator job
This commit is contained in:
parent
e86ed4e212
commit
bd8b6446aa
|
@ -9,6 +9,7 @@ pub struct FileDuplicatorJob {}
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct FileDuplicatorJobState {
|
pub struct FileDuplicatorJobState {
|
||||||
pub root_path: PathBuf,
|
pub root_path: PathBuf,
|
||||||
|
pub root_prefix: PathBuf,
|
||||||
pub root_type: ObjectType,
|
pub root_type: ObjectType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +44,38 @@ impl StatefulJob for FileDuplicatorJob {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let root_prefix = if fs_info.obj_type == ObjectType::File {
|
||||||
|
let mut output_path = fs_info.obj_path.clone();
|
||||||
|
output_path.set_file_name(
|
||||||
|
fs_info
|
||||||
|
.obj_path
|
||||||
|
.file_stem()
|
||||||
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.to_string() + "-Copy"
|
||||||
|
+ &fs_info.obj_path.extension().map_or_else(
|
||||||
|
|| String::from(""),
|
||||||
|
|x| String::from(".") + x.to_str().unwrap(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
output_path
|
||||||
|
} else {
|
||||||
|
let mut output_path = fs_info.obj_path.clone();
|
||||||
|
output_path.set_file_name(
|
||||||
|
output_path
|
||||||
|
.file_stem()
|
||||||
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.to_string() + "-Copy",
|
||||||
|
);
|
||||||
|
output_path
|
||||||
|
};
|
||||||
|
|
||||||
state.data = Some(FileDuplicatorJobState {
|
state.data = Some(FileDuplicatorJobState {
|
||||||
root_path: fs_info.obj_path.clone(),
|
root_path: fs_info.obj_path.clone(),
|
||||||
|
root_prefix,
|
||||||
root_type: fs_info.obj_type.clone(),
|
root_type: fs_info.obj_type.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -64,44 +95,13 @@ impl StatefulJob for FileDuplicatorJob {
|
||||||
let step = state.steps[0].clone();
|
let step = state.steps[0].clone();
|
||||||
let info = &step.fs_info;
|
let info = &step.fs_info;
|
||||||
|
|
||||||
// temporary
|
let job_state = state.data.clone().ok_or(JobError::MissingData {
|
||||||
let job_state = if let Some(st) = state.data.clone() {
|
value: String::from("job state"),
|
||||||
st
|
})?;
|
||||||
} else {
|
|
||||||
return Err(JobError::CryptoError(sd_crypto::Error::MediaLengthParse));
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut root_path = if job_state.root_type == ObjectType::File {
|
|
||||||
let mut output_path = info.obj_path.clone();
|
|
||||||
output_path.set_file_name(
|
|
||||||
info.obj_path
|
|
||||||
.file_stem()
|
|
||||||
.unwrap()
|
|
||||||
.to_str()
|
|
||||||
.unwrap()
|
|
||||||
.to_string() + "-Copy"
|
|
||||||
+ &info.obj_path.extension().map_or_else(
|
|
||||||
|| String::from(""),
|
|
||||||
|x| String::from(".") + x.to_str().unwrap(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
output_path
|
|
||||||
} else {
|
|
||||||
let mut output_path = job_state.root_path.clone();
|
|
||||||
output_path.set_file_name(
|
|
||||||
output_path
|
|
||||||
.file_stem()
|
|
||||||
.unwrap()
|
|
||||||
.to_str()
|
|
||||||
.unwrap()
|
|
||||||
.to_string() + "-Copy",
|
|
||||||
);
|
|
||||||
output_path
|
|
||||||
};
|
|
||||||
|
|
||||||
match info.obj_type {
|
match info.obj_type {
|
||||||
ObjectType::File => {
|
ObjectType::File => {
|
||||||
let mut path = root_path.clone();
|
let mut path = job_state.root_prefix.clone();
|
||||||
|
|
||||||
if job_state.root_type == ObjectType::Directory {
|
if job_state.root_type == ObjectType::Directory {
|
||||||
path.push(
|
path.push(
|
||||||
|
@ -126,15 +126,6 @@ impl StatefulJob for FileDuplicatorJob {
|
||||||
obj_type,
|
obj_type,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut path = root_path.clone();
|
|
||||||
path.push(
|
|
||||||
entry
|
|
||||||
.path()
|
|
||||||
.strip_prefix(job_state.root_path.clone())
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
std::fs::create_dir_all(path)?;
|
|
||||||
} else {
|
} else {
|
||||||
let obj_type = ObjectType::File;
|
let obj_type = ObjectType::File;
|
||||||
state.steps.push_back(FileDuplicatorJobStep {
|
state.steps.push_back(FileDuplicatorJobStep {
|
||||||
|
@ -147,6 +138,17 @@ impl StatefulJob for FileDuplicatorJob {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut path_suffix = entry
|
||||||
|
.path()
|
||||||
|
.strip_prefix(job_state.root_path.clone())
|
||||||
|
.unwrap()
|
||||||
|
.to_path_buf();
|
||||||
|
path_suffix.set_file_name("");
|
||||||
|
|
||||||
|
let mut path = job_state.root_prefix.clone();
|
||||||
|
path.push(path_suffix);
|
||||||
|
std::fs::create_dir_all(path)?;
|
||||||
|
|
||||||
ctx.progress(vec![JobReportUpdate::TaskCount(state.steps.len())]);
|
ctx.progress(vec![JobReportUpdate::TaskCount(state.steps.len())]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue