timkendrick / recursive-copy

Simple, flexible file copy utility
96 stars 18 forks source link

Ignore existing files? #34

Open pdehaan opened 2 years ago

pdehaan commented 2 years ago

I have the following code, but not sure I 100% understand the rules of overwrite:

  copy('assets', 'www/assets', { overwrite: false }, function (err, results) {
    if (err) {
      console.error(`[ERROR] Copy failed: ${err.message}`);
    } else {
      console.info(`Copied ${results.length} files`);
    }
  });

I ran touch assets/{1..1000}.jpg so I have 1001 [invalid] image files locally. First time I run the code above, everything works and I see this in my console:

Copied 1001 files

Now, if I build my site again and run the same code, I get the following error (since the "www/assets" folder exists and has my previous images):

[ERROR] Copy failed: EEXIST, file already exists www/assets/1000.jpg

If I set { overwrite: true } it works every time, but is presumably recopying over 1001 unchanged files on each build. Is there an option for "copy the image if it doesn't exist, but ignore it if it does"?


UPDATE: I guess I'm asking for a feature/flag similar to merge-dir's conflict resolution of "overwrite"-vs-"skip"-vs-"ask" (but without "ask").