Showing the changes to node_modules/simple-git/src/util/exists.js (1 of 41 files). Show all
Unified · Split
| @@ -0,0 +1,33 @@ | ||
| 1 | + | |
| 2 | +var fs = require('fs'); | |
| 3 | + | |
| 4 | +function exists (path, isFile, isDirectory) { | |
| 5 | + try { | |
| 6 | + var matches = false; | |
| 7 | + var stat = fs.statSync(path); | |
| 8 | + | |
| 9 | + matches = matches || isFile && stat.isFile(); | |
| 10 | + matches = matches || isDirectory && stat.isDirectory(); | |
| 11 | + | |
| 12 | + return matches; | |
| 13 | + } | |
| 14 | + catch (e) { | |
| 15 | + if (e.code === 'ENOENT') { | |
| 16 | + return false; | |
| 17 | + } | |
| 18 | + | |
| 19 | + throw e; | |
| 20 | + } | |
| 21 | +} | |
| 22 | + | |
| 23 | +module.exports = function (path, type) { | |
| 24 | + if (!type) { | |
| 25 | + return exists(path, true, true); | |
| 26 | + } | |
| 27 | + | |
| 28 | + return exists(path, type & 1, type & 2); | |
| 29 | +}; | |
| 30 | + | |
| 31 | +module.exports.FILE = 1; | |
| 32 | + | |
| 33 | +module.exports.FOLDER = 2; | |