File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6565#endif
6666
6767#if defined(__APPLE__ )
68+ # include <copyfile.h>
6869# include <sys/sysctl.h>
6970#elif defined(__linux__ ) && !defined(FICLONE )
7071# include <sys/ioctl.h>
@@ -1240,6 +1241,32 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
12401241}
12411242
12421243static ssize_t uv__fs_copyfile (uv_fs_t * req ) {
1244+ #if defined(__APPLE__ ) && !TARGET_OS_IPHONE
1245+ /* On macOS, use the native copyfile(3). */
1246+ copyfile_flags_t flags ;
1247+
1248+ /* Don't overwrite the destination if its permissions disallow it. */
1249+ if (faccessat (AT_FDCWD , req -> new_path , R_OK | W_OK , AT_EACCESS )) {
1250+ if (errno != ENOENT )
1251+ return UV__ERR (errno );
1252+ }
1253+
1254+ flags = COPYFILE_ALL ;
1255+
1256+ if (req -> flags & UV_FS_COPYFILE_FICLONE )
1257+ flags |= COPYFILE_CLONE ;
1258+
1259+ if (req -> flags & UV_FS_COPYFILE_FICLONE_FORCE )
1260+ flags |= COPYFILE_CLONE_FORCE ;
1261+
1262+ if (req -> flags & UV_FS_COPYFILE_EXCL )
1263+ flags |= COPYFILE_EXCL ;
1264+
1265+ if (copyfile (req -> path , req -> new_path , NULL , flags ))
1266+ return UV__ERR (errno );
1267+
1268+ return 0 ;
1269+ #else /* defined(__APPLE__) && !TARGET_OS_IPHONE */
12431270 uv_fs_t fs_req ;
12441271 uv_file srcfd ;
12451272 uv_file dstfd ;
@@ -1415,6 +1442,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) {
14151442
14161443 errno = UV__ERR (result );
14171444 return -1 ;
1445+ #endif /* defined(__APPLE__) && !TARGET_OS_IPHONE */
14181446}
14191447
14201448static void uv__to_stat (struct stat * src , uv_stat_t * dst ) {
You can’t perform that action at this time.
0 commit comments