From 61c66aeb68f875c85837ce67d49ba7f93b97ed53 Mon Sep 17 00:00:00 2001 From: CEbbinghaus Date: Fri, 27 Sep 2024 02:17:01 +1000 Subject: [PATCH] Bugfix: Fixed card labels with escaped ascii characters (#46) * Unscaping card label to get proper mount name * Updated Version --- backend/Cargo.lock | 10 ++++++++++ backend/Cargo.toml | 1 + backend/src/watch.rs | 35 +++++++++++++++++++++++++++++++---- backend/version | 2 +- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index e568fe6..4e47b26 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -330,6 +330,7 @@ dependencies = [ "tracing", "tracing-appender", "tracing-subscriber", + "unescaper", ] [[package]] @@ -1924,6 +1925,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" +[[package]] +name = "unescaper" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c878a167baa8afd137494101a688ef8c67125089ff2249284bd2b5f9bfedb815" +dependencies = [ + "thiserror", +] + [[package]] name = "unicode-bidi" version = "0.3.13" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 2c691fb..6347a5c 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -28,6 +28,7 @@ lazy_static = "1.4.0" tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["json"] } tracing-appender = "0.2.3" +unescaper = "0.1.5" [dev-dependencies] criterion = { version = "0.4", features = ["html_reports"] } diff --git a/backend/src/watch.rs b/backend/src/watch.rs index fa632d6..18af9c9 100644 --- a/backend/src/watch.rs +++ b/backend/src/watch.rs @@ -99,11 +99,38 @@ fn find_mount_name() -> Result, Error> { .filter_map(|dir| dir.ok()) { trace!(path = ?entry.path().canonicalize()?, "testing label for mount point of MicroSD Card"); - if entry.path().canonicalize()? == PathBuf::from("/dev/mmcblk0p1") { - let label = entry.file_name(); - info!(label = ?label, "Found MicroSD Card label"); - return Ok(Some(label.to_string_lossy().to_string())); + if entry.path().canonicalize()? != PathBuf::from("/dev/mmcblk0p1") { + continue; + } + + let raw_mount_name: String = match entry.file_name().to_str() { + Some(v) => v.to_owned(), + None => { + error!("Failed to convert mount point to string"); + return Ok(None); + } + }; + + // apparently the label will occasionally contain ascii escape characters like \x20 + let mount_name = match unescaper::unescape(&raw_mount_name) { + Ok(v) => v, + Err(err) => { + error!(%err, "Failed to unescape mount point"); + return Ok(None); + } + }; + + info!(mount = mount_name, "Found MicroSD Card mount label"); + + if !has_libraryfolder(&Some(mount_name.clone())) { + warn!( + mount = mount_name, + "Mount point does not resolve library folder" + ); + return Ok(None); } + + return Ok(Some(mount_name)); } Ok(None) diff --git a/backend/version b/backend/version index 75955dd..cd47247 100644 --- a/backend/version +++ b/backend/version @@ -1 +1 @@ -0.10.9 \ No newline at end of file +0.10.10 \ No newline at end of file