-
Notifications
You must be signed in to change notification settings - Fork 141
syscontainers: do not delete modified files with --system-package=no #1131
Changes from all commits
540ec99
1eac52e
8181d73
73d9191
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -526,7 +526,7 @@ def _resolve_remote_path(self, remote_path): | |
raise ValueError("The container's rootfs is set to remote, but the remote rootfs does not exist") | ||
return real_path | ||
|
||
def _checkout(self, repo, name, img, deployment, upgrade, values=None, destination=None, extract_only=False, remote=None, prefix=None, installed_files=None, system_package='no'): | ||
def _checkout(self, repo, name, img, deployment, upgrade, values=None, destination=None, extract_only=False, remote=None, prefix=None, installed_files_checksum=None, system_package='no'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing to do in this PR but this method is getting a bit out of hand with it's arguments! |
||
destination = destination or os.path.join(self._get_system_checkout_path(), "{}.{}".format(name, deployment)) | ||
unitfileout, tmpfilesout = self._get_systemd_destination_files(name, prefix) | ||
|
||
|
@@ -536,8 +536,8 @@ def _checkout(self, repo, name, img, deployment, upgrade, values=None, destinati | |
raise ValueError("The file %s already exists." % f) | ||
|
||
try: | ||
return self._do_checkout(repo, name, img, upgrade, deployment, values, destination, unitfileout, tmpfilesout, extract_only, remote, prefix, installed_files=installed_files, | ||
system_package=system_package) | ||
return self._do_checkout(repo, name, img, upgrade, deployment, values, destination, unitfileout, tmpfilesout, extract_only, remote, prefix, | ||
installed_files_checksum=installed_files_checksum, system_package=system_package) | ||
except (GLib.Error, ValueError, OSError, subprocess.CalledProcessError, KeyboardInterrupt) as e: | ||
try: | ||
if not extract_only and not upgrade: | ||
|
@@ -707,7 +707,7 @@ def _canonicalize_location(self, destination): | |
|
||
|
||
def _do_checkout(self, repo, name, img, upgrade, deployment, values, destination, unitfileout, | ||
tmpfilesout, extract_only, remote, prefix=None, installed_files=None, system_package='no'): | ||
tmpfilesout, extract_only, remote, prefix=None, installed_files_checksum=None, system_package='no'): | ||
""" | ||
Actually do the checkout. | ||
|
||
|
@@ -886,10 +886,11 @@ def _do_checkout(self, repo, name, img, upgrade, deployment, values, destination | |
labels = {k.lower() : v for k, v in img_obj.get('Labels', {}).items()} | ||
(rpm_installed, rpm_file, _) = RPMHostInstall.generate_rpm(name, image_id, labels, exports, destination, values=values, installed_files_template=installed_files_template, rename_files=rename_files, defaultversion=deployment) | ||
if rpm_installed or system_package == 'absent': | ||
new_installed_files = [] | ||
new_installed_files_checksum = {} | ||
else: | ||
new_installed_files = RPMHostInstall.rm_add_files_to_host(installed_files, exports, prefix or "/", files_template=installed_files_template, values=values, rename_files=rename_files) | ||
new_installed_files_checksum = RPMHostInstall.rm_add_files_to_host(installed_files_checksum, exports, prefix or "/", files_template=installed_files_template, values=values, rename_files=rename_files) | ||
|
||
new_installed_files = list(new_installed_files_checksum.keys()) | ||
try: | ||
with open(os.path.join(destination, "info"), 'w') as info_file: | ||
info = {"image" : img, | ||
|
@@ -899,6 +900,7 @@ def _do_checkout(self, repo, name, img, upgrade, deployment, values, destination | |
"values" : values, | ||
"has-container-service" : has_container_service, | ||
"installed-files": new_installed_files, | ||
"installed-files-checksum": new_installed_files_checksum, | ||
"installed-files-template": installed_files_template, | ||
"rename-installed-files" : rename_files, | ||
"rpm-installed" : rpm_installed, | ||
|
@@ -1077,7 +1079,10 @@ def update_container(self, name, setvalues=None, rebase=None): | |
image = rebase or info["image"] | ||
values = info["values"] | ||
revision = info["revision"] if "revision" in info else None | ||
installed_files = info["installed-files"] if "installed-files" in info else None | ||
installed_files_checksum = info["installed-files-checksum"] if "installed-files-checksum" in info else None | ||
if installed_files_checksum is None: | ||
installed_files = info["installed-files"] if "installed-files" in info else None | ||
installed_files_checksum = {k : "" for k in installed_files} | ||
rpm_installed = info["rpm-installed"] if "rpm-installed" in info else None | ||
system_package = info["system-package"] if "system-package" in info else None | ||
runtime = info["runtime"] if "runtime" in info else None | ||
|
@@ -1110,7 +1115,8 @@ def update_container(self, name, setvalues=None, rebase=None): | |
self._runtime_from_info_file = runtime | ||
if system_package is None: | ||
system_package = 'yes' if rpm_installed else 'no' | ||
self._checkout(repo, name, image, next_deployment, True, values, remote=self.args.remote, installed_files=installed_files, system_package=system_package) | ||
self._checkout(repo, name, image, next_deployment, True, values, remote=self.args.remote, | ||
installed_files_checksum=installed_files_checksum, system_package=system_package) | ||
return | ||
|
||
def rollback(self, name): | ||
|
@@ -1131,7 +1137,10 @@ def rollback(self, name): | |
with open(os.path.join(self._get_system_checkout_path(), name, "info"), "r") as info_file: | ||
info = json.loads(info_file.read()) | ||
rpm_installed = info["rpm-installed"] if "rpm-installed" in info else None | ||
installed_files = info["installed-files"] if "installed-files" in info and rpm_installed is None else None | ||
installed_files_checksum = info["installed-files-checksum"] if "installed-files-checksum" in info else None | ||
if installed_files_checksum is None: | ||
installed_files = info["installed-files"] if "installed-files" in info else None | ||
installed_files_checksum = {k : "" for k in installed_files} | ||
installed_files_template = info["installed-files-template"] if "installed-files-template" in info and rpm_installed is None else None | ||
has_container_service = info["has-container-service"] if "has-container-service" in info else True | ||
rename_files = info["rename-installed-files"] if "rename-installed-files" in info else None | ||
|
@@ -1164,8 +1173,8 @@ def rollback(self, name): | |
if (os.path.exists(tmpfiles)): | ||
shutil.copyfile(tmpfiles, tmpfilesout) | ||
|
||
if installed_files: | ||
RPMHostInstall.rm_add_files_to_host(installed_files, os.path.join(destination, "rootfs/exports"), files_template=installed_files_template, rename_files=rename_files) | ||
if installed_files_checksum: | ||
RPMHostInstall.rm_add_files_to_host(installed_files_checksum, os.path.join(destination, "rootfs/exports"), files_template=installed_files_template, rename_files=rename_files) | ||
|
||
os.unlink(path) | ||
os.symlink(destination, path) | ||
|
@@ -1597,9 +1606,12 @@ def uninstall(self, name): | |
installed_files = None | ||
with open(os.path.join(checkout, name, "info"), 'r') as info_file: | ||
info = json.loads(info_file.read()) | ||
installed_files = info["installed-files"] if "installed-files" in info else None | ||
if installed_files: | ||
RPMHostInstall.rm_add_files_to_host(installed_files, None) | ||
installed_files_checksum = info["installed-files-checksum"] if "installed-files-checksum" in info else None | ||
installed_files = info["installed-files"] if "installed-files" in info else [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: seems like the assignment of checksum here is a bit inconsistent with other implementations,
any reasons for that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it is done a bit differently so if installed_files_checksum is not present (for containers installed before this patch), we assume it is empty:
|
||
if installed_files_checksum == None: | ||
installed_files_checksum = {k: "" for k in installed_files} | ||
if installed_files_checksum: | ||
RPMHostInstall.rm_add_files_to_host(installed_files_checksum, None) | ||
|
||
if rpm_installed: | ||
try: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ teardown () { | |
${ATOMIC} uninstall --storage ostree atomic-test-system-hostfs || true | ||
rm -rf /etc/systemd/system/atomic-test-system-*.service /etc/tmpfiles.d/atomic-test-system-*.conf | ||
ostree --repo=${ATOMIC_OSTREE_REPO} refs --delete ociimage &> /dev/null || true | ||
rm -f /usr/local/lib/secret-message | ||
} | ||
trap teardown EXIT | ||
|
||
|
@@ -149,3 +150,11 @@ for i in /usr/local/lib/renamed-atomic-test-system-hostfs /usr/local/lib/secret- | |
do | ||
test -e $i | ||
done | ||
|
||
echo "This message will not be deleted" > /usr/local/lib/secret-message | ||
|
||
ATOMIC_OSTREE_TEST_FORCE_IMAGE_ID=NEW-ID ${ATOMIC} containers update atomic-test-system-hostfs | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: Do you think it is better to also include a check to see if the error message is there to notify the user? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do that no? There is:
|
||
test -e /usr/local/lib/secret-message | ||
|
||
assert_matches "This message will not be deleted" /usr/local/lib/secret-message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q, hmm, I don't quite get ... how "delete" got involved in this function, can you explain it a bit :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we keep track of what files/directories we are adding. We add the directory only if it is not already present.
In this way when we uninstall the container we will not delete directories that were already present when we first installed the container