From 47e633131acc0bdf5298a06027daafba7872a7ba Mon Sep 17 00:00:00 2001 From: HuijingHei Date: Fri, 29 Dec 2023 11:20:35 +0800 Subject: [PATCH] Check generated tmpfiles.d dir when removing package When removing package, will also remove the generated tmpfile config under the rpm-ostree tmpfiles.d directory. Since https://github.com/coreos/rpm-ostree/pull/4697, we use the new directory like `usr/lib/rpm-ostree/tmpfiles.d`, but for old `usr/lib/tmpfiles.d`, failed with `error: opendir(usr/lib/ rpm-ostree/tmpfiles.d): No such file or directory`. With this patch, check if `usr/lib/rpm-ostree/tmpfiles.d` does not exist, will use old `usr/lib/tmpfiles.d` instead. Also needs https://github.com/coreos/rpm-ostree/pull/4727. Fixes: https://github.com/fedora-silverblue/issue-tracker/issues/523 --- src/libpriv/rpmostree-core.cxx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/libpriv/rpmostree-core.cxx b/src/libpriv/rpmostree-core.cxx index 5ba6ca23b6..83133001e1 100644 --- a/src/libpriv/rpmostree-core.cxx +++ b/src/libpriv/rpmostree-core.cxx @@ -3086,10 +3086,25 @@ delete_package_from_root (RpmOstreeContext *self, rpmte pkg, int rootfs_dfd, GHa } /* And finally, delete any automatically generated tmpfiles.d dropin. */ + const char *tmpfiles_path = "usr/lib/rpm-ostree/tmpfiles.d"; + /* Check if the new rpm-ostree tmpfiles.d directory exists; + * if not, switch to old tmpfiles.d directory. + */ + if (!glnx_fstatat_allow_noent (rootfs_dfd, tmpfiles_path, NULL, AT_SYMLINK_NOFOLLOW, error)) + return FALSE; glnx_autofd int tmpfiles_dfd = -1; - if (!glnx_opendirat (rootfs_dfd, "usr/lib/rpm-ostree/tmpfiles.d", TRUE, &tmpfiles_dfd, error)) + g_autofree char *dropin = NULL; + if (errno == 0) + { + dropin = g_strdup_printf ("%s.conf", rpmteN (pkg)); + } + else if (errno == ENOENT) + { + tmpfiles_path = "usr/lib/tmpfiles.d"; + dropin = g_strdup_printf ("pkg-%s.conf", rpmteN (pkg)); + } + if (!glnx_opendirat (rootfs_dfd, tmpfiles_path, TRUE, &tmpfiles_dfd, error)) return FALSE; - g_autofree char *dropin = g_strdup_printf ("%s.conf", rpmteN (pkg)); if (!glnx_shutil_rm_rf_at (tmpfiles_dfd, dropin, cancellable, error)) return FALSE;