From 86b56e445fa75798f12330a1b23d2cd2a3b4c724 Mon Sep 17 00:00:00 2001 From: Anomalocaridid <29845794+Anomalocaridid@users.noreply.github.com> Date: Tue, 30 Jul 2024 16:54:49 -0400 Subject: [PATCH 1/3] fix: fix terminal applications not launching properly --- src/common/desktop_entry.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/desktop_entry.rs b/src/common/desktop_entry.rs index 6ce787b..62973fe 100644 --- a/src/common/desktop_entry.rs +++ b/src/common/desktop_entry.rs @@ -143,7 +143,8 @@ impl DesktopEntry { // If the entry expects a terminal (emulator), but this process is not running in one, we // launch a new one. - if self.terminal && config.terminal_output { + // TODO: make regression test (currently infeasible with terminal method's reliance on system state) + if self.terminal && !config.terminal_output { let term_cmd = config.terminal(selector, use_selector)?; exec = shlex::split(&term_cmd) .ok_or_else(|| Error::from(ErrorKind::BadCmd(term_cmd)))? From 0e1ee0b9de0e8ef05c7f196eee1f0b5633b456e8 Mon Sep 17 00:00:00 2001 From: Anomalocaridid <29845794+Anomalocaridid@users.noreply.github.com> Date: Tue, 30 Jul 2024 18:31:00 -0400 Subject: [PATCH 2/3] fix: do not discard `application/x-zerosize` results for empty, extensionless files --- src/common/mime_types.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/common/mime_types.rs b/src/common/mime_types.rs index 2baf46b..c54de61 100644 --- a/src/common/mime_types.rs +++ b/src/common/mime_types.rs @@ -40,12 +40,16 @@ impl TryFrom<&Path> for MimeType { guess.file_name(&path.to_string_lossy()); let mime = if let Some(mime) = - mime_to_option(&db, guess.guess().mime_type().clone()) + mime_to_option(&db, guess.guess().mime_type().clone(), true) { mime } else { - mime_to_option(&db, guess.path(path).guess().mime_type().clone()) - .ok_or_else(|| ErrorKind::Ambiguous(path.to_owned()))? + mime_to_option( + &db, + guess.path(path).guess().mime_type().clone(), + false, + ) + .ok_or_else(|| ErrorKind::Ambiguous(path.to_owned()))? }; Ok(Self(mime)) @@ -53,11 +57,16 @@ impl TryFrom<&Path> for MimeType { } /// Tests if a given mime is "acceptable" and returns None otherwise -fn mime_to_option(db: &xdg_mime::SharedMimeInfo, mime: Mime) -> Option { +fn mime_to_option( + db: &xdg_mime::SharedMimeInfo, + mime: Mime, + discard_zerosize: bool, +) -> Option { let application_zerosize: Mime = "application/x-zerosize".parse().ok()?; if mime == mime::APPLICATION_OCTET_STREAM - || db.mime_type_equal(&mime, &application_zerosize) + || (db.mime_type_equal(&mime, &application_zerosize) + && discard_zerosize) { None } else { From 5b07276cb42b13c6e4012350a819b233b5cbbfe4 Mon Sep 17 00:00:00 2001 From: Anomalocaridid <29845794+Anomalocaridid@users.noreply.github.com> Date: Tue, 30 Jul 2024 18:37:32 -0400 Subject: [PATCH 3/3] tests: add regression test for the mime of empty, extensionless files --- src/common/mime_types.rs | 4 ++++ tests/empty | 0 2 files changed, 4 insertions(+) create mode 100644 tests/empty diff --git a/src/common/mime_types.rs b/src/common/mime_types.rs index c54de61..63c1c91 100644 --- a/src/common/mime_types.rs +++ b/src/common/mime_types.rs @@ -147,6 +147,10 @@ mod tests { MimeType::try_from(Path::new("./tests/no_html_tags.html"))?.0, "text/html" ); + assert_eq!( + MimeType::try_from(Path::new("./tests/empty"))?.0, + "application/x-zerosize" + ); Ok(()) } diff --git a/tests/empty b/tests/empty new file mode 100644 index 0000000..e69de29