copy: Make copy_xattr() more generic

Let's make copy_xattr() a little more generic in preparation for
copying symlink xattrs.
This commit is contained in:
Daan De Meyer
2023-02-13 21:51:11 +01:00
parent a4d2461c46
commit c17cfe6ef7
8 changed files with 16 additions and 16 deletions

View File

@@ -1105,7 +1105,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
if (r < 0)
return log_error_errno(r, "Failed to copy bytes from %s in mage '%s' to '%s': %m", arg_source, arg_image, arg_target);
(void) copy_xattr(source_fd, target_fd, 0);
(void) copy_xattr(source_fd, NULL, target_fd, NULL, 0);
(void) copy_access(source_fd, target_fd);
(void) copy_times(source_fd, target_fd, 0);
@@ -1182,7 +1182,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
if (r < 0)
return log_error_errno(r, "Failed to copy bytes from '%s' to '%s' in image '%s': %m", arg_source, arg_target, arg_image);
(void) copy_xattr(source_fd, target_fd, 0);
(void) copy_xattr(source_fd, NULL, target_fd, NULL, 0);
(void) copy_access(source_fd, target_fd);
(void) copy_times(source_fd, target_fd, 0);

View File

@@ -216,7 +216,7 @@ static int raw_export_process(RawExport *e) {
finish:
if (r >= 0) {
(void) copy_times(e->input_fd, e->output_fd, COPY_CRTIME);
(void) copy_xattr(e->input_fd, e->output_fd, 0);
(void) copy_xattr(e->input_fd, NULL, e->output_fd, NULL, 0);
}
if (e->on_finished)

View File

@@ -234,7 +234,7 @@ static int raw_import_finish(RawImport *i) {
if (S_ISREG(i->input_stat.st_mode)) {
(void) copy_times(i->input_fd, i->output_fd, COPY_CRTIME);
(void) copy_xattr(i->input_fd, i->output_fd, 0);
(void) copy_xattr(i->input_fd, NULL, i->output_fd, NULL, 0);
}
}

View File

@@ -396,7 +396,7 @@ static int raw_pull_make_local_copy(RawPull *i) {
return log_error_errno(r, "Failed to make writable copy of image: %m");
(void) copy_times(i->raw_job->disk_fd, dfd, COPY_CRTIME);
(void) copy_xattr(i->raw_job->disk_fd, dfd, 0);
(void) copy_xattr(i->raw_job->disk_fd, NULL, dfd, NULL, 0);
dfd = safe_close(dfd);

View File

@@ -921,7 +921,7 @@ int locale_gen_enable_locale(const char *locale) {
r = copy_access(fileno(fr), fileno(fw));
if (r < 0)
return r;
r = copy_xattr(fileno(fr), fileno(fw), COPY_ALL_XATTRS);
r = copy_xattr(fileno(fr), NULL, fileno(fw), NULL, COPY_ALL_XATTRS);
if (r < 0)
log_debug_errno(r, "Failed to copy all xattrs from old to new /etc/locale.gen file, ignoring: %m");
}

View File

@@ -3840,7 +3840,7 @@ static int do_copy_files(Partition *p, const char *root, const Set *denylist) {
if (r < 0)
return log_error_errno(r, "Failed to copy '%s' to '%s%s': %m", *source, strempty(arg_root), *target);
(void) copy_xattr(sfd, tfd, COPY_ALL_XATTRS);
(void) copy_xattr(sfd, NULL, tfd, NULL, COPY_ALL_XATTRS);
(void) copy_access(sfd, tfd);
(void) copy_times(sfd, tfd, 0);
}

View File

@@ -754,7 +754,7 @@ static int fd_copy_regular(
r = -errno;
(void) futimens(fdt, (struct timespec[]) { st->st_atim, st->st_mtim });
(void) copy_xattr(fdf, fdt, copy_flags);
(void) copy_xattr(fdf, NULL, fdt, NULL, copy_flags);
if (copy_flags & COPY_FSYNC) {
if (fsync(fdt) < 0) {
@@ -1058,7 +1058,7 @@ static int fd_copy_directory(
if (fchmod(fdt, st->st_mode & 07777) < 0)
r = -errno;
(void) copy_xattr(dirfd(d), fdt, copy_flags);
(void) copy_xattr(dirfd(d), NULL, fdt, NULL, copy_flags);
(void) futimens(fdt, (struct timespec[]) { st->st_atim, st->st_mtim });
}
@@ -1313,7 +1313,7 @@ int copy_file_fd_full(
* mode/ownership of that device node...) */
if (S_ISREG(st.st_mode)) {
(void) copy_times(fdf, fdt, copy_flags);
(void) copy_xattr(fdf, fdt, copy_flags);
(void) copy_xattr(fdf, NULL, fdt, NULL, copy_flags);
}
if (copy_flags & COPY_FSYNC_FULL) {
@@ -1385,7 +1385,7 @@ int copy_file_full(
goto fail;
(void) copy_times(fdf, fdt, copy_flags);
(void) copy_xattr(fdf, fdt, copy_flags);
(void) copy_xattr(fdf, NULL, fdt, NULL, copy_flags);
if (chattr_mask != 0)
(void) chattr_fd(fdt, chattr_flags, chattr_mask & ~CHATTR_EARLY_FL, NULL);
@@ -1570,11 +1570,11 @@ int copy_rights_with_fallback(int fdf, int fdt, const char *patht) {
return fchmod_and_chown_with_fallback(fdt, patht, st.st_mode & 07777, st.st_uid, st.st_gid);
}
int copy_xattr(int fdf, int fdt, CopyFlags copy_flags) {
int copy_xattr(int df, const char *from, int dt, const char *to, CopyFlags copy_flags) {
_cleanup_free_ char *names = NULL;
int ret = 0, r;
r = flistxattr_malloc(fdf, &names);
r = listxattr_at_malloc(df, from, 0, &names);
if (r < 0)
return r;
@@ -1584,13 +1584,13 @@ int copy_xattr(int fdf, int fdt, CopyFlags copy_flags) {
if (!FLAGS_SET(copy_flags, COPY_ALL_XATTRS) && !startswith(p, "user."))
continue;
r = fgetxattr_malloc(fdf, p, &value);
r = getxattr_at_malloc(df, from, p, 0, &value);
if (r == -ENODATA)
continue; /* gone by now */
if (r < 0)
return r;
if (fsetxattr(fdt, p, value, r, 0) < 0)
if (xsetxattr(dt, to, p, value, r, 0) < 0)
ret = -errno;
}

View File

@@ -77,4 +77,4 @@ int copy_rights_with_fallback(int fdf, int fdt, const char *patht);
static inline int copy_rights(int fdf, int fdt) {
return copy_rights_with_fallback(fdf, fdt, NULL); /* no fallback */
}
int copy_xattr(int fdf, int fdt, CopyFlags copy_flags);
int copy_xattr(int df, const char *from, int dt, const char *to, CopyFlags copy_flags);