chore: more pedantic clippy suggestions
This commit is contained in:
parent
5863671217
commit
5f729829d7
17 changed files with 1063 additions and 998 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
use tokio::sync::Notify;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum ControllerState {
|
||||
Cancelled,
|
||||
Failed,
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ async fn handle_replace(
|
|||
let item_from = match tab::item_from_path(file_from, IconSizes::default()) {
|
||||
Ok(ok) => ok,
|
||||
Err(err) => {
|
||||
log::warn!("{}", err);
|
||||
log::warn!("{err}");
|
||||
return ReplaceResult::Cancel;
|
||||
}
|
||||
};
|
||||
|
|
@ -44,7 +44,7 @@ async fn handle_replace(
|
|||
let item_to = match tab::item_from_path(file_to, IconSizes::default()) {
|
||||
Ok(ok) => ok,
|
||||
Err(err) => {
|
||||
log::warn!("{}", err);
|
||||
log::warn!("{err}");
|
||||
return ReplaceResult::Cancel;
|
||||
}
|
||||
};
|
||||
|
|
@ -98,13 +98,13 @@ async fn copy_or_move(
|
|||
compio::runtime::spawn(async move {
|
||||
let controller = controller_c;
|
||||
log::info!(
|
||||
"{} {:?} to {:?}",
|
||||
"{} {:?} to {}",
|
||||
match method {
|
||||
Method::Copy => "Copy",
|
||||
Method::Move { .. } => "Move",
|
||||
},
|
||||
paths,
|
||||
to
|
||||
to.display()
|
||||
);
|
||||
|
||||
// Handle duplicate file names by renaming paths
|
||||
|
|
@ -141,12 +141,15 @@ async fn copy_or_move(
|
|||
//TODO: use compio::fs::rename?
|
||||
match fs::rename(from, to) {
|
||||
Ok(()) => {
|
||||
log::info!("renamed {from:?} to {to:?}");
|
||||
log::info!("renamed {} to {}", from.display(), to.display());
|
||||
false
|
||||
}
|
||||
Err(err) => {
|
||||
log::info!(
|
||||
"failed to rename {from:?} to {to:?}, fallback to recursive move: {err}"
|
||||
"failed to rename {} to {}, fallback to recursive move: {}",
|
||||
from.display(),
|
||||
to.display(),
|
||||
err
|
||||
);
|
||||
true
|
||||
}
|
||||
|
|
@ -227,15 +230,14 @@ fn copy_unique_path(from: &Path, to: &Path) -> PathBuf {
|
|||
.unwrap_or_else(|| {
|
||||
from.file_stem()
|
||||
.and_then(|s| s.to_str())
|
||||
.map(|stem| {
|
||||
.map_or((file_name, None), |stem| {
|
||||
(
|
||||
stem.to_string(),
|
||||
from.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.map(|e| e.to_string()),
|
||||
.map(str::to_string),
|
||||
)
|
||||
})
|
||||
.unwrap_or((file_name, None))
|
||||
})
|
||||
};
|
||||
|
||||
|
|
@ -283,7 +285,7 @@ fn paths_parent_name(paths: &[PathBuf]) -> Cow<'_, str> {
|
|||
return fl!("unknown-folder").into();
|
||||
};
|
||||
|
||||
for path in paths.iter() {
|
||||
for path in paths {
|
||||
//TODO: is it possible to have different parents, and what should be returned?
|
||||
if path.parent() != Some(parent) {
|
||||
return fl!("unknown-folder").into();
|
||||
|
|
@ -397,18 +399,18 @@ impl OperationError {
|
|||
pub fn from_err<T: ToString>(err: T, controller: &Controller) -> Self {
|
||||
controller.set_state(ControllerState::Failed);
|
||||
|
||||
OperationError {
|
||||
Self {
|
||||
kind: OperationErrorType::Generic(err.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_kind(kind: OperationErrorType, controller: &Controller) -> Self {
|
||||
controller.set_state(ControllerState::Failed);
|
||||
OperationError { kind }
|
||||
Self { kind }
|
||||
}
|
||||
|
||||
pub fn from_msg(m: impl Into<String>) -> Self {
|
||||
OperationError {
|
||||
Self {
|
||||
kind: OperationErrorType::Generic(m.into()),
|
||||
}
|
||||
}
|
||||
|
|
@ -572,7 +574,7 @@ impl Operation {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn show_progress_notification(&self) -> bool {
|
||||
pub const fn show_progress_notification(&self) -> bool {
|
||||
// Long running operations show a progress notification
|
||||
match self {
|
||||
Self::Compress { .. }
|
||||
|
|
@ -625,7 +627,7 @@ impl Operation {
|
|||
let controller = controller_c;
|
||||
let Some(relative_root) = to.parent() else {
|
||||
return Err(OperationError::from_err(
|
||||
format!("path {:?} has no parent directory", to),
|
||||
format!("path {} has no parent directory", to.display()),
|
||||
&controller,
|
||||
));
|
||||
};
|
||||
|
|
@ -636,7 +638,7 @@ impl Operation {
|
|||
};
|
||||
|
||||
let mut paths = paths;
|
||||
for path in paths.clone().iter() {
|
||||
for path in &paths.clone() {
|
||||
if path.is_dir() {
|
||||
let new_paths_it = WalkDir::new(path).into_iter();
|
||||
for entry in new_paths_it.skip(1) {
|
||||
|
|
@ -1011,7 +1013,7 @@ impl Operation {
|
|||
}
|
||||
Self::RemoveFromRecents { paths } => {
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let path_refs = paths.iter().map(|p| p.as_ref()).collect::<Vec<&Path>>();
|
||||
let path_refs = paths.iter().map(PathBuf::as_path).collect::<Vec<&Path>>();
|
||||
recently_used_xbel::remove_recently_used(&path_refs)
|
||||
})
|
||||
.await
|
||||
|
|
@ -1205,7 +1207,7 @@ mod tests {
|
|||
debug!("[{id}] Replace request");
|
||||
tx.send(ReplaceResult::Cancel)
|
||||
.await
|
||||
.expect("Sending a response to a replace request should succeed")
|
||||
.expect("Sending a response to a replace request should succeed");
|
||||
}
|
||||
_ => unreachable!(
|
||||
"Only [ `Message::PendingProgress`, `Message::DialogPush(DialogPage::Replace)` ] are sent from operation"
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ impl Context {
|
|||
continue;
|
||||
}
|
||||
|
||||
for entry in WalkDir::new(&from_parent).into_iter() {
|
||||
for entry in WalkDir::new(&from_parent) {
|
||||
self.controller
|
||||
.check()
|
||||
.await
|
||||
|
|
@ -76,7 +76,11 @@ impl Context {
|
|||
|
||||
let entry = entry.map_err(|err| {
|
||||
OperationError::from_err(
|
||||
format!("failed to walk directory {:?}: {}", from_parent, err),
|
||||
format!(
|
||||
"failed to walk directory {}: {}",
|
||||
from_parent.display(),
|
||||
err
|
||||
),
|
||||
&self.controller,
|
||||
)
|
||||
})?;
|
||||
|
|
@ -92,7 +96,7 @@ impl Context {
|
|||
} else if file_type.is_symlink() {
|
||||
let target = fs::read_link(&from).map_err(|err| {
|
||||
OperationError::from_err(
|
||||
format!("failed to read link {:?}: {}", from, err),
|
||||
format!("failed to read link {}: {}", from_parent.display(), err),
|
||||
&self.controller,
|
||||
)
|
||||
})?;
|
||||
|
|
@ -111,8 +115,10 @@ impl Context {
|
|||
let relative = from.strip_prefix(&from_parent).map_err(|err| {
|
||||
OperationError::from_err(
|
||||
format!(
|
||||
"failed to remove prefix {:?} from {:?}: {}",
|
||||
from_parent, from, err
|
||||
"failed to remove prefix {} from {}: {}",
|
||||
from_parent.display(),
|
||||
from.display(),
|
||||
err
|
||||
),
|
||||
&self.controller,
|
||||
)
|
||||
|
|
@ -163,8 +169,11 @@ impl Context {
|
|||
if op.run(self, progress).await.map_err(|err| {
|
||||
OperationError::from_err(
|
||||
format!(
|
||||
"failed to {:?} {:?} to {:?}: {}",
|
||||
op.kind, op.from, op.to, err
|
||||
"failed to {:?} {} to {}: {}",
|
||||
op.kind,
|
||||
op.from.display(),
|
||||
op.to.display(),
|
||||
err
|
||||
),
|
||||
&self.controller,
|
||||
)
|
||||
|
|
@ -209,7 +218,7 @@ impl Context {
|
|||
}
|
||||
ReplaceResult::KeepBoth => match op.to.parent() {
|
||||
Some(to_parent) => Ok(ControlFlow::Continue(copy_unique_path(&op.from, to_parent))),
|
||||
None => Err(format!("failed to get parent of {:?}", op.to).into()),
|
||||
None => Err(format!("failed to get parent of {}", op.to.display()).into()),
|
||||
},
|
||||
ReplaceResult::Skip(apply_to_all) => {
|
||||
if apply_to_all {
|
||||
|
|
@ -319,7 +328,11 @@ impl Op {
|
|||
(ctx.on_progress)(self, &progress);
|
||||
if let Err(err) = to_file.set_permissions(metadata.permissions()).await {
|
||||
// This error is not propagated upwards as some filesystems do not support setting permissions
|
||||
log::warn!("failed to set permissions for {:?}: {}", self.to, err);
|
||||
log::warn!(
|
||||
"failed to set permissions for {}: {}",
|
||||
self.to.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
|
||||
// Prevent spamming the progress callbacks.
|
||||
|
|
@ -402,7 +415,7 @@ impl Op {
|
|||
self.skipped.cleanup.set(true);
|
||||
}
|
||||
// Try standard copy if hard link fails with cross device error
|
||||
let mut copy_op = Op {
|
||||
let mut copy_op = Self {
|
||||
kind: OpKind::Copy,
|
||||
from: self.from.clone(),
|
||||
to: self.to.clone(),
|
||||
|
|
@ -410,9 +423,8 @@ impl Op {
|
|||
is_cleanup: self.is_cleanup,
|
||||
};
|
||||
return Box::pin(copy_op.run(ctx, progress)).await;
|
||||
} else {
|
||||
return Err(err.into());
|
||||
}
|
||||
return Err(err.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue