Skip to content

Commit

Permalink
Unscaping card label to get proper mount name
Browse files Browse the repository at this point in the history
  • Loading branch information
CEbbinghaus committed Sep 26, 2024
1 parent 6a1a2d3 commit d6af215
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 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
28 changes: 24 additions & 4 deletions backend/src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,31 @@ 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 mount = entry.file_name();
info!(mount = ?mount, "Found MicroSD Card mount label");

// apparently the label will occasionally contain ascii escape characters like \x20
let unescaped = match unescaper::unescape(mount) {
Ok(v) => v,
Err(err) => {
error!(%err, "Failed to unescape mount point");
return Ok(None);
}
};

if !has_libraryfolder(Some(mount)) {
warn!(
mount = unescaped,
"Mount point does not resolve library folder"
);
return Ok(None);
}

return Ok(Some(unescaped));
}

Ok(None)
Expand Down

0 comments on commit d6af215

Please sign in to comment.