Skip to content

fs.copyFile does not actually do a full copy #30575

Open
@greggman

Description

@greggman
  • Version: 13.1.0
  • Platform: MacOS
  • Subsystem: fs

copyFile on MacOS does not correctly copy files. A simple example

Here's a .jpg downloaded with Chrome

$ ls -l -@     
total 6792
-rw-r--r--@ 1 gregg  staff  3476085 Nov 21 20:28 original.jpg
	com.apple.macl	     72 
	com.apple.metadata:_kMDItemUserTags	     42 
	com.apple.metadata:kMDItemWhereFroms	    190 
	com.apple.quarantine	     57 

copy with it cp

$ cp original.jpg copied-with-cp.jpg
$ls -l -@                          
total 13584
-rw-r--r--@ 1 gregg  staff  3476085 Nov 21 20:48 copied-with-cp.jpg
	com.apple.macl	     72 
	com.apple.metadata:_kMDItemUserTags	     42 
	com.apple.metadata:kMDItemWhereFroms	    190 
	com.apple.quarantine	     57 
-rw-r--r--@ 1 gregg  staff  3476085 Nov 21 20:28 original.jpg
	com.apple.macl	     72 
	com.apple.metadata:_kMDItemUserTags	     42 
	com.apple.metadata:kMDItemWhereFroms	    190 
	com.apple.quarantine	     57 

now copy it with fs.copyFileSync

$ node
Welcome to Node.js v13.1.0.
Type ".help" for more information.
> const fs = require('fs')
undefined
> fs.copyFileSync('original.jpg', 'copied-with-fs-copyFile.jpg');
undefined
> 
$ ls -l -@
total 20376
-rw-r--r--@ 1 gregg  staff  3476085 Nov 21 20:48 copied-with-cp.jpg
	com.apple.macl	     72 
	com.apple.metadata:_kMDItemUserTags	     42 
	com.apple.metadata:kMDItemWhereFroms	    190 
	com.apple.quarantine	     57 
-rw-r--r--  1 gregg  staff  3476085 Nov 21 20:49 copied-with-fs-copyFile.jpg
-rw-r--r--@ 1 gregg  staff  3476085 Nov 21 20:28 original.jpg
	com.apple.macl	     72 
	com.apple.metadata:_kMDItemUserTags	     42 
	com.apple.metadata:kMDItemWhereFroms	    190 
	com.apple.quarantine	     57 

notice all the metadata is missing.

I believe like windows calls an OS level copy function in MacOS copyItem needs to be called.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.libuvIssues and PRs related to the libuv dependency or the uv binding.macosIssues and PRs related to the macOS platform / OSX.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions