Skip to content

Commit

Permalink
[Core] Full file:// syntax support
Browse files Browse the repository at this point in the history
Closes #14. Fully support `file` URLs by making use the OpenAssetIO
`FileUrlPathConverter` utility.

The utility will throw on non-`file` URLs being provided, maintaining
existing behaviour (with a slightly different error message). Confirmed
with manual testing.

The `FileUrlPathConverter` utility is only available as of OpenAssetIO
1.0.0-beta.2.0. So update README.

Signed-off-by: David Feltell <[email protected]>
  • Loading branch information
feltech committed Jun 12, 2024
1 parent e2a4446 commit 0929e55
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 37 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ limitations.

## Dependencies

### [OpenAssetIO](https://github.com/OpenAssetIO/OpenAssetIO/) (1.0.0-alpha.14)
### [OpenAssetIO](https://github.com/OpenAssetIO/OpenAssetIO/) (1.0.0-beta.2.0)

Currently, OpenAssetIO must be built from source to build
`usdOpenAssetIOResolver`.
The OpenAssetIO libary is available pre-built for some common platforms
are available
[here](https://github.com/OpenAssetIO/OpenAssetIO/releases).

The steps to do this can be found
[here.](https://github.com/OpenAssetIO/OpenAssetIO/blob/main/doc/BUILDING.md)
Alternatively, OpenAssetIO can be built from source. The steps to do
this can be found
[here](https://github.com/OpenAssetIO/OpenAssetIO/blob/main/doc/BUILDING.md).

### [USD](https://github.com/PixarAnimationStudios/USD) (22.11)

Expand Down
41 changes: 10 additions & 31 deletions src/resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "resolver.h"

#include <optional>
#include <stdexcept>
#include <thread>

Expand All @@ -20,7 +21,7 @@
#include <openassetio/log/LoggerInterface.hpp>
#include <openassetio/log/SeverityFilter.hpp>
#include <openassetio/python/hostApi.hpp>
#include <openassetio/trait/TraitsData.hpp>
#include <openassetio/utils/path.hpp>

#include <openassetio_mediacreation/traits/content/LocatableContentTrait.hpp>

Expand All @@ -35,21 +36,6 @@ TF_DEBUG_CODES(OPENASSETIO_RESOLVER)
PXR_NAMESPACE_CLOSE_SCOPE

namespace {
/*
* Replaces all occurrences of the search string in the subject with
* the supplied replacement.
*/
void replaceAllInString(std::string &subject, const std::string &search,
const std::string &replace) {
const size_t searchLength = search.length();
const size_t replaceLength = replace.length();
size_t pos = 0;
while ((pos = subject.find(search, pos)) != std::string::npos) {
subject.replace(pos, searchLength, replace);
pos += replaceLength;
}
}

/*
* OpenAssetIO LoggerInterface implementation
*
Expand Down Expand Up @@ -239,27 +225,20 @@ class UsdOpenAssetIOResolver::Impl {
const openassetio::trait::TraitsDataPtr traitsData = manager_->resolve(
entityReference, {LocatableContentTrait::kId}, ResolveAccess::kRead, context_);

// OpenAssetIO is URL based, but we need a path, so check the
// scheme and decode into a path

static constexpr std::string_view kFileURLScheme{"file://"};
static constexpr std::size_t kProtocolSize = kFileURLScheme.size();

openassetio::Str url = LocatableContentTrait(traitsData).getLocation();
if (url.rfind(kFileURLScheme, 0) == openassetio::Str::npos) {
std::string msg = "Only file URLs are supported: ";
msg += url;
throw std::runtime_error(msg);
const std::optional<openassetio::Str> url = LocatableContentTrait(traitsData).getLocation();
if (!url) {
throw std::invalid_argument{"Entity reference does not have a location: " +
entityReference.toString()};
}

// TODO(tc): Decode % escape sequences properly
replaceAllInString(url, "%20", " ");
return url.substr(kProtocolSize);
// OpenAssetIO is URL based, but we need a path. Note: will throw if
// the URL is not valid.
return fileUrlPathConverter_.pathFromUrl(*url);
}

openassetio::log::LoggerInterfacePtr logger_;
openassetio::hostApi::ManagerPtr manager_;
openassetio::ContextConstPtr context_;
openassetio::utils::FileUrlPathConverter fileUrlPathConverter_;
};

UsdOpenAssetIOResolver::UsdOpenAssetIOResolver() : impl_{std::make_unique<Impl>()} {}
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/integration_test_data/bal_library.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"traits": {
"openassetio-mediacreation:content.LocatableContent": {
"location":
"file://${bal_library_dir}/recursive_assetized_resolve/floors/floor%201.usd"
"file://${bal_library_dir}/recursive_assetized_resolve/floors/floor%20%40%201.usd"
}
}
}
Expand Down

0 comments on commit 0929e55

Please sign in to comment.