From 22dca5725451c62f9e1850db5b834eb5689f3be7 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 14 Dec 2017 14:42:06 -0500 Subject: [PATCH] core,passwd: Use new libostree hardlink-break API The code moved into libostree here: https://github.com/ostreedev/ostree/pull/1378 --- src/libpriv/rpmostree-core.c | 6 +-- src/libpriv/rpmostree-passwd-util.c | 4 +- src/libpriv/rpmostree-util.c | 61 ----------------------------- src/libpriv/rpmostree-util.h | 7 ---- 4 files changed, 5 insertions(+), 73 deletions(-) diff --git a/src/libpriv/rpmostree-core.c b/src/libpriv/rpmostree-core.c index 7138d50a1d..258577ed30 100644 --- a/src/libpriv/rpmostree-core.c +++ b/src/libpriv/rpmostree-core.c @@ -2523,8 +2523,8 @@ break_hardlinks_at (int dfd, return FALSE; if (dent == NULL) break; - if (!rpmostree_break_hardlink (dfd_iter.fd, dent->d_name, 0, - cancellable, error)) + if (!ostree_break_hardlink (dfd_iter.fd, dent->d_name, FALSE, + cancellable, error)) return FALSE; } @@ -3008,7 +3008,7 @@ apply_rpmfi_overrides (RpmOstreeContext *self, if (!S_ISDIR (stbuf.st_mode)) { - if (!rpmostree_break_hardlink (tmprootfs_dfd, fn, 0, cancellable, error)) + if (!ostree_break_hardlink (tmprootfs_dfd, fn, FALSE, cancellable, error)) return FALSE; } diff --git a/src/libpriv/rpmostree-passwd-util.c b/src/libpriv/rpmostree-passwd-util.c index fd10491986..011e01de29 100644 --- a/src/libpriv/rpmostree-passwd-util.c +++ b/src/libpriv/rpmostree-passwd-util.c @@ -1071,8 +1071,8 @@ rpmostree_passwd_prepare_rpm_layering (int rootfs_dfd, if (errno == ENOENT) continue; - if (!rpmostree_break_hardlink (rootfs_dfd, src, GLNX_FILE_COPY_NOXATTRS, - cancellable, error)) + if (!ostree_break_hardlink (rootfs_dfd, src, TRUE, + cancellable, error)) return FALSE; } diff --git a/src/libpriv/rpmostree-util.c b/src/libpriv/rpmostree-util.c index 8b08e2b411..4882e4d893 100644 --- a/src/libpriv/rpmostree-util.c +++ b/src/libpriv/rpmostree-util.c @@ -731,67 +731,6 @@ rpmostree_stdout_is_journal (void) return stdout_is_socket; } -/* Given a path to a file/symlink, make a copy (reflink if possible) - * of it if it's a hard link. We need this in a few places right now: - * - The RPM database - * - SELinux policy "denormalization" where a label changes - * - Working around shadow-utils opening /etc/passwd with O_RDWR - * - Upon applying rpmfi overrides during assembly - */ -gboolean -rpmostree_break_hardlink (int dfd, - const char *path, - GLnxFileCopyFlags copyflags, - GCancellable *cancellable, - GError **error) -{ - struct stat stbuf; - - if (!glnx_fstatat (dfd, path, &stbuf, AT_SYMLINK_NOFOLLOW, error)) - return FALSE; - - if (!S_ISLNK (stbuf.st_mode) && !S_ISREG (stbuf.st_mode)) - return glnx_throw (error, "Unsupported type for entry '%s'", path); - - if (stbuf.st_nlink > 1) - { - guint count; - gboolean copy_success = FALSE; - char *path_tmp = glnx_strjoina (path, ".XXXXXX"); - - for (count = 0; count < 100; count++) - { - g_autoptr(GError) tmp_error = NULL; - - glnx_gen_temp_name (path_tmp); - - if (!glnx_file_copy_at (dfd, path, &stbuf, dfd, path_tmp, copyflags, - cancellable, &tmp_error)) - { - if (g_error_matches (tmp_error, G_IO_ERROR, G_IO_ERROR_EXISTS)) - continue; - g_propagate_error (error, g_steal_pointer (&tmp_error)); - return FALSE; - } - - copy_success = TRUE; - break; - } - - if (!copy_success) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS, - "Exceeded limit of %u file creation attempts", count); - return FALSE; - } - - if (!glnx_renameat (dfd, path_tmp, dfd, path, error)) - return FALSE; - } - - return TRUE; -} - /* Given the result of rpm_ostree_db_diff(), print it. */ void rpmostree_diff_print (GPtrArray *removed, diff --git a/src/libpriv/rpmostree-util.h b/src/libpriv/rpmostree-util.h index 0f596f877f..f6d39db009 100644 --- a/src/libpriv/rpmostree-util.h +++ b/src/libpriv/rpmostree-util.h @@ -130,13 +130,6 @@ rpmostree_cache_branch_to_nevra (const char *cachebranch); char * rpmostree_commit_content_checksum (GVariant *commit); -gboolean -rpmostree_break_hardlink (int dfd, - const char *path, - GLnxFileCopyFlags copyflags, - GCancellable *cancellable, - GError **error); - /* https://github.com/ostreedev/ostree/pull/1132 */ typedef struct { gboolean initialized;