davglass / cpr

Nodejs cp -R
Other
79 stars 80 forks source link

Empty directory handling #11

Closed silverwind closed 9 years ago

silverwind commented 9 years ago

Seems this module doesn't handle empty directories very well. Given a file tree

parent
    child-dir
    child.file

If you cpr the parent somewhere, there's an inevitable stat error on the destination child-dir path. Similary, just running cpr on an empty directory also fails. I'm working around this now with

fs.readdir(src, function (err, files) {
    if (files.length) {
        cpr(src, dst, function (errs) {
            if (!errs) return;
            errs.forEach(function (err) {
                if (err.code === "ENOENT" && err.syscall === "stat") {
                    mkdirp(err.path);
                }
            });
        });
    } else {
        mkdirp(dst);
    }
});

but it'd be nice to see this fixed :)

davglass commented 9 years ago

Published in cpr@0.4.0, let me know if you have any more issues with it.

silverwind commented 9 years ago

:+1: looks to be working!