macos: revert clonefile (#3987)
* Revert "macos: fix source not being followed when cloning (#3941)" This reverts commit507f2f950d. * Revert "darwin: bring back macos-specific copyfile(3) (#3654)" This reverts commitd4eb276eea.
This commit is contained in:
parent
3f331e97da
commit
15e81386bf
@ -66,9 +66,7 @@
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
# include <copyfile.h>
|
||||
# include <sys/clonefile.h>
|
||||
# define UV__FS_CLONE_ACL 0x0004
|
||||
# include <sys/sysctl.h>
|
||||
#elif defined(__linux__) && !defined(FICLONE)
|
||||
# include <sys/ioctl.h>
|
||||
# define FICLONE _IOW(0x94, 9, int)
|
||||
@ -1243,74 +1241,7 @@ done:
|
||||
return r;
|
||||
}
|
||||
|
||||
#if defined(__APPLE__) && !TARGET_OS_IPHONE
|
||||
|
||||
static int uv__fs_clonefile_mac(uv_fs_t* req) {
|
||||
static _Atomic int no_clone_acl;
|
||||
int flags;
|
||||
|
||||
flags = UV__FS_CLONE_ACL;
|
||||
if (atomic_load_explicit(&no_clone_acl, memory_order_relaxed))
|
||||
flags = 0;
|
||||
|
||||
/* Note: clonefile() does not set the group ID on the destination
|
||||
* file correctly. */
|
||||
if (!clonefile(req->path, req->new_path, flags))
|
||||
return 0; /* success */
|
||||
|
||||
if (errno == EINVAL) {
|
||||
atomic_store_explicit(&no_clone_acl, 1, memory_order_relaxed);
|
||||
errno = 0;
|
||||
/* UV__FS_CLONE_ACL flag not supported (macOS < 13); try without. */
|
||||
if (!clonefile(req->path, req->new_path, 0))
|
||||
return 0; /* success */
|
||||
}
|
||||
|
||||
return UV__ERR(errno);
|
||||
}
|
||||
|
||||
static int uv__fs_fcopyfile_mac(uv_fs_t* req) {
|
||||
int rc;
|
||||
copyfile_flags_t flags;
|
||||
|
||||
/* Don't overwrite the destination if its permissions disallow it. */
|
||||
if (faccessat(AT_FDCWD, req->new_path, R_OK | W_OK, AT_EACCESS)) {
|
||||
if (errno != ENOENT)
|
||||
return UV__ERR(errno);
|
||||
}
|
||||
|
||||
if ((req->flags & UV_FS_COPYFILE_FICLONE) ||
|
||||
(req->flags & UV_FS_COPYFILE_FICLONE_FORCE)) {
|
||||
rc = uv__fs_clonefile_mac(req);
|
||||
|
||||
/* Return on success.
|
||||
* If an error occurred and force was set, return the error to the caller;
|
||||
* fall back to copyfile() when force was not set. */
|
||||
if (rc == 0 || (req->flags & UV_FS_COPYFILE_FICLONE_FORCE))
|
||||
return rc;
|
||||
|
||||
/* cloning failed. Inherit clonefile flags required for
|
||||
falling back to copyfile. */
|
||||
flags = COPYFILE_ALL | COPYFILE_NOFOLLOW_SRC | COPYFILE_EXCL;
|
||||
} else {
|
||||
flags = COPYFILE_ALL;
|
||||
if (req->flags & UV_FS_COPYFILE_EXCL)
|
||||
flags |= COPYFILE_EXCL;
|
||||
}
|
||||
|
||||
if (copyfile(req->path, req->new_path, NULL, flags))
|
||||
return UV__ERR(errno);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* defined(__APPLE__) && !TARGET_OS_IPHONE */
|
||||
|
||||
static int uv__fs_copyfile(uv_fs_t* req) {
|
||||
#if defined(__APPLE__) && !TARGET_OS_IPHONE
|
||||
/* On macOS, use the native clonefile(2)/copyfile(3). */
|
||||
return uv__fs_fcopyfile_mac(req);
|
||||
#else
|
||||
static ssize_t uv__fs_copyfile(uv_fs_t* req) {
|
||||
uv_fs_t fs_req;
|
||||
uv_file srcfd;
|
||||
uv_file dstfd;
|
||||
@ -1486,7 +1417,6 @@ out:
|
||||
|
||||
errno = UV__ERR(result);
|
||||
return -1;
|
||||
#endif /* defined(__APPLE__) && !TARGET_OS_IPHONE */
|
||||
}
|
||||
|
||||
static void uv__to_stat(struct stat* src, uv_stat_t* dst) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user