Skip to content

Commit

Permalink
Merge pull request #358 from ros-drivers/resolve-symlinked-dev-path
Browse files Browse the repository at this point in the history
Correctly resolve symlinks to device paths
  • Loading branch information
flynneva authored Feb 8, 2025
2 parents 0dc42a4 + c62771c commit 12e12bc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/usb_cam_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,15 @@ void UsbCamNode::service_capture(
std::string resolve_device_path(const std::string & path)
{
if (std::filesystem::is_symlink(path)) {
// For some reason read_symlink only returns videox
return "/dev/" + std::string(std::filesystem::read_symlink(path));
std::filesystem::path target_path = std::filesystem::read_symlink(path);

// if the target path is relative, resolve it
if (target_path.is_relative()) {
target_path = std::filesystem::absolute(path).parent_path() / target_path;
target_path = std::filesystem::canonical(target_path);
}

return target_path.string();
}
return path;
}
Expand Down

0 comments on commit 12e12bc

Please sign in to comment.