1'use strict' 2var fs = require('fs') 3var inflight = require('inflight') 4var accessError = require('./access-error.js') 5var isFsAccessAvailable = require('./is-fs-access-available.js') 6 7if (isFsAccessAvailable) { 8 module.exports = fsAccessImplementation 9} else { 10 module.exports = fsStatImplementation 11} 12 13// exposed only for testing purposes 14module.exports.fsAccessImplementation = fsAccessImplementation 15module.exports.fsStatImplementation = fsStatImplementation 16 17function fsAccessImplementation (dir, done) { 18 done = inflight('exists:' + dir, done) 19 if (!done) return 20 fs.access(dir, fs.F_OK, done) 21} 22 23function fsStatImplementation (dir, done) { 24 done = inflight('exists:' + dir, done) 25 if (!done) return 26 fs.stat(dir, function (er) { done(accessError(dir, er)) }) 27} 28