Debian Codegraph @

fs2/lstat.js

raw
1 "use strict";
2
3 var isCallable = require("es5-ext/object/is-callable")
4 , isValue = require("es5-ext/object/is-value")
5 , deferred = require("deferred")
6 , resolve = require("path").resolve
7 , original = require("fs").lstat;
8
9 var lstat = function (path, options) {
10 var def = deferred();
11 original(path, function (err, stats) {
12 if (err) {
13 if (options.loose && (err.code === "ENOENT" || err.code === "ENOTDIR")) {
14 def.resolve(null);
15 } else {
16 def.reject(err);
17 }
18 } else {
19 def.resolve(stats);
20 }
21 });
22 return def.promise;
23 };
24 lstat.returnsPromise = true;
25
26 module.exports = function (path/*, callback*/) {
27 var options, cb;
28
29 path = resolve(String(path));
30 options = arguments[1];
31 cb = arguments[2];
32 if (!isValue(cb) && isCallable(options)) {
33 cb = options;
34 options = {};
35 } else {
36 options = Object(options);
37 }
38
39 return lstat(path, options).cb(cb);
40 };
41 module.exports.returnsPromise = true;
42 module.exports.lstat = lstat;