Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to overwrite files with copyFile #81

Open
CharlesTaylor7 opened this issue Oct 9, 2023 · 1 comment
Open

Impossible to overwrite files with copyFile #81

CharlesTaylor7 opened this issue Oct 9, 2023 · 1 comment

Comments

@CharlesTaylor7
Copy link

CharlesTaylor7 commented Oct 9, 2023

When I run Node.FS.Aff.copyFile, it fails when the file already exists.
That's because of the definition of defaultCopyMode which uses the fs.constants.COPYFILE_EXCL flag.

There's two issues:

(1) The default is inconsistent with the underlying node API. fs.copyFile without a specified copy mode operates as if no flags were applied. It allows overwriting files on copy.

https://nodejs.org/api/fs.html#fscopyfilesrc-dest-mode-callback

Asynchronously copies src to dest. By default, dest is overwritten if it already exists.

(2) There's no way to use this library to get at the node default behavior.

The structure of the Node.FS.Constants api only allows appending flags not removing them.
There's no export of a "noFlags :: CopyMode".

@CharlesTaylor7
Copy link
Author

CharlesTaylor7 commented Oct 9, 2023

I have two ideas in mind for how to resolve this:

(1)
Redefine defaultCopyMode:

-- Constants.purs
foreign import defaultCopyMode :: CopyMode
// Constants.js
export defaultCopyMode = 0;

Pros: it matches the node default.
Cons: it's a breaking change, requires a version bump and is surprising to people who relied on the old behavior.

(2)
Simply define and export this definition, but don't change defaultCopyMode. And apply some doc comments that explain the difference between noFlagsCopyMode and defaultCopyMode

// Constants.js
export noFlagsCopyMode = 0;

Pros: It's safer to have people opt-in
Cons: Not a 1:1 with the node docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant