Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/to_disk.py
Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | def _create_files(self, files_data: List[Dict[str, Any]]) -> None: | ||||
path = os.path.join(self.root, file_data["path"]) | path = os.path.join(self.root, file_data["path"]) | ||||
self._create_file(path, file_data["content"], file_data["perms"]) | self._create_file(path, file_data["content"], file_data["perms"]) | ||||
def _create_revisions(self, revs_data: List[Dict[str, Any]]) -> None: | def _create_revisions(self, revs_data: List[Dict[str, Any]]) -> None: | ||||
"""Create the revisions in the tree as broken symlinks to the target | """Create the revisions in the tree as broken symlinks to the target | ||||
identifier.""" | identifier.""" | ||||
for file_data in revs_data: | for file_data in revs_data: | ||||
path = os.path.join(self.root, file_data["path"]) | path = os.path.join(self.root, file_data["path"]) | ||||
target = hashutil.hash_to_hex(file_data["target"]) | target = hashutil.hash_to_bytehex(file_data["target"]) | ||||
self._create_file(path, target, mode=DentryPerms.symlink) | self._create_file(path, target, mode=DentryPerms.symlink) | ||||
def _create_file( | def _create_file( | ||||
self, path: bytes, content: bytes, mode: int = DentryPerms.content | self, path: bytes, content: bytes, mode: int = DentryPerms.content | ||||
) -> None: | ) -> None: | ||||
"""Create the given file and fill it with content.""" | """Create the given file and fill it with content.""" | ||||
perms = mode_to_perms(mode) | perms = mode_to_perms(mode) | ||||
if perms == DentryPerms.symlink: | if perms == DentryPerms.symlink: | ||||
os.symlink(content, path) | os.symlink(content, path) | ||||
else: | else: | ||||
with open(path, "wb") as f: | with open(path, "wb") as f: | ||||
f.write(content) | f.write(content) | ||||
os.chmod(path, perms.value) | os.chmod(path, perms.value) |