-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ResourceRetriever::getFilePath() #972
Conversation
TEST(PackageResourceRetriever, getFilePath_StripsTrailingSlash) | ||
{ | ||
#ifdef _WIN32 | ||
const char* expected = "file:///" "dart://sample/test/foo"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very unclear about the purpose behind this #ifdef
, especially since I believe this will set the value of expected
to a const char*
which dereferences to file:///dart://sample/test/foo
, which doesn't seem like a valid URI (although I could certainly be wrong).
Some commentary about the motivation behind the #ifdef
(Why is Windows different? Shouldn't that kind of difference be handled in the Uri
class?) would be helpful. As well as the meaning behind strange URI which seems to contain both the file
scheme and the dart
scheme in sequence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those invalid URI tests were unintentionally introduced in 162b7a8#diff-2c76e43b1bdbf70403566db01e2e1198. They are fixed by c79de2d.
Some commentary about the motivation behind the #ifdef (Why is Windows different? Shouldn't that kind of difference be handled in the Uri class?) would be helpful.
Added. I hope the comment answers your concern.
Codecov Report
@@ Coverage Diff @@
## release-6.4 #972 +/- ##
==============================================
Coverage ? 56.69%
==============================================
Files ? 310
Lines ? 23962
Branches ? 0
==============================================
Hits ? 13586
Misses ? 10376
Partials ? 0
|
It should be possible to get exactly the same behavior using the existing Uri uriToMesh = /* snip */;
std::string relativePathToTexture = /* snip */;
auto uriToTexture = Uri::fromRelativeUri(uriToMesh, relativePathToTexture); The big advantage of Implementing |
This may work for a file URI, but how could we get the file path from a non-file URI (e.g.,
I see your point and have the same concern, but couldn't figure out a better solution here. 😞 |
Another solution I came up with was storing the file path to
|
You don't need to get a file path at all - you just need a path to refer to the resource, such that you can retrieve it later. In fact, a file path may not exist at all - the underlying resource retriever could, e.g. use Suppose you are loading a URDF from the URI auto urdfUri = Uri::fromString{"dart://my_directory/fruit.urdf"};
auto urdfResource = myResourceRetriever->retrieve(urdfUri);
auto urdfString = read_all(urdfResource.read);
auto urdfModel = parse(urdfString); Suppose you encounter the relative path auto relativeMeshUri = Uri::fromString{"meshes/banana.stl"}; // loaded from urdfModel
auto meshUri = Uri::fromRelativeUri(urdfUri, relativeMeshUri);
// meshUri now contains "dart://my_directory/meshes/banana.stl" Now, you can simply load auto meshResource = myResourceRetriever->retrieve(meshUri); Since you are using the same Maybe I am missing something. Why do we need to convert the |
@mkoval All you pointed out make sense to me. I should have said the motivation behind this change. 😅 This was for loading texture images using OSG that requires the file path to the image files (see this). But I couldn't come up with a way to incorporate our resource/retriever mechanism into this (like |
Revision of #970 retargeting to
release-6.4
.Motivation
In some cases, it is required to extract the (absolute) file path of a URI (if available). For example,
MeshShape
needs to know the path to a mesh file to infer the path to a texture image, which is given as a relative path. Currently, we don't have a public method to get a file path from a URI unless it's a file URI.PackageResourceRetriever
andDartResourceRetriever
have similar functionality, but it's not public.Proposal
I propose adding
ResourceRetriever::getFilePath()
that returns the absolute file path specified by a URI or an empty string if unavailable.Before creating a pull request
Before merging a pull request
CHANGELOG.md