Skip to content

Commit 72feaf9

Browse files
authored
refactor(bundler): remove unused fs utils, add http utils (#11716)
1 parent d86aacc commit 72feaf9

File tree

21 files changed

+499
-714
lines changed

21 files changed

+499
-714
lines changed

Cargo.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri-bundler/src/bundle.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
// SPDX-License-Identifier: MIT
55

66
mod category;
7-
mod common;
87
#[cfg(target_os = "linux")]
98
mod linux;
109
#[cfg(target_os = "macos")]
1110
mod macos;
12-
mod path_utils;
1311
mod platform;
1412
mod settings;
1513
mod updater_bundle;

crates/tauri-bundler/src/bundle/linux/appimage/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
// SPDX-License-Identifier: Apache-2.0
44
// SPDX-License-Identifier: MIT
55

6-
use super::{
7-
super::{
8-
common::{self, CommandExt},
9-
path_utils,
10-
},
11-
debian,
6+
use super::debian;
7+
use crate::{
8+
bundle::settings::Arch,
9+
utils::{fs_utils, CommandExt},
10+
Settings,
1211
};
13-
use crate::{bundle::settings::Arch, Settings};
1412
use anyhow::Context;
1513
use handlebars::Handlebars;
1614
use std::{
@@ -56,7 +54,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
5654
// generate deb_folder structure
5755
let (data_dir, icons) = debian::generate_data(&settings, &package_dir)
5856
.with_context(|| "Failed to build data folders and files")?;
59-
common::copy_custom_files(&settings.appimage().files, &data_dir)
57+
fs_utils::copy_custom_files(&settings.appimage().files, &data_dir)
6058
.with_context(|| "Failed to copy custom files")?;
6159

6260
let output_path = settings.project_out_directory().join("bundle/appimage");
@@ -72,7 +70,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
7270
arch
7371
);
7472
let appimage_path = output_path.join(&appimage_filename);
75-
path_utils::create(app_dir_path, true)?;
73+
fs_utils::create_dir(&app_dir_path, true)?;
7674

7775
// setup data to insert into shell script
7876
let mut sh_map = BTreeMap::new();

crates/tauri-bundler/src/bundle/linux/debian.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
// metadata, as well as generating the md5sums file. Currently we do not
2424
// generate postinst or prerm files.
2525

26-
use super::{super::common, freedesktop};
27-
use crate::{bundle::settings::Arch, Settings};
26+
use super::freedesktop;
27+
use crate::{bundle::settings::Arch, utils::fs_utils, Settings};
2828
use anyhow::Context;
2929
use flate2::{write::GzEncoder, Compression};
3030
use tar::HeaderMode;
@@ -73,7 +73,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
7373

7474
let (data_dir, _) = generate_data(settings, &package_dir)
7575
.with_context(|| "Failed to build data folders and files")?;
76-
common::copy_custom_files(&settings.deb().files, &data_dir)
76+
fs_utils::copy_custom_files(&settings.deb().files, &data_dir)
7777
.with_context(|| "Failed to copy custom files")?;
7878

7979
// Generate control files.
@@ -113,7 +113,7 @@ pub fn generate_data(
113113

114114
for bin in settings.binaries() {
115115
let bin_path = settings.binary_path(bin);
116-
common::copy_file(&bin_path, bin_dir.join(bin.name()))
116+
fs_utils::copy_file(&bin_path, &bin_dir.join(bin.name()))
117117
.with_context(|| format!("Failed to copy binary from {bin_path:?}"))?;
118118
}
119119

@@ -141,7 +141,7 @@ fn generate_changelog_file(settings: &Settings, data_dir: &Path) -> crate::Resul
141141
let product_name = settings.product_name();
142142
let dest_path = data_dir.join(format!("usr/share/doc/{product_name}/changelog.gz"));
143143

144-
let changelog_file = common::create_file(&dest_path)?;
144+
let changelog_file = fs_utils::create_file(&dest_path)?;
145145
let mut gzip_encoder = GzEncoder::new(changelog_file, Compression::new(9));
146146
io::copy(&mut src_file, &mut gzip_encoder)?;
147147

@@ -161,7 +161,7 @@ fn generate_control_file(
161161
// For more information about the format of this file, see
162162
// https://www.debian.org/doc/debian-policy/ch-controlfields.html
163163
let dest_path = control_dir.join("control");
164-
let mut file = common::create_file(&dest_path)?;
164+
let mut file = fs_utils::create_file(&dest_path)?;
165165
let package = heck::AsKebabCase(settings.product_name());
166166
writeln!(file, "Package: {}", package)?;
167167
writeln!(file, "Version: {}", settings.version_string())?;
@@ -294,7 +294,7 @@ fn create_script_file_from_path(from: &PathBuf, to: &PathBuf) -> crate::Result<(
294294
/// for each file within the `data_dir`.
295295
fn generate_md5sums(control_dir: &Path, data_dir: &Path) -> crate::Result<()> {
296296
let md5sums_path = control_dir.join("md5sums");
297-
let mut md5sums_file = common::create_file(&md5sums_path)?;
297+
let mut md5sums_file = fs_utils::create_file(&md5sums_path)?;
298298
for entry in WalkDir::new(data_dir) {
299299
let entry = entry?;
300300
let path = entry.path();
@@ -327,7 +327,7 @@ fn copy_resource_files(settings: &Settings, data_dir: &Path) -> crate::Result<()
327327
/// Create an empty file at the given path, creating any parent directories as
328328
/// needed, then write `data` into the file.
329329
fn create_file_with_data<P: AsRef<Path>>(path: P, data: &str) -> crate::Result<()> {
330-
let mut file = common::create_file(path.as_ref())?;
330+
let mut file = fs_utils::create_file(path.as_ref())?;
331331
file.write_all(data.as_bytes())?;
332332
file.flush()?;
333333
Ok(())
@@ -376,7 +376,7 @@ fn create_tar_from_dir<P: AsRef<Path>, W: Write>(src_dir: P, dest_file: W) -> cr
376376
fn tar_and_gzip_dir<P: AsRef<Path>>(src_dir: P) -> crate::Result<PathBuf> {
377377
let src_dir = src_dir.as_ref();
378378
let dest_path = src_dir.with_extension("tar.gz");
379-
let dest_file = common::create_file(&dest_path)?;
379+
let dest_file = fs_utils::create_file(&dest_path)?;
380380
let gzip_encoder = GzEncoder::new(dest_file, Compression::default());
381381
let gzip_encoder = create_tar_from_dir(src_dir, gzip_encoder)?;
382382
let mut dest_file = gzip_encoder.finish()?;
@@ -387,7 +387,7 @@ fn tar_and_gzip_dir<P: AsRef<Path>>(src_dir: P) -> crate::Result<PathBuf> {
387387
/// Creates an `ar` archive from the given source files and writes it to the
388388
/// given destination path.
389389
fn create_archive(srcs: Vec<PathBuf>, dest: &Path) -> crate::Result<()> {
390-
let mut builder = ar::Builder::new(common::create_file(dest)?);
390+
let mut builder = ar::Builder::new(fs_utils::create_file(dest)?);
391391
for path in &srcs {
392392
builder.append_path(path)?;
393393
}

crates/tauri-bundler/src/bundle/linux/freedesktop/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ use handlebars::Handlebars;
2626
use image::{self, codecs::png::PngDecoder, ImageDecoder};
2727
use serde::Serialize;
2828

29-
use crate::bundle::common;
30-
use crate::Settings;
29+
use crate::{
30+
utils::{self, fs_utils},
31+
Settings,
32+
};
3133

3234
#[derive(PartialEq, Eq, PartialOrd, Ord)]
3335
pub struct Icon {
@@ -65,7 +67,7 @@ pub fn list_icon_files(
6567
let decoder = PngDecoder::new(BufReader::new(File::open(&icon_path)?))?;
6668
let width = decoder.dimensions().0;
6769
let height = decoder.dimensions().1;
68-
let is_high_density = common::is_retina(&icon_path);
70+
let is_high_density = utils::is_retina(&icon_path);
6971
let dest_path = get_dest_path(width, height, is_high_density);
7072
Icon {
7173
width,
@@ -84,7 +86,7 @@ pub fn list_icon_files(
8486
pub fn copy_icon_files(settings: &Settings, data_dir: &Path) -> crate::Result<Vec<Icon>> {
8587
let icons = list_icon_files(settings, data_dir)?;
8688
for (icon, src) in &icons {
87-
common::copy_file(src, &icon.path)?;
89+
fs_utils::copy_file(src, &icon.path)?;
8890
}
8991

9092
Ok(icons.into_keys().collect())
@@ -105,7 +107,7 @@ pub fn generate_desktop_file(
105107
let path = PathBuf::from("usr/share/applications").join(desktop_file_name);
106108
let dest_path = PathBuf::from("/").join(&path);
107109
let file_path = data_dir.join(&path);
108-
let file = &mut common::create_file(&file_path)?;
110+
let file = &mut fs_utils::create_file(&file_path)?;
109111

110112
let mut handlebars = Handlebars::new();
111113
handlebars.register_escape_fn(handlebars::no_escape);

crates/tauri-bundler/src/bundle/macos/app.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
// files into the `Contents` directory of the bundle.
2424

2525
use super::{
26-
super::common::{self, CommandExt},
2726
icon::create_icns_file,
2827
sign::{notarize, notarize_auth, sign, NotarizeAuthError, SignTarget},
2928
};
30-
use crate::Settings;
29+
use crate::{
30+
utils::{fs_utils, CommandExt},
31+
Settings,
32+
};
3133

3234
use anyhow::Context;
3335

@@ -157,7 +159,7 @@ fn copy_binaries_to_bundle(
157159
for bin in settings.binaries() {
158160
let bin_path = settings.binary_path(bin);
159161
let dest_path = dest_dir.join(bin.name());
160-
common::copy_file(&bin_path, &dest_path)
162+
fs_utils::copy_file(&bin_path, &dest_path)
161163
.with_context(|| format!("Failed to copy binary from {:?}", bin_path))?;
162164
paths.push(dest_path);
163165
}
@@ -173,10 +175,10 @@ fn copy_custom_files_to_bundle(bundle_directory: &Path, settings: &Settings) ->
173175
contents_path
174176
};
175177
if path.is_file() {
176-
common::copy_file(path, bundle_directory.join(contents_path))
178+
fs_utils::copy_file(path, &bundle_directory.join(contents_path))
177179
.with_context(|| format!("Failed to copy file {:?} to {:?}", path, contents_path))?;
178180
} else {
179-
common::copy_dir(path, &bundle_directory.join(contents_path))
181+
fs_utils::copy_dir(path, &bundle_directory.join(contents_path))
180182
.with_context(|| format!("Failed to copy directory {:?} to {:?}", path, contents_path))?;
181183
}
182184
}
@@ -349,7 +351,7 @@ fn copy_framework_from(dest_dir: &Path, framework: &str, src_dir: &Path) -> crat
349351
let src_name = format!("{}.framework", framework);
350352
let src_path = src_dir.join(&src_name);
351353
if src_path.exists() {
352-
common::copy_dir(&src_path, &dest_dir.join(&src_name))?;
354+
fs_utils::copy_dir(&src_path, &dest_dir.join(&src_name))?;
353355
Ok(true)
354356
} else {
355357
Ok(false)
@@ -382,7 +384,7 @@ fn copy_frameworks_to_bundle(
382384
.file_name()
383385
.expect("Couldn't get framework filename");
384386
let dest_path = dest_dir.join(src_name);
385-
common::copy_dir(&src_path, &dest_path)?;
387+
fs_utils::copy_dir(&src_path, &dest_path)?;
386388
add_framework_sign_path(&src_path, &dest_path, &mut paths);
387389
continue;
388390
} else if framework.ends_with(".dylib") {
@@ -395,7 +397,7 @@ fn copy_frameworks_to_bundle(
395397
}
396398
let src_name = src_path.file_name().expect("Couldn't get library filename");
397399
let dest_path = dest_dir.join(src_name);
398-
common::copy_file(&src_path, &dest_path)?;
400+
fs_utils::copy_file(&src_path, &dest_path)?;
399401
paths.push(SignTarget {
400402
path: dest_path,
401403
is_an_executable: false,

crates/tauri-bundler/src/bundle/macos/dmg/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
use super::{app, icon::create_icns_file};
77
use crate::{
8-
bundle::{common::CommandExt, settings::Arch, Bundle},
8+
bundle::{settings::Arch, Bundle},
9+
utils::CommandExt,
910
PackageType, Settings,
1011
};
1112

crates/tauri-bundler/src/bundle/macos/icon.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// SPDX-License-Identifier: Apache-2.0
44
// SPDX-License-Identifier: MIT
55

6-
use crate::bundle::{common, Settings};
6+
use crate::bundle::Settings;
7+
use crate::utils::{self, fs_utils};
78
use std::{
89
cmp::min,
910
ffi::OsStr,
@@ -28,7 +29,7 @@ pub fn create_icns_file(out_dir: &Path, settings: &Settings) -> crate::Result<Op
2829
if icon_path.extension() == Some(OsStr::new("icns")) {
2930
let mut dest_path = out_dir.to_path_buf();
3031
dest_path.push(icon_path.file_name().expect("Could not get icon filename"));
31-
common::copy_file(&icon_path, &dest_path)?;
32+
fs_utils::copy_file(&icon_path, &dest_path)?;
3233
return Ok(Some(dest_path));
3334
}
3435
}
@@ -63,7 +64,7 @@ pub fn create_icns_file(out_dir: &Path, settings: &Settings) -> crate::Result<Op
6364
for icon_path in settings.icon_files() {
6465
let icon_path = icon_path?;
6566
let icon = image::open(&icon_path)?;
66-
let density = if common::is_retina(&icon_path) { 2 } else { 1 };
67+
let density = if utils::is_retina(&icon_path) { 2 } else { 1 };
6768
let (w, h) = icon.dimensions();
6869
let orig_size = min(w, h);
6970
let next_size_down = 2f32.powf((orig_size as f32).log2().floor()) as u32;

0 commit comments

Comments
 (0)