Skip to content

Commit 12e12bc

Browse files
authored
Merge pull request #358 from ros-drivers/resolve-symlinked-dev-path
Correctly resolve symlinks to device paths
2 parents 0dc42a4 + c62771c commit 12e12bc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/usb_cam_node.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,15 @@ void UsbCamNode::service_capture(
124124
std::string resolve_device_path(const std::string & path)
125125
{
126126
if (std::filesystem::is_symlink(path)) {
127-
// For some reason read_symlink only returns videox
128-
return "/dev/" + std::string(std::filesystem::read_symlink(path));
127+
std::filesystem::path target_path = std::filesystem::read_symlink(path);
128+
129+
// if the target path is relative, resolve it
130+
if (target_path.is_relative()) {
131+
target_path = std::filesystem::absolute(path).parent_path() / target_path;
132+
target_path = std::filesystem::canonical(target_path);
133+
}
134+
135+
return target_path.string();
129136
}
130137
return path;
131138
}

0 commit comments

Comments
 (0)