Browse Source

Refactor symlinkType/Sync

ci/travis-osximage
JPeer264 8 years ago
parent
commit
db665955bf
  1. 14
      lib/ensure/symlink-type.js

14
lib/ensure/symlink-type.js

@ -1,10 +1,12 @@
var fs = require('graceful-fs')
'use strict'
const fs = require('graceful-fs')
function symlinkType (srcpath, type, callback) {
callback = (typeof type === 'function') ? type : callback
type = (typeof type === 'function') ? false : type
if (type) return callback(null, type)
fs.lstat(srcpath, function (err, stats) {
fs.lstat(srcpath, (err, stats) => {
if (err) return callback(null, 'file')
type = (stats && stats.isDirectory()) ? 'dir' : 'file'
callback(null, type)
@ -12,9 +14,11 @@ function symlinkType (srcpath, type, callback) {
}
function symlinkTypeSync (srcpath, type) {
let stats
if (type) return type
try {
var stats = fs.lstatSync(srcpath)
stats = fs.lstatSync(srcpath)
} catch (e) {
return 'file'
}
@ -22,6 +26,6 @@ function symlinkTypeSync (srcpath, type) {
}
module.exports = {
symlinkType: symlinkType,
symlinkTypeSync: symlinkTypeSync
symlinkType,
symlinkTypeSync
}

Loading…
Cancel
Save