diff --git a/src/shared/copy.c b/src/shared/copy.c index db26945be8..241a2d112b 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -1084,6 +1084,9 @@ finish: return -errno; } + if (r < 0) + return r; + return copy_flags & COPY_LOCK_BSD ? TAKE_FD(fdt) : 0; } @@ -1133,8 +1136,11 @@ static int fd_copy_tree_generic( copy_progress_path_t progress_path, copy_progress_bytes_t progress_bytes, void *userdata) { + int r; + assert(!FLAGS_SET(copy_flags, COPY_LOCK_BSD)); + if (S_ISDIR(st->st_mode)) return fd_copy_directory(df, from, st, dt, to, original_device, depth_left-1, override_uid, override_gid, copy_flags, denylist, hardlink_context, display_path, @@ -1230,6 +1236,7 @@ int copy_directory_at_full( copy_progress_bytes_t progress_bytes, void *userdata) { + _cleanup_close_ int fdt = -EBADF; struct stat st; int r; @@ -1259,11 +1266,14 @@ int copy_directory_at_full( if (r < 0) return r; + if (FLAGS_SET(copy_flags, COPY_LOCK_BSD)) + fdt = r; + r = sync_dir_by_flags(dir_fdt, to, copy_flags); if (r < 0) return r; - return 0; + return FLAGS_SET(copy_flags, COPY_LOCK_BSD) ? TAKE_FD(fdt) : 0; } int copy_file_fd_at_full(