81e35884d81d1e219eccae731886ea92710f836a
[yaffs-website] / node_modules / fs-extra / lib / ensure / symlink-type.js
1 var fs = require('graceful-fs')
2
3 function symlinkType (srcpath, type, callback) {
4   callback = (typeof type === 'function') ? type : callback
5   type = (typeof type === 'function') ? false : type
6   if (type) return callback(null, type)
7   fs.lstat(srcpath, function (err, stats) {
8     if (err) return callback(null, 'file')
9     type = (stats && stats.isDirectory()) ? 'dir' : 'file'
10     callback(null, type)
11   })
12 }
13
14 function symlinkTypeSync (srcpath, type) {
15   if (type) return type
16   try {
17     var stats = fs.lstatSync(srcpath)
18   } catch (e) {
19     return 'file'
20   }
21   return (stats && stats.isDirectory()) ? 'dir' : 'file'
22 }
23
24 module.exports = {
25   symlinkType: symlinkType,
26   symlinkTypeSync: symlinkTypeSync
27 }