-
Notifications
You must be signed in to change notification settings - Fork 774
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Feature Request] [copy] pass srcStat and destStat to filter #844
Comments
Yeah, if we're already getting stats, no reason not to pass them that I can see; @manidlou? |
Yeah we already get the src and dest stats before we check the filter, so yeah we could pass them to the filter function. |
It would help a lot, but it will not solve all the problems. In the example given by @jedwards1211 the filter function: |
@tomaszcoding Unfortunately, that behavior isn't possible with our implementation, since we don't examine the contents of folders until we run them through the filter. |
I can imagine a solution where the filter function returns a special value that means read this directory but don't create the target directory in the destination yet. Then, when copying a file or directory that the filter returned true for, we would mkdirp its parent (if we haven't already in the current copy operation). |
I think filter should return a boolean (or a Promise resolving to a boolean). This is natural and this is what most people would expect. Also I wouldn't force people to care about performance if they don't have to. The filter function should be responsible for single thing i.e. filtering. Anything more than this would be to imperative in my opinion. Also I wouldn't be so concerned about efficiency here. @RyanZim I understand you would like to implement kind of "lazy" filtering? I believe most users need the "greedy" one (in the end, copy from fs-extra was made to simplify copying recursively). This is the 2nd time I'm using fs-extra and the 1st time I'm using it with a filter and I already hit this problem. I had to use node's |
|
@RyanZim I agree with you in terms of being aligned with node core. However, generally speaking, having |
I would direct them to Node core. |
I'm going to close this out for now; if someone wants this feature, please lobby for its addition in Node core. |
I'm willing to make a PR if you're on board with this 🙂
As mentioned in #843, when doing a
copy
,filter
is actually called with both files and directories. This means if we only want to copy.js
files, our filter has to befilter: async f => (await fs.stat(f)).isDirectory() || f.endsWith('.js')
, which is cumbersome and redundant.copy
is already getting the stats of everything along the way, so if it would pass them to the filter then we could avoid getting them redundantly:filter: (src, dest, srcStat, destStat) => srcStat.isDirectory() || src.endsWith('.js')
The text was updated successfully, but these errors were encountered: