From 15e81386bf9a285cada688c5faf67b3ed1319dcf Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Wed, 10 May 2023 17:38:58 +0200 Subject: [PATCH] macos: revert clonefile (#3987) * Revert "macos: fix source not being followed when cloning (#3941)" This reverts commit 507f2f950d5da7ab1586a46e81fc83dae10c0138. * Revert "darwin: bring back macos-specific copyfile(3) (#3654)" This reverts commit d4eb276eea7cb19a888fe97d7759d97c7092ad02. --- src/unix/fs.c | 74 ++------------------------------------------------- 1 file changed, 2 insertions(+), 72 deletions(-) diff --git a/src/unix/fs.c b/src/unix/fs.c index 82fa2e1b..8606e8dc 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -66,9 +66,7 @@ #endif #if defined(__APPLE__) -# include -# include -# define UV__FS_CLONE_ACL 0x0004 +# include #elif defined(__linux__) && !defined(FICLONE) # include # 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) {