small improvements

This commit is contained in:
Mark 2024-06-12 20:30:39 +02:00
parent a2a6b9575a
commit b7264ddd13
2 changed files with 23 additions and 26 deletions

View File

@ -384,19 +384,20 @@ impl TuiFile {
fn set_current_index_to_visible(&mut self, start: usize, inc: bool) { fn set_current_index_to_visible(&mut self, start: usize, inc: bool) {
let mut i = start; let mut i = start;
loop { loop {
if self.dir_content.get(i).is_some_and(|e| e.passes_filter) { if let Some(e) = self.dir_content.get(i) {
if e.passes_filter {
self.set_current_index(i); self.set_current_index(i);
return; return;
} }
} else {
return;
}
if inc { if inc {
i += 1; i += 1;
if i >= self.dir_content.len() {
break;
}
} else if i > 0 { } else if i > 0 {
i -= 1; i -= 1;
} else { } else {
break; return;
} }
} }
} }
@ -407,7 +408,7 @@ impl TuiFile {
self.updates.request_rescan_files(); self.updates.request_rescan_files();
self.after_rescanning_files.push(Box::new(move |s| { self.after_rescanning_files.push(Box::new(move |s| {
if let Some(i) = s.dir_content.iter().position(find_by) { if let Some(i) = s.dir_content.iter().position(find_by) {
s.set_current_index(i) s.set_current_index(i);
} else { } else {
s.updates.request_reset_current_index(); s.updates.request_reset_current_index();
} }

View File

@ -26,30 +26,26 @@ pub(crate) fn task_copy(
*status.lock().unwrap() = s; *status.lock().unwrap() = s;
} }
let file_from = parent.join(&rel_path); let file_from = parent.join(&rel_path);
let file_to = target.join(&rel_path);
let is_dir = file_from.is_dir(); let is_dir = file_from.is_dir();
let parent_created = if let Some(parent) = rel_path.parent() { let file_to = if let Some(parent) = rel_path.parent() {
parent.as_os_str().is_empty() || created.contains(parent) let mut p = PathBuf::new();
for c in parent.components() {
p.push(c);
if !created.contains(&p) {
p.pop();
break;
}
}
target.join(&p).join(rel_path.file_name().unwrap())
} else { } else {
true target.join(&rel_path)
}; };
if parent_created {
if is_dir { if is_dir {
copy_dir(file_from, file_to, copy_recursive); copy_dir(file_from, file_to, copy_recursive);
created.insert(rel_path); created.insert(rel_path);
} else { } else {
fs::copy(&file_from, &file_to); fs::copy(&file_from, &file_to);
} }
} else {
let rel_path = rel_path.file_name().unwrap();
let file_to = target.join(&rel_path);
if is_dir {
copy_dir(file_from, file_to, copy_recursive);
created.insert(rel_path.into());
} else {
fs::copy(&file_from, &file_to);
}
}
} }
} }
Ok(()) Ok(())