Last change
on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
763 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | const {dirname} = require('path')
|
---|
| 2 |
|
---|
| 3 | const findMade = (opts, parent, path = undefined) => {
|
---|
| 4 | // we never want the 'made' return value to be a root directory
|
---|
| 5 | if (path === parent)
|
---|
| 6 | return Promise.resolve()
|
---|
| 7 |
|
---|
| 8 | return opts.statAsync(parent).then(
|
---|
| 9 | st => st.isDirectory() ? path : undefined, // will fail later
|
---|
| 10 | er => er.code === 'ENOENT'
|
---|
| 11 | ? findMade(opts, dirname(parent), parent)
|
---|
| 12 | : undefined
|
---|
| 13 | )
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | const findMadeSync = (opts, parent, path = undefined) => {
|
---|
| 17 | if (path === parent)
|
---|
| 18 | return undefined
|
---|
| 19 |
|
---|
| 20 | try {
|
---|
| 21 | return opts.statSync(parent).isDirectory() ? path : undefined
|
---|
| 22 | } catch (er) {
|
---|
| 23 | return er.code === 'ENOENT'
|
---|
| 24 | ? findMadeSync(opts, dirname(parent), parent)
|
---|
| 25 | : undefined
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | module.exports = {findMade, findMadeSync}
|
---|
Note:
See
TracBrowser
for help on using the repository browser.