From 818ad826a4f4db6d7e6c17877ee2ca4c4447e6f8 Mon Sep 17 00:00:00 2001 From: Antoine Lambert <anlambert@softwareheritage.org> Date: Mon, 5 Dec 2022 16:15:55 +0100 Subject: [PATCH] from_disk.Content: Add missing path info for symlink from_disk.Content object created for a symlink was missing path info so ensure to add it for consistency with from_disk.Content object created for a regular file. --- swh/model/from_disk.py | 5 ++++- swh/model/tests/test_from_disk.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/swh/model/from_disk.py b/swh/model/from_disk.py index 8bd7f5d1..058e77fa 100644 --- a/swh/model/from_disk.py +++ b/swh/model/from_disk.py @@ -149,7 +149,9 @@ class Content(MerkleLeaf): @classmethod def from_symlink(cls, *, path, mode): """Convert a symbolic link to a Software Heritage content entry""" - return cls.from_bytes(mode=mode, data=os.readlink(path)) + content = cls.from_bytes(mode=mode, data=os.readlink(path)) + content.data["path"] = path + return content @classmethod def from_file(cls, *, path, max_content_length=None): @@ -231,6 +233,7 @@ class Content(MerkleLeaf): data.pop("path", None) return model.SkippedContent.from_dict(data) elif "data" in data: + data.pop("path", None) return model.Content.from_dict(data) else: return DiskBackedContent.from_dict(data) diff --git a/swh/model/tests/test_from_disk.py b/swh/model/tests/test_from_disk.py index c07fef68..1ebcbbe9 100644 --- a/swh/model/tests/test_from_disk.py +++ b/swh/model/tests/test_from_disk.py @@ -558,7 +558,9 @@ class SymlinkToContent(DataMixin, unittest.TestCase): path = os.path.join(self.tmpdir_name, filename) perms = 0o120000 conv_content = Content.from_symlink(path=path, mode=perms) - self.assertContentEqual(conv_content, symlink) + symlink_copy = symlink.copy() + symlink_copy["path"] = path + self.assertContentEqual(conv_content, symlink_copy, check_path=True) def test_symlink_to_base_model(self): for filename, symlink in self.symlinks.items(): -- GitLab