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

Not filter each file, stops on first false #187

Closed
serraventura opened this issue Oct 29, 2015 · 5 comments
Closed

Not filter each file, stops on first false #187

serraventura opened this issue Oct 29, 2015 · 5 comments

Comments

@serraventura
Copy link

I've got same issue as #70 .

Im using latest release.

"fs-extra": "^0.26.0",

@jprichardson
Copy link
Owner

Thanks for reporting. Do you have any code (along with a description of the file tree) so that I can reproduce this bug?

@serraventura
Copy link
Author

I don't have the code anymore, since I changed the approach to not need to use the filter. But I'll try to reproduce it again later.

thnaks.

@lafleurh
Copy link

I am having this problem also. (I ended up writing my own copy folder function using your walk function and copy function that takes two paths and a filter, which worked well.)

Here's what I did when using your copy function to copy a folder with a filter:

fs.copy('/home/myuser/projects/website', '/home/myuser/public_html/customfolder', { 'clobber': true,
                        'preserveTimestamps': true, filter: /\.php$/i },
            function (err) {
                if (err) return console.error('Error copying ' + item.path + ': ' + err);
                console.log('Copied file ' + item.path);
            })

It seems like it applies the filter to the source path, when I look at the code, and doesn't get to the point where it enumerates the files and folders recursively to filter them. Maybe I'm reading it incorrectly.

This is what I see in your code:

ncp.js:

...
function ncp (source, dest, options, callback) {
...
 var currentPath = path.resolve(basePath, source)
...
  startCopy(currentPath)

  function startCopy (source) {
    started++
    if (filter) {
      if (filter instanceof RegExp) {
        if (!filter.test(source)) {
          return doneOne(true)

but I don't see it looping or any recursion prior to the filter check. That doesn't happen until onDir which is down the call stack from startCopy. It just tests the source path, which would be the root source directory. It seems like the check should be done instead in the copyFile function or onFile function to test each file individually instead.

@eos3tion
Copy link

When walk on files,the regExp's lastIndex will increase.
contents.forEach(function (content) { var opts = options opts.recursive = true copySync(path.join(src, content), path.join(dest, content), opts) })
if (options.filter instanceof RegExp) performCopy = options.filter.test(src)
Next file's test will begin with last file's index,so it will test failed and lastIndex reset to 0.

Right code must be:
if (options.filter instanceof RegExp){ options.filter.lastIndex=0; performCopy = options.filter.test(src) }

@RyanZim
Copy link
Collaborator

RyanZim commented Dec 29, 2016

Regular expression filters aren't supported anymore, closing as a wontfix.

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

No branches or pull requests

5 participants