From 5bc4d7738a172f6361d8b5dd0949789dcf1ff60d Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 26 Mar 2019 23:12:13 -0700 Subject: [PATCH] fs: remove macOS-specific copyfile(3) Using copyfile(3) on macOS apparently results in situations where file permissions are ignored. Using the same code for other UNIX-like operating systems seems to fix the issue. Refs: https://github.com/nodejs/node/issues/26936#issuecomment-476992597 PR-URL: https://github.com/libuv/libuv/pull/2233 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Santiago Gimeno Reviewed-By: Sakthipriyan Vairamani --- src/unix/fs.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/src/unix/fs.c b/src/unix/fs.c index ade88051..da5d603c 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -60,7 +60,6 @@ #endif #if defined(__APPLE__) -# include # include #elif defined(__linux__) && !defined(FICLONE) # include @@ -889,45 +888,6 @@ done: } static ssize_t uv__fs_copyfile(uv_fs_t* req) { -#if defined(__APPLE__) && !TARGET_OS_IPHONE - /* On macOS, use the native copyfile(3). */ - static int can_clone; - copyfile_flags_t flags; - char buf[64]; - size_t len; - int major; - - flags = COPYFILE_ALL; - - if (req->flags & UV_FS_COPYFILE_EXCL) - flags |= COPYFILE_EXCL; - - /* Check OS version. Cloning is only supported on macOS >= 10.12. */ - if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE) { - if (can_clone == 0) { - len = sizeof(buf); - if (sysctlbyname("kern.osrelease", buf, &len, NULL, 0)) - return UV__ERR(errno); - - if (1 != sscanf(buf, "%d", &major)) - abort(); - - can_clone = -1 + 2 * (major >= 16); /* macOS >= 10.12 */ - } - - if (can_clone < 0) - return UV_ENOSYS; - } - - /* copyfile() simply ignores COPYFILE_CLONE if it's not supported. */ - if (req->flags & UV_FS_COPYFILE_FICLONE) - flags |= 1 << 24; /* COPYFILE_CLONE */ - - if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE) - flags |= 1 << 25; /* COPYFILE_CLONE_FORCE */ - - return copyfile(req->path, req->new_path, NULL, flags); -#else uv_fs_t fs_req; uv_file srcfd; uv_file dstfd; @@ -1054,7 +1014,6 @@ out: errno = UV__ERR(result); return -1; -#endif } static void uv__to_stat(struct stat* src, uv_stat_t* dst) {