@@ -118,6 +118,11 @@ def _resolve_asset_root() -> str:
118118
119119_GIT_SSH_RE = re .compile (r"^[^@/:]+@[^:]+:.+" )
120120
121+ _MIRROR_URL_SCHEMES = frozenset ({"http" , "https" , "omniverse" })
122+ """URL schemes whose assets are cached locally, and which therefore start a cache layout."""
123+
124+ _MIRROR_NETLOC_PORT_RE = re .compile (r"^(.+)_(\d+)$" )
125+
121126
122127def retrieve_git_asset_path (
123128 git_path : str , local_path : str , cache_dir : str | None = None , force_update : bool = False
@@ -305,6 +310,33 @@ def _mirror_path(url: str, download_dir: str) -> str:
305310 return os .path .join (download_dir , parsed .scheme , netloc , * parsed .path .lstrip ("/" ).split ("/" ))
306311
307312
313+ def unmirror_file_path (path : str ) -> str :
314+ """Reverses :func:`retrieve_file_path` caching, mapping a cached copy back to its source URL.
315+
316+ A remote asset is cached under ``<download_dir>/<scheme>/<host>/<path>``, and stages reference
317+ that cached copy rather than the URL it came from. Exports of such a stage therefore carry
318+ absolute paths that only resolve on the machine holding the cache. This recovers the URL so an
319+ export can name the source asset instead.
320+
321+ Args:
322+ path: Local filesystem path, typically an asset path read from a USD layer.
323+
324+ Returns:
325+ The URL the path was cached from, or ``""`` when it does not lie inside a cache layout.
326+ """
327+ parts = path .replace (os .sep , "/" ).split ("/" )
328+ # the last two components are the host and at least one path component, so a scheme found
329+ # there cannot be the start of a cache layout
330+ for index , part in enumerate (parts [:- 2 ]):
331+ if part .lower () not in _MIRROR_URL_SCHEMES :
332+ continue
333+ netloc , * remainder = parts [index + 1 :]
334+ # ``_mirror_path`` writes a port separator as '_', which is not valid in a host name
335+ netloc = _MIRROR_NETLOC_PORT_RE .sub (r"\1:\2" , netloc )
336+ return f"{ part .lower ()} ://{ netloc } /{ '/' .join (remainder )} "
337+ return ""
338+
339+
308340def _remote_fingerprint (url : str ) -> dict | None :
309341 """Provider metadata identifying the revision of ``url`` the server currently holds.
310342
0 commit comments