Skip to content

Commit 8817294

Browse files
authored
fix(cli): Ignore file access events (#12164)
1 parent cd841d8 commit 8817294

File tree

14 files changed

+72
-57
lines changed

14 files changed

+72
-57
lines changed

.changes/ignore-notify-access-type.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
tauri-cli: 'patch:bug'
3+
'@tauri-apps/cli': 'patch:bug'
4+
---
5+
6+
Fixed an issue that caused `tauri dev` to crash before showing the app on Linux.

Cargo.lock

+15-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bench/tests/files_transfer/src-tauri/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async fn read_file<R: Runtime>(app: AppHandle<R>) -> Result<Response, String> {
1818
.path()
1919
.resolve(".tauri_3mb.json", BaseDirectory::Home)
2020
.map_err(|e| e.to_string())?;
21-
let contents = read(&path).map_err(|e| e.to_string())?;
21+
let contents = read(path).map_err(|e| e.to_string())?;
2222
Ok(Response::new(contents))
2323
}
2424

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
5656
let product_name = settings.product_name();
5757

5858
let mut settings = settings.clone();
59-
if main_binary.name().contains(" ") {
59+
if main_binary.name().contains(' ') {
6060
let main_binary_path = settings.binary_path(main_binary);
6161
let project_out_directory = settings.project_out_directory();
6262

@@ -108,7 +108,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
108108

109109
// Using create_dir_all for a single dir so we don't get errors if the path already exists
110110
fs::create_dir_all(&app_dir_usr_bin)?;
111-
fs::create_dir_all(&app_dir_usr_lib)?;
111+
fs::create_dir_all(app_dir_usr_lib)?;
112112

113113
// Copy bins and libs that linuxdeploy doesn't know about
114114

@@ -258,7 +258,7 @@ fn prepare_tools(tools_path: &Path, arch: &str) -> crate::Result<PathBuf> {
258258
fn write_and_make_executable(path: &Path, data: Vec<u8>) -> std::io::Result<()> {
259259
use std::os::unix::fs::PermissionsExt;
260260

261-
fs::write(path, &data)?;
261+
fs::write(path, data)?;
262262
fs::set_permissions(path, fs::Permissions::from_mode(0o770))?;
263263

264264
Ok(())

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub fn generate_desktop_file(
153153

154154
let mime_type = (!mime_type.is_empty()).then_some(mime_type.join(";"));
155155

156-
let bin_name_exec = if bin_name.contains(" ") {
156+
let bin_name_exec = if bin_name.contains(' ') {
157157
format!("\"{bin_name}\"")
158158
} else {
159159
bin_name.to_string()

crates/tauri-cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ colored = "2"
5252
serde = { version = "1", features = ["derive"] }
5353
serde_json = { version = "1", features = ["preserve_order"] }
5454
notify = "7"
55-
notify-debouncer-mini = "0.5"
55+
notify-debouncer-full = "0.4"
5656
shared_child = "1"
5757
duct = "0.13"
5858
toml_edit = { version = "0.22", features = ["serde"] }

crates/tauri-cli/src/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
8787

8888
let bin_path = interface.build(interface_options)?;
8989

90-
log::info!(action ="Built"; "application at: {}", tauri_utils::display_path(&bin_path));
90+
log::info!(action ="Built"; "application at: {}", tauri_utils::display_path(bin_path));
9191

9292
let app_settings = interface.app_settings();
9393

crates/tauri-cli/src/dev/builtin_dev_server.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,10 @@ fn watch<F: Fn() + Send + 'static>(dir: PathBuf, handler: F) {
162162
thread::spawn(move || {
163163
let (tx, rx) = std::sync::mpsc::channel();
164164

165-
let mut watcher = notify_debouncer_mini::new_debouncer(Duration::from_secs(1), tx)
165+
let mut watcher = notify_debouncer_full::new_debouncer(Duration::from_secs(1), None, tx)
166166
.expect("failed to start builtin server fs watcher");
167167

168168
watcher
169-
.watcher()
170169
.watch(&dir, notify::RecursiveMode::Recursive)
171170
.expect("builtin server failed to watch dir");
172171

crates/tauri-cli/src/interface/rust.rs

+35-36
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use anyhow::Context;
1818
use glob::glob;
1919
use ignore::gitignore::{Gitignore, GitignoreBuilder};
2020
use notify::RecursiveMode;
21-
use notify_debouncer_mini::new_debouncer;
21+
use notify_debouncer_full::new_debouncer;
2222
use serde::{Deserialize, Deserializer};
2323
use tauri_bundler::{
2424
AppCategory, AppImageSettings, BundleBinary, BundleSettings, DebianSettings, DmgSettings,
@@ -124,15 +124,13 @@ impl Interface for Rust {
124124
fn new(config: &Config, target: Option<String>) -> crate::Result<Self> {
125125
let manifest = {
126126
let (tx, rx) = sync_channel(1);
127-
let mut watcher = new_debouncer(Duration::from_secs(1), move |r| {
127+
let mut watcher = new_debouncer(Duration::from_secs(1), None, move |r| {
128128
if let Ok(events) = r {
129129
let _ = tx.send(events);
130130
}
131131
})
132132
.unwrap();
133-
watcher
134-
.watcher()
135-
.watch(&tauri_dir().join("Cargo.toml"), RecursiveMode::Recursive)?;
133+
watcher.watch(tauri_dir().join("Cargo.toml"), RecursiveMode::Recursive)?;
136134
let (manifest, _modified) = rewrite_manifest(config)?;
137135
let now = Instant::now();
138136
let timeout = Duration::from_secs(2);
@@ -527,7 +525,7 @@ impl Rust {
527525
.expect("watch_folders should not be empty");
528526
let ignore_matcher = build_ignore_matcher(&common_ancestor);
529527

530-
let mut watcher = new_debouncer(Duration::from_secs(1), move |r| {
528+
let mut watcher = new_debouncer(Duration::from_secs(1), None, move |r| {
531529
if let Ok(events) = r {
532530
tx.send(events).unwrap()
533531
}
@@ -539,7 +537,7 @@ impl Rust {
539537
lookup(&path, |file_type, p| {
540538
if p != path {
541539
log::debug!("Watching {} for changes...", display_path(&p));
542-
let _ = watcher.watcher().watch(
540+
let _ = watcher.watch(
543541
&p,
544542
if file_type.is_dir() {
545543
RecursiveMode::Recursive
@@ -555,42 +553,43 @@ impl Rust {
555553
loop {
556554
if let Ok(events) = rx.recv() {
557555
for event in events {
558-
let event_path = event.path;
559-
560-
if !ignore_matcher.is_ignore(&event_path, event_path.is_dir()) {
561-
if is_configuration_file(self.app_settings.target, &event_path) {
562-
if let Ok(config) = reload_config(config.as_ref()) {
563-
let (manifest, modified) =
564-
rewrite_manifest(config.lock().unwrap().as_ref().unwrap())?;
565-
if modified {
566-
*self.app_settings.manifest.lock().unwrap() = manifest;
567-
// no need to run the watcher logic, the manifest was modified
568-
// and it will trigger the watcher again
569-
continue;
556+
#[cfg(target_os = "linux")]
557+
if event.kind.is_access() {
558+
continue;
559+
}
560+
561+
if let Some(event_path) = event.paths.first() {
562+
if !ignore_matcher.is_ignore(event_path, event_path.is_dir()) {
563+
if is_configuration_file(self.app_settings.target, event_path) {
564+
if let Ok(config) = reload_config(config.as_ref()) {
565+
let (manifest, modified) =
566+
rewrite_manifest(config.lock().unwrap().as_ref().unwrap())?;
567+
if modified {
568+
*self.app_settings.manifest.lock().unwrap() = manifest;
569+
// no need to run the watcher logic, the manifest was modified
570+
// and it will trigger the watcher again
571+
continue;
572+
}
570573
}
571574
}
572-
}
573575

574-
log::info!(
575-
"File {} changed. Rebuilding application...",
576-
display_path(
577-
event_path
578-
.strip_prefix(frontend_path)
579-
.unwrap_or(&event_path)
580-
)
581-
);
576+
log::info!(
577+
"File {} changed. Rebuilding application...",
578+
display_path(event_path.strip_prefix(frontend_path).unwrap_or(event_path))
579+
);
582580

583-
let mut p = process.lock().unwrap();
584-
p.kill().with_context(|| "failed to kill app process")?;
581+
let mut p = process.lock().unwrap();
582+
p.kill().with_context(|| "failed to kill app process")?;
585583

586-
// wait for the process to exit
587-
// note that on mobile, kill() already waits for the process to exit (duct implementation)
588-
loop {
589-
if !matches!(p.try_wait(), Ok(None)) {
590-
break;
584+
// wait for the process to exit
585+
// note that on mobile, kill() already waits for the process to exit (duct implementation)
586+
loop {
587+
if !matches!(p.try_wait(), Ok(None)) {
588+
break;
589+
}
591590
}
591+
*p = run(self)?;
592592
}
593-
*p = run(self)?;
594593
}
595594
}
596595
}

crates/tauri-macros/src/command/wrapper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ fn rustc_version() -> (u32, u32) {
478478
.split(' ')
479479
.nth(1)
480480
.unwrap_or_default()
481-
.split(".")
481+
.split('.')
482482
.take(2)
483483
.flat_map(|p| p.parse::<u32>().ok())
484484
.collect::<Vec<_>>();

crates/tauri-runtime-wry/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2682,7 +2682,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
26822682
pending,
26832683
)?;
26842684

2685-
#[allow(clippy::manual_inspect)]
2685+
#[allow(unknown_lints, clippy::manual_inspect)]
26862686
self
26872687
.context
26882688
.main_thread
@@ -3311,7 +3311,7 @@ fn handle_user_message<T: UserEvent>(
33113311
let _ = webview.print();
33123312
}
33133313
WebviewMessage::Close => {
3314-
#[allow(clippy::manual_inspect)]
3314+
#[allow(unknown_lints, clippy::manual_inspect)]
33153315
windows.0.borrow_mut().get_mut(&window_id).map(|window| {
33163316
if let Some(i) = window.webviews.iter().position(|w| w.id == webview.id) {
33173317
window.webviews.remove(i);
@@ -3535,7 +3535,7 @@ fn handle_user_message<T: UserEvent>(
35353535
if let Some(window) = window {
35363536
match handler(&window) {
35373537
Ok(webview) => {
3538-
#[allow(clippy::manual_inspect)]
3538+
#[allow(unknown_lints, clippy::manual_inspect)]
35393539
windows.0.borrow_mut().get_mut(&window_id).map(|w| {
35403540
w.webviews.push(webview);
35413541
w.has_children.store(true, Ordering::Relaxed);

crates/tauri-utils/src/platform.rs

+1
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ mod tests {
396396
assert_eq!(resource_dir, path.parent().unwrap());
397397

398398
let path = PathBuf::from("/path/to/target/unknown-profile/app");
399+
#[allow(clippy::needless_borrows_for_generic_args)]
399400
let resource_dir = super::resource_dir_from(&path, &package_info, &env);
400401
#[cfg(target_os = "macos")]
401402
assert!(resource_dir.is_err());

crates/tauri/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ permissions = [{}]
428428
.join(",")
429429
);
430430

431-
write_if_changed(&default_toml, toml_content)
431+
write_if_changed(default_toml, toml_content)
432432
.unwrap_or_else(|_| panic!("unable to autogenerate core:default set"));
433433

434434
let _ = tauri_utils::acl::build::define_permissions(

examples/file-associations/src-tauri/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn handle_file_associations(app: AppHandle, files: Vec<PathBuf>) {
3535
let files = files
3636
.into_iter()
3737
.map(|f| {
38-
let file = f.to_string_lossy().replace("\\", "\\\\"); // escape backslash
38+
let file = f.to_string_lossy().replace('\\', "\\\\"); // escape backslash
3939
format!("\"{file}\"",) // wrap in quotes for JS array
4040
})
4141
.collect::<Vec<_>>()
@@ -59,7 +59,7 @@ fn main() {
5959
// files may aslo be passed as `file://path/to/file`
6060
for maybe_file in std::env::args().skip(1) {
6161
// skip flags like -f or --flag
62-
if maybe_file.starts_with("-") {
62+
if maybe_file.starts_with('-') {
6363
continue;
6464
}
6565

0 commit comments

Comments
 (0)