diff --git a/swh/fuse/cli.py b/swh/fuse/cli.py --- a/swh/fuse/cli.py +++ b/swh/fuse/cli.py @@ -37,6 +37,7 @@ "url": "https://archive.softwareheritage.org/api/1", "auth-token": None, }, + "json-indent": 2, } 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 @@ -546,7 +546,11 @@ OriginVisit.MetaFile, name="meta.json", mode=int(EntryMode.RDONLY_FILE), - content=json.dumps(self.meta, default=lambda x: str(x)), + content=json.dumps( + self.meta, + indent=self.fuse.conf["json-indent"], + default=lambda x: str(x), + ), ) diff --git a/swh/fuse/fs/mountpoint.py b/swh/fuse/fs/mountpoint.py --- a/swh/fuse/fs/mountpoint.py +++ b/swh/fuse/fs/mountpoint.py @@ -98,7 +98,8 @@ async def get_content(self) -> bytes: # Get raw JSON metadata from API (un-typified) metadata = await self.fuse.cache.metadata.get(self.swhid, typify=False) - return json.dumps(metadata).encode() + json_str = json.dumps(metadata, indent=self.fuse.conf["json-indent"]) + return (json_str + "\n").encode() async def size(self) -> int: return len(await self.get_content()) diff --git a/swh/fuse/tests/conftest.py b/swh/fuse/tests/conftest.py --- a/swh/fuse/tests/conftest.py +++ b/swh/fuse/tests/conftest.py @@ -41,6 +41,7 @@ "history": {"in-memory": True}, }, "web-api": {"url": API_URL, "auth-token": None}, + "json-indent": None, } # Run FUSE in foreground mode but in a separate process, so it does not diff --git a/swh/fuse/tests/test_meta.py b/swh/fuse/tests/test_meta.py --- a/swh/fuse/tests/test_meta.py +++ b/swh/fuse/tests/test_meta.py @@ -13,4 +13,4 @@ file_path_meta = fuse_mntdir / f"meta/{swhid}.json" assert file_path_meta.exists() expected = json.dumps(get_data_from_web_archive(swhid)) - assert file_path_meta.read_text() == expected + assert file_path_meta.read_text().strip() == expected.strip() diff --git a/swh/fuse/tests/test_release.py b/swh/fuse/tests/test_release.py --- a/swh/fuse/tests/test_release.py +++ b/swh/fuse/tests/test_release.py @@ -15,7 +15,7 @@ def test_access_meta(fuse_mntdir): file_path = fuse_mntdir / "archive" / ROOT_REL / "meta.json" expected = json.dumps(get_data_from_web_archive(ROOT_REL)) - assert file_path.read_text() == expected + assert file_path.read_text().strip() == expected.strip() def test_access_rev_target(fuse_mntdir): diff --git a/swh/fuse/tests/test_revision.py b/swh/fuse/tests/test_revision.py --- a/swh/fuse/tests/test_revision.py +++ b/swh/fuse/tests/test_revision.py @@ -18,7 +18,7 @@ def test_access_meta(fuse_mntdir): file_path = fuse_mntdir / "archive" / ROOT_REV / "meta.json" expected = json.dumps(get_data_from_web_archive(ROOT_REV)) - assert file_path.read_text() == expected + assert file_path.read_text().strip() == expected.strip() def test_list_root(fuse_mntdir):