diff --git a/swh/model/from_disk.py b/swh/model/from_disk.py index 8bd7f5d18f3bb39895969c8b260fd06d038391f6..058e77fa2b39e1293b404c91f1747049add5bfb6 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 c07fef683b2c47583aa514dc0961331f63df1ef2..1ebcbbe981f8e53b73a2e3913bfd9b6b537c15ec 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():