source: trip-planner-front/node_modules/fs-extra/lib/mkdirs/mkdirs-sync.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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