Skip to content

fs: add recursive cp method - #39372

Closed
bcoe wants to merge 1 commit into
nodejs:masterfrom
bcoe:copy
Closed

fs: add recursive cp method#39372
bcoe wants to merge 1 commit into
nodejs:masterfrom
bcoe:copy

Conversation

@bcoe

@bcoebcoe commented Jul 13, 2021

Copy link
Copy Markdown
Contributor

Introduces recursive cp method, based on fs-extra implementation

Refs: nodejs/tooling#98
Fixes: #35880


Opening to start conversation.

TODO:

  • still have many tests to write, to increase coverage. (coverage is at 92%).
  • need to document sync and promise API.

CC: @nodejs/tooling, @jprichardson, @manidlou, @RyanZim

@nodejs-github-botnodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jul 13, 2021
Comment threadtest/parallel/test-copy.js Outdated
Comment threadlib/internal/fs/copy/copy.js Outdated
Comment threadlib/internal/fs/copy/copy.js Outdated
@nodejs-github-bot

This comment has been minimized.

Comment threadlib/internal/fs/promises.js Outdated
Comment threadlib/internal/fs/promises.js Outdated
Comment threadlib/internal/fs/copy/copy.js Outdated
Comment threadlib/internal/fs/copy/copy.js Outdated
Comment threadlib/internal/fs/copy/copy-sync.js Outdated

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@targostargos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making sure this doesn't land without documentation for the Promises and sync APIs

Comment threadlib/internal/fs/copy/copy-sync.js
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@iansuiansu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall! 🙌

Comment threadlib/internal/fs/promises.js Outdated
Comment threadlib/internal/fs/utils.js Outdated
@bcoe

bcoe commented Jul 15, 2021

Copy link
Copy Markdown
ContributorAuthor

@mcollina@targos small, but significant update, I thought force would be a better option than overwrite for when clobbering the destination folder, and have renamed it to this. Also, force now defaults to false.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@bcoebcoe added notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version. labels Jul 15, 2021
Comment threadlib/internal/fs/copy/copy-sync.js Outdated
@RyanZim

Copy link
Copy Markdown
Contributor

I thought force would be a better option than overwrite for when clobbering the destination folder, and have renamed it to this. Also, force now defaults to false.

While we're rethinking options, should errorOnExist default to false or true? This is another one of those options that has its value for compat reasons.

@RyanZim

Copy link
Copy Markdown
Contributor

Also, for reference; discussion thread on how fs-extra should handle the forthcoming naming conflict: jprichardson/node-fs-extra#912

@aduh95aduh95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further simplifications on the subject of replacing open + futimes + close with utimes.

Comment threadlib/internal/fs/copy/copy-sync.js Outdated
Comment threadlib/internal/fs/copy/copy-sync.js Outdated
Comment threadlib/internal/fs/copy/copy.js Outdated
Comment threadlib/internal/fs/copy/copy.js Outdated
@bcoe

bcoe commented Jul 15, 2021

Copy link
Copy Markdown
ContributorAuthor

@RyanZim@iansu

While we're rethinking options, should errorOnExist default to false or true? This is another one of those options that has its value for compat reasons.

I was tempted to go with false, which I believe would make copying to the same folder twice relatively safe, i.e., you don't clobber files, but it's less of a pain in the neck to recover from a partial copy (you don't have to lookup an option).

Thoughts?

Comment threadlib/internal/fs/utils.js Outdated
@nodejs-github-bot

This comment has been minimized.

Comment threaddoc/api/errors.md Outdated
Comment threaddoc/api/errors.md Outdated
Comment threaddoc/api/fs.md Outdated
Comment threadlib/internal/fs/copy/copy-sync.js Outdated
Comment threadlib/internal/fs/copy/copy.js Outdated
Comment threadlib/internal/fs/copy/copy.js Outdated
@bcoe

bcoe commented Jul 22, 2021

Copy link
Copy Markdown
ContributorAuthor

FYI, waiting on a windows machine at work (there are some hiccups with provisioning). Would happily pair with someone on fixing up the failing windows test, if anyone has a system up and running.

bcoe pushed a commit that referenced this pull request Aug 12, 2021
Introduces recursive cp method, based on fs-extra implementation.
PR-URL: #39372Fixes: #35880
Refs: nodejs/tooling#98
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ian Sutherland <ian@iansutherland.ca>
@bcoe

bcoe commented Aug 12, 2021

Copy link
Copy Markdown
ContributorAuthor

Landed in 87d6fd7

@bcoebcoe closed this Aug 12, 2021
danielleadams pushed a commit that referenced this pull request Aug 16, 2021
Introduces recursive cp method, based on fs-extra implementation.
PR-URL: #39372Fixes: #35880
Refs: nodejs/tooling#98
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ian Sutherland <ian@iansutherland.ca>
danielleadams added a commit that referenced this pull request Aug 16, 2021
Notable changes:
* fs:
* add recursive cp method (Benjamin Coe) #39372
PR-URL: #39782
@aduh95aduh95 added the experimental Issues and PRs related to experimental features. label Aug 16, 2021
danielleadams added a commit that referenced this pull request Aug 17, 2021
Notable changes:
* fs:
* experimental: add recursive cp method (Benjamin Coe) #39372
PR-URL: #39782
danielleadams added a commit that referenced this pull request Aug 18, 2021
Notable changes:
* fs:
* experimental: add recursive cp method (Benjamin Coe) #39372
PR-URL: #39782
@lostpebble

lostpebble commented Aug 19, 2021

Copy link
Copy Markdown

Is there any place to give feedback on this function?

Just looking through the docs, I think the option force: <boolean> is a bit ambiguous and would have been better suited to be named overwrite- as that's literally what it achieves, according to the docs.

[EDIT]
Sorry, after reading further comments, I see it was actually changed from overwrite to force - which I'm a little confused about now...

@bcoe

bcoe commented Aug 26, 2021

Copy link
Copy Markdown
ContributorAuthor

@lostpebble please feel free to open an issue. As much as possible I'd like to model after cp's flags, but perhaps clobber is the better name in this case?

One good thing about force is it's consistent with rm.

RyanZim added a commit to jprichardson/node-fs-extra that referenced this pull request Oct 25, 2022
RyanZim added a commit to jprichardson/node-fs-extra that referenced this pull request Nov 19, 2022
neysidevhcr1j added a commit to neysidevhcr1j/neysidevhcr1j that referenced this pull request May 20, 2025
9liaswilde added a commit to 9liaswilde/robotboy6558 that referenced this pull request May 30, 2025
AnthoneTurner added a commit to AnthoneTurner/stone that referenced this pull request Jun 10, 2025
SaurabViena pushed a commit to SaurabViena/NoneCharacter that referenced this pull request Jun 13, 2025
bugcloudLeah pushed a commit to bugcloudLeah/vert-x3 that referenced this pull request Jun 15, 2025
FabianSili pushed a commit to FabianSili/CazaresLuisc that referenced this pull request Jun 15, 2025
JosepehWilson added a commit to JosepehWilson/Xilinxa that referenced this pull request Jul 6, 2025
StevensBrownu added a commit to StevensBrownu/funicular that referenced this pull request Jul 8, 2025
ID279184665 added a commit to ID279184665/phytochemical that referenced this pull request Jul 22, 2025
criticalPathway added a commit to criticalPathway/node-fs-extra that referenced this pull request Nov 17, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.experimentalIssues and PRs related to experimental features.lib / srcIssues and PRs related to general changes in the lib or src directory.needs-ciPRs that need a full CI run.notable-changePRs with changes that should be highlighted in changelogs.semver-minorPRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs: add cp method

13 participants

@bcoe@nodejs-github-bot@RyanZim@targos@manidlou@lostpebble@mcollina@joesepi@iansu@jasnell@merceyz@aduh95@Mesteery