a zip code crypto-currency system good for red ONLY

copy-sync.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict'
  2. const fs = require('graceful-fs')
  3. const path = require('path')
  4. const copyFileSync = require('./copy-file-sync')
  5. const mkdir = require('../mkdirs')
  6. function copySync (src, dest, options) {
  7. if (typeof options === 'function' || options instanceof RegExp) {
  8. options = {filter: options}
  9. }
  10. options = options || {}
  11. options.recursive = !!options.recursive
  12. // default to true for now
  13. options.clobber = 'clobber' in options ? !!options.clobber : true
  14. // overwrite falls back to clobber
  15. options.overwrite = 'overwrite' in options ? !!options.overwrite : options.clobber
  16. options.dereference = 'dereference' in options ? !!options.dereference : false
  17. options.preserveTimestamps = 'preserveTimestamps' in options ? !!options.preserveTimestamps : false
  18. options.filter = options.filter || function () { return true }
  19. // Warn about using preserveTimestamps on 32-bit node:
  20. if (options.preserveTimestamps && process.arch === 'ia32') {
  21. console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n
  22. see https://github.com/jprichardson/node-fs-extra/issues/269`)
  23. }
  24. const stats = (options.recursive && !options.dereference) ? fs.lstatSync(src) : fs.statSync(src)
  25. const destFolder = path.dirname(dest)
  26. const destFolderExists = fs.existsSync(destFolder)
  27. let performCopy = false
  28. if (options.filter instanceof RegExp) {
  29. console.warn('Warning: fs-extra: Passing a RegExp filter is deprecated, use a function')
  30. performCopy = options.filter.test(src)
  31. } else if (typeof options.filter === 'function') performCopy = options.filter(src, dest)
  32. if (stats.isFile() && performCopy) {
  33. if (!destFolderExists) mkdir.mkdirsSync(destFolder)
  34. copyFileSync(src, dest, {
  35. overwrite: options.overwrite,
  36. errorOnExist: options.errorOnExist,
  37. preserveTimestamps: options.preserveTimestamps
  38. })
  39. } else if (stats.isDirectory() && performCopy) {
  40. if (!fs.existsSync(dest)) mkdir.mkdirsSync(dest)
  41. const contents = fs.readdirSync(src)
  42. contents.forEach(content => {
  43. const opts = options
  44. opts.recursive = true
  45. copySync(path.join(src, content), path.join(dest, content), opts)
  46. })
  47. } else if (options.recursive && stats.isSymbolicLink() && performCopy) {
  48. const srcPath = fs.readlinkSync(src)
  49. fs.symlinkSync(srcPath, dest)
  50. }
  51. }
  52. module.exports = copySync