|
|
|
@ -491,38 +491,38 @@ class TemplateWrapper:
|
|
|
|
|
# Путь к архивной версии файла.
|
|
|
|
|
self.archive_path = self._get_archive_path(self.target_path)
|
|
|
|
|
|
|
|
|
|
self.md5_matching = (self.parameters.autoupdate
|
|
|
|
|
or self.parameters.force)
|
|
|
|
|
self.contents_matching = (self.parameters.autoupdate
|
|
|
|
|
or self.parameters.force)
|
|
|
|
|
|
|
|
|
|
if not self.protected:
|
|
|
|
|
self.md5_matching = True
|
|
|
|
|
self.contents_matching = True
|
|
|
|
|
|
|
|
|
|
elif self.parameters.unbound:
|
|
|
|
|
# Если присутствует unbound, то просто модифицируем файл и
|
|
|
|
|
# удаляем его из CONTENTS.
|
|
|
|
|
self.md5_matching = True
|
|
|
|
|
self.contents_matching = True
|
|
|
|
|
|
|
|
|
|
elif self.target_type is None:
|
|
|
|
|
# Если целевой файл отсутствует.
|
|
|
|
|
if self.target_path in self.target_package:
|
|
|
|
|
# Проверка -- был ли файл удален.
|
|
|
|
|
# self.md5_matching = self.md5_matching
|
|
|
|
|
# self.contents_matching = self.contents_matching
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
self.md5_matching = True
|
|
|
|
|
self.contents_matching = True
|
|
|
|
|
|
|
|
|
|
elif self.target_without_package:
|
|
|
|
|
# Если файл по целевому пути не относится к какому-либо пакету.
|
|
|
|
|
# self.md5_matching = False
|
|
|
|
|
# self.contents_matching = False
|
|
|
|
|
pass
|
|
|
|
|
elif not self.md5_matching:
|
|
|
|
|
elif not self.contents_matching:
|
|
|
|
|
# Если файл есть и он относится к текущему пакету.
|
|
|
|
|
# Если по каким-то причинам уже нужно считать, что хэш-суммы
|
|
|
|
|
# совпадают -- в дальнейшей проверке нет необходимости.
|
|
|
|
|
target_md5 = self.target_package.get_md5(self.target_path)
|
|
|
|
|
self.md5_matching = self.target_package.is_md5_equal(
|
|
|
|
|
self.target_path,
|
|
|
|
|
file_md5=target_md5)
|
|
|
|
|
# target_md5 = self.target_package.get_md5(self.target_path)
|
|
|
|
|
self.contents_matching = self.target_package.check_contents_data(
|
|
|
|
|
self.target_path,
|
|
|
|
|
symlink=self.target_is_link)
|
|
|
|
|
|
|
|
|
|
# Если по целевому пути файл не относящийся к какому-либо пакету и
|
|
|
|
|
# присутствует параметр autoupdate -- удаляем этот файл.
|
|
|
|
@ -531,7 +531,7 @@ class TemplateWrapper:
|
|
|
|
|
self.remove_original = True
|
|
|
|
|
|
|
|
|
|
# Определяем пути входных и выходных файлов.
|
|
|
|
|
if self.md5_matching:
|
|
|
|
|
if self.contents_matching:
|
|
|
|
|
# Приоритет отдаем пути из параметра source.
|
|
|
|
|
if self.parameters.source:
|
|
|
|
|
self.input_path = self.parameters.source
|
|
|
|
@ -972,13 +972,18 @@ class TemplateExecutor:
|
|
|
|
|
else:
|
|
|
|
|
chown = self.file_default_parameters.get('chown', False)
|
|
|
|
|
|
|
|
|
|
if template_format.EXECUTABLE or template_object.md5_matching:
|
|
|
|
|
if template_format.EXECUTABLE or template_object.contents_matching:
|
|
|
|
|
# Действия, если целевой файл не имеет пользовательских изменений
|
|
|
|
|
# или если он исполнительный.
|
|
|
|
|
# Парсим текст шаблона используя его формат.
|
|
|
|
|
parsed_template = template_format(template_object.template_text,
|
|
|
|
|
template_object.template_path,
|
|
|
|
|
ignore_comments=True)
|
|
|
|
|
|
|
|
|
|
if (not parsed_template and not template_object.parameters.source
|
|
|
|
|
if (not parsed_template and template_object.parameters.source
|
|
|
|
|
and template_object.format_class.EXECUTABLE):
|
|
|
|
|
# Если шаблон пуст, параметром source не задан входной файл,
|
|
|
|
|
# а шаблон является исполнительным
|
|
|
|
|
if template_object.target_type is DIR:
|
|
|
|
|
self._remove_directory(template_object.target_path)
|
|
|
|
|
shutil.copytree(input_path,
|
|
|
|
@ -994,8 +999,7 @@ class TemplateExecutor:
|
|
|
|
|
self._chmod_file(template_object.target_path, chmod)
|
|
|
|
|
|
|
|
|
|
elif not template_object.format_class.EXECUTABLE:
|
|
|
|
|
# Действия при совпадении md5 из CONTENTS и md5 целевого файла.
|
|
|
|
|
# А также если шаблон просто исполнительный.
|
|
|
|
|
# Действия для шаблонов не являющихся исполнительными.
|
|
|
|
|
output_paths = [output_path]
|
|
|
|
|
|
|
|
|
|
# Если целевой файл защищен, а шаблон не userspace.
|
|
|
|
@ -1167,7 +1171,7 @@ class TemplateExecutor:
|
|
|
|
|
# Обновляем CONTENTS.
|
|
|
|
|
template_object.add_to_contents(file_md5=output_text_md5)
|
|
|
|
|
else:
|
|
|
|
|
# Действия если CL совпало. Пока ничего не делаем.
|
|
|
|
|
# Действия если CL совпало. Hичего не делаем.
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def _append_after_file(self, template_object: TemplateWrapper) -> None:
|
|
|
|
@ -1233,24 +1237,83 @@ class TemplateExecutor:
|
|
|
|
|
def _append_link_file(self, template_object: TemplateWrapper) -> None:
|
|
|
|
|
'''Метод описывающий действия при append = "link", если шаблон --
|
|
|
|
|
файл. Создает ссылку на файл, указанный в параметре source.'''
|
|
|
|
|
self._link_file(template_object.parameters.source,
|
|
|
|
|
template_object.target_path)
|
|
|
|
|
input_path = template_object.input_path
|
|
|
|
|
output_path = template_object.output_path
|
|
|
|
|
|
|
|
|
|
if template_object.contents_matching:
|
|
|
|
|
output_paths = [output_path]
|
|
|
|
|
# Если целевой файл защищен, а шаблон не userspace.
|
|
|
|
|
if (template_object.protected
|
|
|
|
|
and not template_object.is_userspace):
|
|
|
|
|
# Тогда также обновляем архив.
|
|
|
|
|
output_paths.append(template_object.archive_path)
|
|
|
|
|
|
|
|
|
|
for link_path in output_paths:
|
|
|
|
|
if not os.path.exists(os.path.dirname(link_path)):
|
|
|
|
|
self._create_directory(
|
|
|
|
|
template_object,
|
|
|
|
|
path_to_create=os.path.dirname(link_path))
|
|
|
|
|
elif os.path.exists(link_path):
|
|
|
|
|
os.unlink(link_path)
|
|
|
|
|
self._link_file(input_path, link_path)
|
|
|
|
|
|
|
|
|
|
# Корректируем список измененных файлов.
|
|
|
|
|
if template_object.target_path not in self.changed_files:
|
|
|
|
|
self.changed_files[template_object.target_path] = 'N'
|
|
|
|
|
else:
|
|
|
|
|
self.changed_files[template_object.target_path] = 'M'
|
|
|
|
|
|
|
|
|
|
if self.dbpkg:
|
|
|
|
|
# Убираем целевой файл из CL.
|
|
|
|
|
self.calculate_config_file.remove_file(
|
|
|
|
|
template_object.target_path)
|
|
|
|
|
if template_object.parameters.unbound:
|
|
|
|
|
template_object.remove_from_contents()
|
|
|
|
|
else:
|
|
|
|
|
template_object.add_to_contents()
|
|
|
|
|
else:
|
|
|
|
|
source_path_md5 = self._get_source_hash(input_path)
|
|
|
|
|
if not self.calculate_config_file.compare_md5(
|
|
|
|
|
template_object.target_path,
|
|
|
|
|
source_path_md5
|
|
|
|
|
):
|
|
|
|
|
if not os.path.exists(os.path.dirname(output_path)):
|
|
|
|
|
self._create_directory(
|
|
|
|
|
template_object,
|
|
|
|
|
path_to_create=os.path.dirname(output_path))
|
|
|
|
|
elif os.path.exists(output_path):
|
|
|
|
|
os.unlink(output_path)
|
|
|
|
|
self._link_file(input_path, output_path)
|
|
|
|
|
|
|
|
|
|
self.changed_files[template_object.target_path] = 'C'
|
|
|
|
|
if self.dbpkg:
|
|
|
|
|
template_object.add_to_contents()
|
|
|
|
|
|
|
|
|
|
# Обновляем CL.
|
|
|
|
|
self.calculate_config_file.set_files_md5(
|
|
|
|
|
template_object.target_path,
|
|
|
|
|
source_path_md5)
|
|
|
|
|
self.changed_files[template_object.target_path] = 'C'
|
|
|
|
|
# Обновляем CONTENTS.
|
|
|
|
|
template_object.add_to_contents()
|
|
|
|
|
else:
|
|
|
|
|
# Действия если CL совпало. Hичего не делаем.
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# Меняем права и владельца файла, на который указывает ссылка.
|
|
|
|
|
if template_object.parameters.chmod:
|
|
|
|
|
self._chmod_file(template_object.parameters.source,
|
|
|
|
|
template_object.parameters.chmod)
|
|
|
|
|
self._chmod_file(input_path, template_object.parameters.chmod)
|
|
|
|
|
|
|
|
|
|
if template_object.parameters.chown:
|
|
|
|
|
self._chown_file(template_object.parameters.source,
|
|
|
|
|
template_object.parameters.chown)
|
|
|
|
|
|
|
|
|
|
# Корректируем список измененных файлов.
|
|
|
|
|
if template_object.target_path not in self.changed_files:
|
|
|
|
|
self.changed_files[template_object.target_path] = 'N'
|
|
|
|
|
|
|
|
|
|
if self.dbpkg:
|
|
|
|
|
template_object.add_to_contents()
|
|
|
|
|
self._chown_file(input_path, template_object.parameters.chown)
|
|
|
|
|
|
|
|
|
|
def _get_source_hash(self, source_path: str) -> str:
|
|
|
|
|
if (self.chroot_path != "/" and
|
|
|
|
|
source_path.startswith(self.chroot_path)):
|
|
|
|
|
source_path = source_path[len(self.chroot_path):]
|
|
|
|
|
if not source_path.startswith("/"):
|
|
|
|
|
source_path = "/" + source_path
|
|
|
|
|
return hashlib.md5(source_path.encode()).hexdigest()
|
|
|
|
|
|
|
|
|
|
def _create_directory(self, template_object: TemplateWrapper,
|
|
|
|
|
path_to_create=None) -> None:
|
|
|
|
|