Skip to content
Snippets Groups Projects
Commit 818ad826 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

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.
parent fe8d5558
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment