core,passwd: Use new libostree hardlink-break API
The code moved into libostree here: https://github.com/ostreedev/ostree/pull/1378 Closes: #1154 Approved by: jlebon
This commit is contained in:
parent
5ff69e10db
commit
9843c93439
@ -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;
|
||||
}
|
||||
|
||||
@ -3010,7 +3010,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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user