Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Fixed card labels with escaped ascii characters #46

Merged
merged 5 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading