Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict'
|
---|
| 2 |
|
---|
| 3 | const fs = require('graceful-fs')
|
---|
| 4 | const path = require('path')
|
---|
| 5 | const invalidWin32Path = require('./win32').invalidWin32Path
|
---|
| 6 |
|
---|
| 7 | const o777 = parseInt('0777', 8)
|
---|
| 8 |
|
---|
| 9 | function 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 |
|
---|
| 54 | module.exports = mkdirsSync
|
---|
Note:
See
TracBrowser
for help on using the repository browser.