Skip to content

Commit

Permalink
fs: remove macOS-specific copyfile(3)
Browse files Browse the repository at this point in the history
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: nodejs/node#26936 (comment)
  • Loading branch information
Trott committed Mar 27, 2019
1 parent 99440bb commit d46e754
Showing 1 changed file with 0 additions and 40 deletions.
40 changes: 0 additions & 40 deletions src/unix/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,45 +889,6 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
}

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;
Expand Down Expand Up @@ -1054,7 +1015,6 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) {

errno = UV__ERR(result);
return -1;
#endif
}

static void uv__to_stat(struct stat* src, uv_stat_t* dst) {
Expand Down

0 comments on commit d46e754

Please sign in to comment.