Now files permissions are saved after using templates without chmod value. fixed #66

master
Иванов Денис 3 years ago
parent d130e476aa
commit ff97850ba2

@ -308,10 +308,11 @@ class TemplateWrapper:
self._check_user_changes()
if self.target_type is not None and self.contents_matching:
# Удаляем целевой файл, если append = 'replace'
if self.parameters.append and self.parameters.append == "replace":
self.remove_original = True
# if self.target_type is not None and self.contents_matching:
# # Удаляем целевой файл, если append = 'replace'
# if (self.parameters.append and
# self.parameters.append == "replace"):
# self.remove_original = True
def _check_type_conflicts(self) -> NoReturn:
'''Метод для проверки конфликтов типов.'''
@ -1034,6 +1035,8 @@ class TemplateExecutor:
# Если шаблон пуст, параметром source задан входной файл,
# и при этом формат шаблона raw и append = 'replace'
# значит этот шаблон предназначен для копирования.
if template_object.target_type is not None:
self._remove_file(template_object.target_path)
output_file_md5 = self._copy_from_source(template_object,
chown=chown,
chmod=chmod)
@ -1049,6 +1052,9 @@ class TemplateExecutor:
input_text = self._get_input_text(template_object,
replace=replace)
if (replace and template_object.target_type is not None and
os.path.exists(output_path)):
self._clear_file(output_path)
# Если шаблон не исполнительный разбираем входной текст.
parsed_input = template_format(

@ -1788,6 +1788,26 @@ class TestDirectoryProcessor:
'/etc/dir_78/file_1')).st_mode
assert int(mode) == 0o100655
def test_saving_permissions_after_file_replace(self):
if os.getuid() == 0:
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_62')
mode = os.stat(join_paths(CHROOT_PATH, '/etc/file_23')).st_mode
if mode != 0o100645:
os.chmod(join_paths(CHROOT_PATH, '/etc/file_23'), 0o100645)
directory_processor = DirectoryProcessor('install',
datavars_module=datavars)
directory_processor.process_template_directories()
with open(join_paths(CHROOT_PATH,
'/etc/file_23'), 'r') as target_file:
target_text = target_file.read()
assert target_text == "joy division -- new dawn fades"
mode = os.stat(join_paths(CHROOT_PATH, '/etc/file_23')).st_mode
assert int(mode) == 0o100645
def test_using_file_templates_from_base_directory(self):
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_61')

@ -0,0 +1,2 @@
{% calculate action = "install", append = 'skip',
package = "test-category/test-package" %}
Loading…
Cancel
Save