Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict'
  2. const fs = require('graceful-fs')
  3. const path = require('path')
  4. const invalidWin32Path = require('./win32').invalidWin32Path
  5. const o777 = parseInt('0777', 8)
  6. function mkdirsSync (p, opts, made) {
  7. if (!opts || typeof opts !== 'object') {
  8. opts = { mode: opts }
  9. }
  10. let mode = opts.mode
  11. const xfs = opts.fs || fs
  12. if (process.platform === 'win32' && invalidWin32Path(p)) {
  13. const errInval = new Error(p + ' contains invalid WIN32 path characters.')
  14. errInval.code = 'EINVAL'
  15. throw errInval
  16. }
  17. if (mode === undefined) {
  18. mode = o777 & (~process.umask())
  19. }
  20. if (!made) made = null
  21. p = path.resolve(p)
  22. try {
  23. xfs.mkdirSync(p, mode)
  24. made = made || p
  25. } catch (err0) {
  26. if (err0.code === 'ENOENT') {
  27. if (path.dirname(p) === p) throw err0
  28. made = mkdirsSync(path.dirname(p), opts, made)
  29. mkdirsSync(p, opts, made)
  30. } else {
  31. // In the case of any other error, just see if there's a dir there
  32. // already. If so, then hooray! If not, then something is borked.
  33. let stat
  34. try {
  35. stat = xfs.statSync(p)
  36. } catch (err1) {
  37. throw err0
  38. }
  39. if (!stat.isDirectory()) throw err0
  40. }
  41. }
  42. return made
  43. }
  44. module.exports = mkdirsSync