fix as suggestion.

This commit is contained in:
ShuiRuTian 2021-01-12 00:21:03 +08:00
parent 1b004dcf88
commit d877390882

View File

@ -433,27 +433,23 @@ pub(crate) fn handle_will_rename_files(
match (from_path.parent(), to_path.parent()) { match (from_path.parent(), to_path.parent()) {
(Some(p1), Some(p2)) if p1 == p2 => { (Some(p1), Some(p2)) if p1 == p2 => {
if from_path.is_dir() { if from_path.is_dir() {
// This is a quick implement, try to use will_rename_file code.
// imitate change the older_folder/mod.rs to older_folder/new_folder.rs
// add '/' to end of url -- from `file://path/to/folder` to `file://path/to/folder/` // add '/' to end of url -- from `file://path/to/folder` to `file://path/to/folder/`
let mut old_folder_name = from_path.file_stem()?.to_str()?.to_string(); let mut old_folder_name = from_path.file_stem()?.to_str()?.to_string();
old_folder_name.push('/'); old_folder_name.push('/');
let from_with_trailing_slash = from.join(&old_folder_name).ok()?; let from_with_trailing_slash = from.join(&old_folder_name).ok()?;
let imitate_from_url = from_with_trailing_slash.join("mod.rs").ok()?; let imitate_from_url = from_with_trailing_slash.join("mod.rs").ok()?;
let imite_new_file_name = to_path.file_name()?.to_str()?; let new_file_name = to_path.file_name()?.to_str()?;
Some(( Some((
snap.url_to_file_id(&imitate_from_url).ok()?, snap.url_to_file_id(&imitate_from_url).ok()?,
imite_new_file_name.to_string(), new_file_name.to_string(),
)) ))
} else { } else {
let old_name = from_path.file_stem()?.to_str()?; let old_name = from_path.file_stem()?.to_str()?;
let new_name = to_path.file_stem()?.to_str()?; let new_name = to_path.file_stem()?.to_str()?;
if old_name != "mod" && new_name != "mod" { match(old_name,new_name){
Some((snap.url_to_file_id(&from).ok()?, new_name.to_string())) ("mod","mod") =>Some((snap.url_to_file_id(&from).ok()?, new_name.to_string())),
} else { _=>None
None
} }
} }
} }