Skip to content

Commit

Permalink
Bugfix: Fixed card labels with escaped ascii characters (#46)
Browse files Browse the repository at this point in the history
* Unscaping card label to get proper mount name
* Updated Version
  • Loading branch information
CEbbinghaus authored Sep 26, 2024
1 parent 6a1a2d3 commit 61c66ae
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
10 changes: 10 additions & 0 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
35 changes: 31 additions & 4 deletions backend/src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,38 @@ fn find_mount_name() -> Result<Option<String>, 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)
Expand Down
2 changes: 1 addition & 1 deletion backend/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.9
0.10.10

0 comments on commit 61c66ae

Please sign in to comment.