diff --git a/swh/fuse/fs/artifact.py b/swh/fuse/fs/artifact.py --- a/swh/fuse/fs/artifact.py +++ b/swh/fuse/fs/artifact.py @@ -482,10 +482,17 @@ next_prefix = next_subdirs[0] if len(next_subdirs) == 1: + # Non-alias targets are symlinks to their corresponding archived + # artifact, whereas alias targets are relative symlinks to the + # corresponding snapshot directory entry. + prefix = "" + if branch_meta["target_type"] != "alias": + prefix = f"{root_path}/archive/" + yield self.create_child( FuseSymlinkEntry, name=next_prefix, - target=Path(root_path, f"archive/{branch_meta['target']}"), + target=Path(prefix, str(branch_meta["target"])), ) else: subdirs.add(next_prefix) diff --git a/swh/fuse/tests/data/api_data.py b/swh/fuse/tests/data/api_data.py --- a/swh/fuse/tests/data/api_data.py +++ b/swh/fuse/tests/data/api_data.py @@ -2778,6 +2778,11 @@ "target_type": "revision", "target_url": "https://archive.softwareheritage.org/api/1/revision/a2db7c15ce9f586164cabb15d83fb3f6bbeb3cf5/", }, + "HEAD": { + "target": "refs/heads/master", + "target_type": "alias", + "target_url": "https://archive.softwareheritage.org/api/1/revision/430a9fd4c797c50cea26157141b2408073b2ed91/", + }, }, "next_branch": None, }, diff --git a/swh/fuse/tests/data/gen-api-data.py b/swh/fuse/tests/data/gen-api-data.py --- a/swh/fuse/tests/data/gen-api-data.py +++ b/swh/fuse/tests/data/gen-api-data.py @@ -61,6 +61,15 @@ data = requests.get(f"{API_URL_real}/{url}").text data = json.loads(data) + if swhid.object_type == SNAPSHOT: + # Add a custom alias to test out this special case for snapshot + alias_name = "refs/heads/master" + data["branches"]["HEAD"] = { # type: ignore + "target": alias_name, + "target_type": "alias", + "target_url": data["branches"][alias_name]["target_url"], # type: ignore + } + MOCK_ARCHIVE[url] = data METADATA[swhid] = data