davglass / cpr

Nodejs cp -R
Other
79 stars 80 forks source link

Globs #38

Open stevenvachon opened 7 years ago

stevenvachon commented 7 years ago
cpr("/path/to/dir/", "/dest/")
//-> copies contents of /path/to/dir/ into /dest/

cpr("/path/to/dir/**/*", "/dest/")
//-> same as above

cpr("/path/**/dir/", "/dest/")
//-> same, and possibly more if there're other nested dirs named "dir"

When/if glob expands directories, we can use glob.Glob to copy each file as it is expanded from the glob. This is not only better because it helps avoid race conditions by copying the file immediately after it's expanded, but it may also have better performance because the hard drive has already sought to that track/sector.

Since a glob will likely resolve to many files, we might as well implement #41 along with this. An instance of glob.Glob per glob and file paths memoized to avoid redundancy.

cpr(["/path/to/dir/", "/path/to/dir/**/*", "/path/**/dir/"], "/dest/")
//-> same as above, with no file copied more than once
stevenvachon commented 5 years ago

cpy and its underlying cp-file both do this.