Lines Matching defs:to

140 static int fd_copy_symlink(int df, const char *from, const struct stat *st, int dt, const char *to) {
146 assert(to);
152 if (symlinkat(target, dt, to) < 0)
155 if (fchownat(dt, to, st->st_uid, st->st_gid, AT_SYMLINK_NOFOLLOW) < 0)
161 static int fd_copy_regular(int df, const char *from, const struct stat *st, int dt, const char *to) {
168 assert(to);
174 fdt = openat(dt, to, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, st->st_mode & 07777);
180 unlinkat(dt, to, 0);
201 unlinkat(dt, to, 0);
207 static int fd_copy_fifo(int df, const char *from, const struct stat *st, int dt, const char *to) {
212 assert(to);
214 r = mkfifoat(dt, to, st->st_mode & 07777);
218 if (fchownat(dt, to, st->st_uid, st->st_gid, AT_SYMLINK_NOFOLLOW) < 0)
221 if (fchmodat(dt, to, st->st_mode & 07777, 0) < 0)
227 static int fd_copy_node(int df, const char *from, const struct stat *st, int dt, const char *to) {
232 assert(to);
234 r = mknodat(dt, to, st->st_mode, st->st_rdev);
238 if (fchownat(dt, to, st->st_uid, st->st_gid, AT_SYMLINK_NOFOLLOW) < 0)
241 if (fchmodat(dt, to, st->st_mode & 07777, 0) < 0)
252 const char *to,
263 assert(to);
275 r = mkdirat(dt, to, st->st_mode & 07777);
283 fdt = openat(dt, to, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
343 int copy_tree_at(int fdf, const char *from, int fdt, const char *to, bool merge) {
347 assert(to);
353 return fd_copy_regular(fdf, from, &st, fdt, to);
355 return fd_copy_directory(fdf, from, &st, fdt, to, st.st_dev, merge);
357 return fd_copy_symlink(fdf, from, &st, fdt, to);
359 return fd_copy_fifo(fdf, from, &st, fdt, to);
361 return fd_copy_node(fdf, from, &st, fdt, to);
366 int copy_tree(const char *from, const char *to, bool merge) {
367 return copy_tree_at(AT_FDCWD, from, AT_FDCWD, to, merge);
370 int copy_directory_fd(int dirfd, const char *to, bool merge) {
375 assert(to);
383 return fd_copy_directory(dirfd, NULL, &st, AT_FDCWD, to, st.st_dev, merge);
405 int copy_file(const char *from, const char *to, int flags, mode_t mode, unsigned chattr_flags) {
409 assert(to);
412 fdt = open(to, flags|O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, mode);
423 unlink(to);
428 unlink_noerrno(to);
435 int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace, unsigned chattr_flags) {
440 assert(to);
442 r = tempfn_random(to, NULL, &t);
451 r = renameat(AT_FDCWD, t, AT_FDCWD, to);
455 r = rename_noreplace(AT_FDCWD, t, AT_FDCWD, to);