diff options
Diffstat (limited to 'node_modules/fs-extra/lib/ensure/link.js')
| -rw-r--r-- | node_modules/fs-extra/lib/ensure/link.js | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/node_modules/fs-extra/lib/ensure/link.js b/node_modules/fs-extra/lib/ensure/link.js index f6d67486..c3d1c694 100644 --- a/node_modules/fs-extra/lib/ensure/link.js +++ b/node_modules/fs-extra/lib/ensure/link.js @@ -1,39 +1,39 @@ 'use strict' -const u = require('universalify').fromCallback +const u = require('universalify').fromPromise const path = require('path') -const fs = require('graceful-fs') +const fs = require('../fs') const mkdir = require('../mkdirs') -const pathExists = require('../path-exists').pathExists +const { pathExists } = require('../path-exists') const { areIdentical } = require('../util/stat') -function createLink (srcpath, dstpath, callback) { - function makeLink (srcpath, dstpath) { - fs.link(srcpath, dstpath, err => { - if (err) return callback(err) - callback(null) - }) +async function createLink (srcpath, dstpath) { + let dstStat + try { + dstStat = await fs.lstat(dstpath) + } catch { + // ignore error } - fs.lstat(dstpath, (_, dstStat) => { - fs.lstat(srcpath, (err, srcStat) => { - if (err) { - err.message = err.message.replace('lstat', 'ensureLink') - return callback(err) - } - if (dstStat && areIdentical(srcStat, dstStat)) return callback(null) + let srcStat + try { + srcStat = await fs.lstat(srcpath) + } catch (err) { + err.message = err.message.replace('lstat', 'ensureLink') + throw err + } + + if (dstStat && areIdentical(srcStat, dstStat)) return + + const dir = path.dirname(dstpath) + + const dirExists = await pathExists(dir) + + if (!dirExists) { + await mkdir.mkdirs(dir) + } - const dir = path.dirname(dstpath) - pathExists(dir, (err, dirExists) => { - if (err) return callback(err) - if (dirExists) return makeLink(srcpath, dstpath) - mkdir.mkdirs(dir, err => { - if (err) return callback(err) - makeLink(srcpath, dstpath) - }) - }) - }) - }) + await fs.link(srcpath, dstpath) } function createLinkSync (srcpath, dstpath) { |
