calvinmetcalf / copyfiles

copy files on the command line
MIT License
412 stars 53 forks source link

Does not give error when copying fails #13

Open fatso83 opened 8 years ago

fatso83 commented 8 years ago

Nothing happens when I run the following script. I don't get an error and no files are being produced.

#!/usr/bin/env node --harmony
const copyfiles = require('copyfiles');
const path = require('path');

const RAZOR_PATH = "Microsoft.AspNet.Razor.3.0.0/lib/net45/System.Web.Razor.dll"
const RAZORENG_PATH = "RazorEngine.3.8.2/lib/net45/RazorEngine.dll"
const JSON_PATH = "Newtonsoft.Json.8.0.3/lib/net45/Newtonsoft.Json.dll"
const destination = '.';
const paths = [ RAZOR_PATH, RAZORENG_PATH, JSON_PATH, destination ].map(path.normalize);
const opts = {};

copyfiles(paths, opts, function(err) {
    if(err) {
        console.error(`Failed copying dependencies: ${paths}`);
        process.exit(1);
    }

    console.log('.NET dependencies copied successfully')
});
calvinmetcalf commented 8 years ago

it's not going to give an error if it can't find the paths so that's why it doesn't throw an error

Tiliavir commented 8 years ago

@calvinmetcalf: yeah but why not? It should throw or log a warning when the source path does not exist! It is completely unreliable otherwise ...

fatso83 commented 8 years ago

That logic makes no sense. If missing files is not an error, then WTF is.

calvinmetcalf commented 8 years ago

so we pass the paths to glob which tries to match them with paths on the hard drive, but a missing file just means a glob that doesn't match anything, which means we just don't put any files into the queue, so we could do a couple things

  1. throw an error if a glob doesn't produce any files, though this might be not great if somebody was just using it to transfer a bunch of directories not actually checking if anything was in them
  2. have it throw an error if nothing gets transferred at all, which would almost always be an error but might miss something
  3. do 2 by default but has an option for 1
Tiliavir commented 8 years ago

Ok that makes sense - I think adding a verbose flag, that logs a warning when a glob is not returning files would be sufficient for me - no idea what others think of this approach so...

onury commented 6 years ago

copyfiles does-not.exist out did not throw. so I'm here..