mirror of
https://github.com/jprichardson/node-fs-extra.git
synced 2026-01-25 16:42:57 +00:00
Refactor symlinkPaths/Sync
This commit is contained in:
parent
082342efbd
commit
2e81b2fe06
@ -1,6 +1,8 @@
|
||||
var path = require('path')
|
||||
'use strict'
|
||||
|
||||
const path = require('path')
|
||||
// path.isAbsolute shim for Node.js 0.10 support
|
||||
var fs = require('graceful-fs')
|
||||
const fs = require('graceful-fs')
|
||||
|
||||
/**
|
||||
* Function that returns two types of paths, one relative to symlink, and one
|
||||
@ -26,7 +28,7 @@ var fs = require('graceful-fs')
|
||||
|
||||
function symlinkPaths (srcpath, dstpath, callback) {
|
||||
if (path.isAbsolute(srcpath)) {
|
||||
return fs.lstat(srcpath, function (err, stat) {
|
||||
return fs.lstat(srcpath, (err, stat) => {
|
||||
if (err) {
|
||||
err.message = err.message.replace('lstat', 'ensureSymlink')
|
||||
return callback(err)
|
||||
@ -37,16 +39,16 @@ function symlinkPaths (srcpath, dstpath, callback) {
|
||||
})
|
||||
})
|
||||
} else {
|
||||
var dstdir = path.dirname(dstpath)
|
||||
var relativeToDst = path.join(dstdir, srcpath)
|
||||
return fs.exists(relativeToDst, function (exists) {
|
||||
const dstdir = path.dirname(dstpath)
|
||||
const relativeToDst = path.join(dstdir, srcpath)
|
||||
return fs.exists(relativeToDst, exists => {
|
||||
if (exists) {
|
||||
return callback(null, {
|
||||
'toCwd': relativeToDst,
|
||||
'toDst': srcpath
|
||||
})
|
||||
} else {
|
||||
return fs.lstat(srcpath, function (err, stat) {
|
||||
return fs.lstat(srcpath, (err, stat) => {
|
||||
if (err) {
|
||||
err.message = err.message.replace('lstat', 'ensureSymlink')
|
||||
return callback(err)
|
||||
@ -62,7 +64,7 @@ function symlinkPaths (srcpath, dstpath, callback) {
|
||||
}
|
||||
|
||||
function symlinkPathsSync (srcpath, dstpath) {
|
||||
var exists
|
||||
let exists
|
||||
if (path.isAbsolute(srcpath)) {
|
||||
exists = fs.existsSync(srcpath)
|
||||
if (!exists) throw new Error('absolute srcpath does not exist')
|
||||
@ -71,8 +73,8 @@ function symlinkPathsSync (srcpath, dstpath) {
|
||||
'toDst': srcpath
|
||||
}
|
||||
} else {
|
||||
var dstdir = path.dirname(dstpath)
|
||||
var relativeToDst = path.join(dstdir, srcpath)
|
||||
const dstdir = path.dirname(dstpath)
|
||||
const relativeToDst = path.join(dstdir, srcpath)
|
||||
exists = fs.existsSync(relativeToDst)
|
||||
if (exists) {
|
||||
return {
|
||||
@ -91,6 +93,6 @@ function symlinkPathsSync (srcpath, dstpath) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'symlinkPaths': symlinkPaths,
|
||||
'symlinkPathsSync': symlinkPathsSync
|
||||
symlinkPaths,
|
||||
symlinkPathsSync
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user