Skip to content

Commit

Permalink
Clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierlemasle committed Jan 26, 2023
1 parent a04eecd commit 3f836c4
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 53 deletions.
3 changes: 1 addition & 2 deletions tooling/bundler/src/bundle/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ impl<'d> serde::de::Visitor<'d> for AppCategoryVisitor {
match self.did_you_mean {
Some(string) => write!(
formatter,
"a valid app category string (did you mean \"{}\"?)",
string
"a valid app category string (did you mean \"{string}\"?)"
),
None => write!(formatter, "a valid app category string"),
}
Expand Down
20 changes: 7 additions & 13 deletions tooling/bundler/src/bundle/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ pub fn copy_file(from: impl AsRef<Path>, to: impl AsRef<Path>) -> crate::Result<
let to = to.as_ref();
if !from.exists() {
return Err(crate::Error::GenericError(format!(
"{:?} does not exist",
from
"{from:?} does not exist"
)));
}
if !from.is_file() {
return Err(crate::Error::GenericError(format!(
"{:?} is not a file",
from
"{from:?} is not a file"
)));
}
let dest_dir = to.parent().expect("No data in parent");
Expand All @@ -96,20 +94,17 @@ pub fn copy_file(from: impl AsRef<Path>, to: impl AsRef<Path>) -> crate::Result<
pub fn copy_dir(from: &Path, to: &Path) -> crate::Result<()> {
if !from.exists() {
return Err(crate::Error::GenericError(format!(
"{:?} does not exist",
from
"{from:?} does not exist"
)));
}
if !from.is_dir() {
return Err(crate::Error::GenericError(format!(
"{:?} is not a Directory",
from
"{from:?} is not a Directory"
)));
}
if to.exists() {
return Err(crate::Error::GenericError(format!(
"{:?} already exists",
from
"{from:?} already exists"
)));
}
let parent = to.parent().expect("No data in parent");
Expand Down Expand Up @@ -154,7 +149,7 @@ impl CommandExt for Command {

fn output_ok(&mut self) -> crate::Result<Output> {
let program = self.get_program().to_string_lossy().into_owned();
debug!(action = "Running"; "Command `{} {}`", program, self.get_args().map(|arg| arg.to_string_lossy()).fold(String::new(), |acc, arg| format!("{} {}", acc, arg)));
debug!(action = "Running"; "Command `{} {}`", program, self.get_args().map(|arg| arg.to_string_lossy()).fold(String::new(), |acc, arg| format!("{acc} {arg}")));

self.stdout(Stdio::piped());
self.stderr(Stdio::piped());
Expand Down Expand Up @@ -208,8 +203,7 @@ impl CommandExt for Command {
Ok(output)
} else {
Err(crate::Error::GenericError(format!(
"failed to run {}",
program
"failed to run {program}"
)))
}
}
Expand Down
20 changes: 10 additions & 10 deletions tooling/bundler/src/bundle/linux/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
settings.version_string(),
arch
);
let package_name = format!("{}.deb", package_base_name);
let package_name = format!("{package_base_name}.deb");

let base_dir = settings.project_out_directory().join("bundle/deb");
let package_dir = base_dir.join(&package_base_name);
if package_dir.exists() {
fs::remove_dir_all(&package_dir)
.with_context(|| format!("Failed to remove old {}", package_base_name))?;
.with_context(|| format!("Failed to remove old {package_base_name}"))?;
}
let package_path = base_dir.join(&package_name);

Expand Down Expand Up @@ -107,7 +107,7 @@ pub fn generate_data(
for bin in settings.binaries() {
let bin_path = settings.binary_path(bin);
common::copy_file(&bin_path, bin_dir.join(bin.name()))
.with_context(|| format!("Failed to copy binary from {:?}", bin_path))?;
.with_context(|| format!("Failed to copy binary from {bin_path:?}"))?;
}

copy_resource_files(settings, &data_dir).with_context(|| "Failed to copy resource files")?;
Expand Down Expand Up @@ -137,11 +137,11 @@ fn generate_control_file(
let mut file = common::create_file(&dest_path)?;
writeln!(file, "Package: {}", AsKebabCase(settings.product_name()))?;
writeln!(file, "Version: {}", settings.version_string())?;
writeln!(file, "Architecture: {}", arch)?;
writeln!(file, "Architecture: {arch}")?;
// Installed-Size must be divided by 1024, see https://www.debian.org/doc/debian-policy/ch-controlfields.html#installed-size
writeln!(file, "Installed-Size: {}", total_dir_size(data_dir)? / 1024)?;
let authors = settings.authors_comma_separated().unwrap_or_default();
writeln!(file, "Maintainer: {}", authors)?;
writeln!(file, "Maintainer: {authors}")?;
if !settings.homepage_url().is_empty() {
writeln!(file, "Homepage: {}", settings.homepage_url())?;
}
Expand All @@ -157,13 +157,13 @@ fn generate_control_file(
if long_description.is_empty() {
long_description = "(none)";
}
writeln!(file, "Description: {}", short_description)?;
writeln!(file, "Description: {short_description}")?;
for line in long_description.lines() {
let line = line.trim();
if line.is_empty() {
writeln!(file, " .")?;
} else {
writeln!(file, " {}", line)?;
writeln!(file, " {line}")?;
}
}
writeln!(file, "Priority: optional")?;
Expand All @@ -186,14 +186,14 @@ fn generate_md5sums(control_dir: &Path, data_dir: &Path) -> crate::Result<()> {
let mut hash = md5::Context::new();
io::copy(&mut file, &mut hash)?;
for byte in hash.compute().iter() {
write!(md5sums_file, "{:02x}", byte)?;
write!(md5sums_file, "{byte:02x}")?;
}
let rel_path = path.strip_prefix(data_dir)?;
let path_str = rel_path.to_str().ok_or_else(|| {
let msg = format!("Non-UTF-8 path: {:?}", rel_path);
let msg = format!("Non-UTF-8 path: {rel_path:?}");
io::Error::new(io::ErrorKind::InvalidData, msg)
})?;
writeln!(md5sums_file, " {}", path_str)?;
writeln!(md5sums_file, " {path_str}")?;
}
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions tooling/bundler/src/bundle/linux/freedesktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn generate_desktop_file(
data_dir: &Path,
) -> crate::Result<(PathBuf, PathBuf)> {
let bin_name = settings.main_binary_name();
let desktop_file_name = format!("{}.desktop", bin_name);
let desktop_file_name = format!("{bin_name}.desktop");
let path = PathBuf::from("usr/share/applications").join(desktop_file_name);
let dest_path = PathBuf::from("/").join(&path);
let file_path = data_dir.join(&path);
Expand All @@ -109,8 +109,8 @@ pub fn generate_desktop_file(
if !settings.short_description().is_empty() {
writeln!(file, "Comment={}", settings.short_description())?;
}
writeln!(file, "Exec={}", bin_name)?;
writeln!(file, "Icon={}", bin_name)?;
writeln!(file, "Exec={bin_name}")?;
writeln!(file, "Icon={bin_name}")?;
writeln!(file, "Name={}", settings.product_name())?;
writeln!(file, "Terminal=false")?;
writeln!(file, "Type=Application")?;
Expand Down
6 changes: 3 additions & 3 deletions tooling/bundler/src/bundle/linux/rpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
// (current limitation of rpm-rs)
let desc = settings.short_description();

let package_base_name = format!("{}-{}-{}.{}", name, version, release, arch);
let package_name = format!("{}.rpm", package_base_name);
let package_base_name = format!("{name}-{version}-{release}.{arch}");
let package_name = format!("{package_base_name}.rpm");

let base_dir = settings.project_out_directory().join("bundle/rpm");
let package_dir = base_dir.join(&package_base_name);
if package_dir.exists() {
fs::remove_dir_all(&package_dir)
.with_context(|| format!("Failed to remove old {}", package_base_name))?;
.with_context(|| format!("Failed to remove old {package_base_name}"))?;
}
fs::create_dir_all(&package_dir)?;
let package_path = base_dir.join(package_name);
Expand Down
10 changes: 5 additions & 5 deletions tooling/bundler/src/bundle/path_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ where
let from = from.as_ref();
if !from.exists() {
if let Some(msg) = from.to_str() {
let msg = format!("Path \"{}\" does not exist or you don't have access", msg);
let msg = format!("Path \"{msg}\" does not exist or you don't have access");
return Err(crate::Error::PathUtilError(msg));
}
return Err(crate::Error::PathUtilError(
Expand All @@ -114,7 +114,7 @@ where

if !from.is_file() {
if let Some(msg) = from.to_str() {
let msg = format!("Path \"{}\" is not a file!", msg);
let msg = format!("Path \"{msg}\" is not a file!");
return Err(crate::Error::PathUtilError(msg));
}
return Err(crate::Error::PathUtilError(
Expand All @@ -127,7 +127,7 @@ where
}

if let Some(msg) = to.as_ref().to_str() {
let msg = format!("Path \"{}\" is exist", msg);
let msg = format!("Path \"{msg}\" is exist");
return Err(crate::Error::PathUtilError(msg));
}
}
Expand All @@ -145,7 +145,7 @@ where
let from = from.as_ref();
if !from.exists() {
if let Some(msg) = from.to_str() {
let msg = format!("Path \"{}\" does not exist or you don't have access!", msg);
let msg = format!("Path \"{msg}\" does not exist or you don't have access!");
return Err(crate::Error::PathUtilError(msg));
}
return Err(crate::Error::PathUtilError(
Expand All @@ -154,7 +154,7 @@ where
}
if !from.is_dir() {
if let Some(msg) = from.to_str() {
let msg = format!("Path \"{}\" is not a directory!", msg);
let msg = format!("Path \"{msg}\" is not a directory!");
return Err(crate::Error::PathUtilError(msg));
}
return Err(crate::Error::PathUtilError(
Expand Down
4 changes: 2 additions & 2 deletions tooling/bundler/src/bundle/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ pub fn target_triple() -> Result<String, crate::Error> {
)));
};

format!("{}-{}", os, env)
format!("{os}-{env}")
};

Ok(format!("{}-{}", arch, os))
Ok(format!("{arch}-{os}"))
}

#[cfg(test)]
Expand Down
3 changes: 1 addition & 2 deletions tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,7 @@ impl Settings {
"windows" => vec![PackageType::WindowsMsi, PackageType::Nsis],
os => {
return Err(crate::Error::GenericError(format!(
"Native {} bundles not yet supported.",
os
"Native {os} bundles not yet supported."
)))
}
};
Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/bundle/updater_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ fn bundle_update_windows(settings: &Settings, bundles: &[Bundle]) -> crate::Resu
p.push(c);
(p, b)
});
let archived_path = archived_path.with_extension(format!("{}.zip", bundle_name));
let archived_path = archived_path.with_extension(format!("{bundle_name}.zip"));

info!(action = "Bundling"; "{}", display_path(&archived_path));

Expand Down
3 changes: 1 addition & 2 deletions tooling/bundler/src/bundle/windows/nsis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ fn build_nsis_app_installer(
"aarch64" => "arm64",
target => {
return Err(crate::Error::ArchError(format!(
"unsupported target: {}",
target
"unsupported target: {target}"
)))
}
};
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn run(args: Vec<String>, bin_name: Option<String>, callback: JsFunction) ->
std::thread::spawn(move || match tauri_cli::try_run(args, bin_name) {
Ok(_) => function.call(Ok(true), ThreadsafeFunctionCallMode::Blocking),
Err(e) => function.call(
Err(Error::new(Status::GenericFailure, format!("{:#}", e))),
Err(Error::new(Status::GenericFailure, format!("{e:#}"))),
ThreadsafeFunctionCallMode::Blocking,
),
});
Expand Down
4 changes: 2 additions & 2 deletions tooling/cli/src/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn command(options: Options) -> Result<()> {
png_targets.extend(
[32, 128]
.into_iter()
.map(|size| PngTarget::new(size, format!("{}x{}.png", size, size)))
.map(|size| PngTarget::new(size, format!("{size}x{size}.png")))
.collect::<Vec<PngTarget>>(),
);
png(&source, &out_dir, png_targets).context("Failed to generate png icons")?;
Expand All @@ -99,7 +99,7 @@ pub fn command(options: Options) -> Result<()> {
&out_dir,
png_icon_sizes
.into_iter()
.map(|size| PngTarget::new(size, format!("{}x{}.png", size, size)))
.map(|size| PngTarget::new(size, format!("{size}x{size}.png")))
.collect(),
)?;
}
Expand Down
8 changes: 1 addition & 7 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,13 +648,7 @@ impl AppSettings for RustAppSettings {
features: &[String],
target: &str,
) -> crate::Result<BundleSettings> {
let arch64bits = if target.starts_with("x86_64") {
true
} else if target.starts_with("aarch64") {
true
} else {
false
};
let arch64bits = target.starts_with("x86_64") || target.starts_with("aarch64");

tauri_config_to_bundle_settings(
&self.manifest,
Expand Down

0 comments on commit 3f836c4

Please sign in to comment.