Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/base.py
Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | def _create_files(self, root, file_datas): | ||||
""" | """ | ||||
# Then create the files | # Then create the files | ||||
for file_data in file_datas: | for file_data in file_datas: | ||||
path = os.path.join(root, file_data['name']) | path = os.path.join(root, file_data['name']) | ||||
content = get_filtered_file_content(self.storage, file_data) | content = get_filtered_file_content(self.storage, file_data) | ||||
self._create_file(path, content, file_data['perms']) | self._create_file(path, content, file_data['perms']) | ||||
def _create_file(self, path, content, perms=0o100644): | def _create_file(self, path, content, mode=0o100644): | ||||
"""Create the given file and fill it with content. | """Create the given file and fill it with content. | ||||
""" | """ | ||||
if perms not in (0o100644, 0o100755, 0o120000): | perms = mode_to_perms(mode) | ||||
logging.warning('File {} has invalid permission {}, ' | if perms == DentryPerms.symlink: | ||||
'defaulting to 644.'.format(path, perms)) | |||||
perms = 0o100644 | |||||
if perms == 0o120000: # Symbolic link | |||||
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 & 0o777) | os.chmod(path, perms.value) | ||||
def _get_file_content(self, obj_id): | def _get_file_content(self, obj_id): | ||||
"""Get the content of the given file. | """Get the content of the given file. | ||||
""" | """ | ||||
content = list(self.storage.content_get([obj_id]))[0]['data'] | content = list(self.storage.content_get([obj_id]))[0]['data'] | ||||
return content | return content | ||||
Show All 12 Lines |