[keel] Add/cleanup UUID/path lookup functions

This commit is contained in:
Gary Talent 2024-05-22 00:32:49 -05:00
parent 76771e7bdd
commit c47f48eba7
3 changed files with 21 additions and 7 deletions

View File

@ -93,9 +93,13 @@ void createUuidMapping(Context &ctx, ox::StringView filePath, ox::UUID const&uui
ox::Error buildUuidMap(Context &ctx) noexcept; ox::Error buildUuidMap(Context &ctx) noexcept;
ox::Result<ox::String> uuidToPath(Context &ctx, ox::CRStringView uuid) noexcept; ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::CRStringView path) noexcept;
ox::Result<ox::String> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept; ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noexcept;
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::CRStringView uuid) noexcept;
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept;
ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept; ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept;

View File

@ -83,19 +83,29 @@ ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::CRStringView path) noexcept {
#endif #endif
} }
ox::Result<ox::String> uuidToPath(Context &ctx, ox::CRStringView uuid) noexcept { ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noexcept {
uuid = substr(uuid, 7);
#ifndef OX_BARE_METAL #ifndef OX_BARE_METAL
oxRequireM(out, ctx.uuidToPath.at(uuid)); oxRequireM(out, ctx.uuidToPath.at(uuid));
return std::move(*out); return ox::CStringView(*out);
#else #else
return OxError(1, "UUID to path conversion not supported on this platform"); return OxError(1, "UUID to path conversion not supported on this platform");
#endif #endif
} }
ox::Result<ox::String> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept { ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::CRStringView uuid) noexcept {
#ifndef OX_BARE_METAL
oxRequireM(out, ctx.uuidToPath.at(uuid));
return ox::CStringView(*out);
#else
return OxError(1, "UUID to path conversion not supported on this platform");
#endif
}
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept {
#ifndef OX_BARE_METAL #ifndef OX_BARE_METAL
oxRequireM(out, ctx.uuidToPath.at(uuid.toString())); oxRequireM(out, ctx.uuidToPath.at(uuid.toString()));
return std::move(*out); return ox::CStringView(*out);
#else #else
return OxError(1, "UUID to path conversion not supported on this platform"); return OxError(1, "UUID to path conversion not supported on this platform");
#endif #endif

View File

@ -30,7 +30,7 @@ static ox::Error pathToInode(
} }
if (beginsWith(path, "uuid://")) { if (beginsWith(path, "uuid://")) {
auto const uuid = ox::substr(path, 7); auto const uuid = ox::substr(path, 7);
oxReturnError(keel::uuidToPath(ctx, uuid).moveTo(path)); oxReturnError(keel::uuidToPath(ctx, uuid).to<ox::String>().moveTo(path));
} }
oxRequire(s, dest.stat(path)); oxRequire(s, dest.stat(path));
oxReturnError(o.at("type").unwrap()->set(static_cast<int8_t>(ox::FileAddressType::Inode))); oxReturnError(o.at("type").unwrap()->set(static_cast<int8_t>(ox::FileAddressType::Inode)));