Skip to content

Commit

Permalink
core,passwd: Use new libostree hardlink-break API
Browse files Browse the repository at this point in the history
The code moved into libostree here:
ostreedev/ostree#1378
  • Loading branch information
cgwalters committed Dec 14, 2017
1 parent 6a2962f commit 22dca57
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 73 deletions.
6 changes: 3 additions & 3 deletions src/libpriv/rpmostree-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/libpriv/rpmostree-passwd-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
61 changes: 0 additions & 61 deletions src/libpriv/rpmostree-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions src/libpriv/rpmostree-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 22dca57

Please sign in to comment.