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
why shut my copy task when i wanna to copy a dir with use filter function #552
Comments
You're consistently returning |
@RyanZim ,i mean although i always return |
@moonrailgun you are strictly returning |
@manidlou @RyanZim now , i have a dir like this:
and the index.js is a test script like this: const fs = require('fs-extra');
fs.copy('./src', './dist', {
filter: function(src) {
if(src.indexOf('b') >= 0) return false;// i dont want to copy file b
return true;
}
}, (err) => {
if (err) return console.error(err);
console.log('success!');
}) Then , i cd to this dir and run
and then, i change my
my |
Mmm...! @moonrailgun I guess you don't get your desired results because your filter condition is based on the src path string, and we overwrite the src and dest with their full paths while we shouldn't! I blame myself on that! In order to make sure about this, will you please change your filter condition to something like this? If my guess is true, your code should work with these changes. const fs = require('fs-extra');
const path = require('path');
fs.copy('./src', './dist', {
filter: function(src) {
const basename = path.basename(src)
if(basename.indexOf('b') >= 0) return false;// i dont want to copy file b
return true;
}
}, (err) => {
if (err) return console.error(err);
console.log('success!');
}) |
@manidlou well this work, but not my mind. but plz look at the follow code: const fs = require('fs-extra');
fs.copy('./src', './dist', {
filter: () => {
const isPass = Math.random() < 0.5;
console.log(isPass);
return isPass;
},
}, (err) => {
if (err) return console.error(err);
console.log('success!');
return null;
}); if the pass return false in first times, or second times. the task is done. and or return false not the first times, its run. and i find why its done . because the first times and second times the src is the root dir. if my filter function not pass it, its throw a error and done my copy task. i just want to copy dir with maybe add some tips in readme file? hopes can help others who happened same problem like me. thanks for your help |
@moonrailgun the proposed fix #554 is under review. It will be most likely published in the next release. |
Good change! same path for filter func can avoid some problem and avoid use |
Fixed in #554, will be in the next release later this month. |
node-fs-extra/lib/copy/copy.js
Lines 59 to 65 in a0d44c1
example:
shut down in first file copy!
i have no idea why about use
cb()
when runhandleFilter
. maybe i just wanna copy a dir and hope to filter some file which i dont want to copyis this a reasonable design?
The text was updated successfully, but these errors were encountered: