ipatests: refactor FileBackup helper

* `cp` now preserves all attributes of original file, there is no reason
  to select only some of them
* backup is now restored with `mv` instead of `cp` to avoid leaving junk

Related to: https://pagure.io/freeipa/issue/8115

Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
Sergey Orlov 2019-11-07 17:47:25 +01:00
parent 0f4c41ab26
commit 72540c4233
No known key found for this signature in database
GPG Key ID: ADF8C90EDD04503D

View File

@ -1927,14 +1927,11 @@ class FileBackup:
self._host = host
self._filename = filename
self._backup = create_temp_file(host)
self._cp_cmd = ['cp']
if is_selinux_enabled(host):
self._cp_cmd.append('--preserve=context')
host.run_command(self._cp_cmd + [filename, self._backup])
host.run_command(['cp', '--preserve=all', filename, self._backup])
def restore(self):
"""Restore file. Can be called multiple times."""
self._host.run_command(self._cp_cmd + [self._backup, self._filename])
self._host.run_command(['mv', self._backup, self._filename])
def __enter__(self):
return self