| 253 | } |
| 254 | |
| 255 | fextl::string ExpandPath(const fextl::string& ContainerPrefix, const fextl::string& PathName) { |
| 256 | if (PathName.empty()) { |
| 257 | return {}; |
| 258 | } |
| 259 | |
| 260 | // Expand home if it exists |
| 261 | if (FHU::Filesystem::IsRelative(PathName)) { |
| 262 | fextl::string Home = getenv("HOME") ?: ""; |
| 263 | // Home expansion only works if it is the first character |
| 264 | // This matches bash behaviour |
| 265 | if (PathName.starts_with("~/")) { |
| 266 | Home.append(PathName.begin() + 1, PathName.end()); |
| 267 | return Home; |
| 268 | } |
| 269 | |
| 270 | // Expand relative path to absolute |
| 271 | char ExistsTempPath[PATH_MAX]; |
| 272 | char* RealPath = FHU::Filesystem::Absolute(PathName.c_str(), ExistsTempPath); |
| 273 | if (RealPath && FHU::Filesystem::Exists(RealPath)) { |
| 274 | return RealPath; |
| 275 | } |
| 276 | |
| 277 | // Only return if it exists |
| 278 | if (FHU::Filesystem::Exists(PathName)) { |
| 279 | return PathName; |
| 280 | } |
| 281 | } else { |
| 282 | // If the containerprefix and pathname isn't empty |
| 283 | // Then we check if the pathname exists in our current namespace |
| 284 | // If the path DOESN'T exist but DOES exist with the prefix applied |
| 285 | // then redirect to the prefix |
| 286 | // |
| 287 | // This might not be expected behaviour for some edge cases but since |
| 288 | // all paths aren't mounted inside the container, then it'll be fine |
| 289 | // |
| 290 | // Main catch case for this is the default thunk install folders |
| 291 | // HostThunks: $CMAKE_INSTALL_PREFIX/lib/fex-emu/HostThunks/ |
| 292 | // GuestThunks: $CMAKE_INSTALL_PREFIX/share/fex-emu/GuestThunks/ |
| 293 | if (!ContainerPrefix.empty() && !PathName.empty()) { |
| 294 | if (!FHU::Filesystem::Exists(PathName)) { |
| 295 | auto ContainerPath = ContainerPrefix + PathName; |
| 296 | if (FHU::Filesystem::Exists(ContainerPath)) { |
| 297 | return ContainerPath; |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | return {}; |
| 303 | } |
| 304 | |
| 305 | constexpr char ContainerManager[] = "/run/host/container-manager"; |
| 306 |
no test coverage detected