validLink.js 514 B

123456789101112131415161718192021222324
  1. var Q = require('q');
  2. var fs = require('graceful-fs');
  3. function validLink(file) {
  4. // Ensures that a file is a symlink that points
  5. // to a valid file
  6. return Q.nfcall(fs.lstat, file)
  7. .then(function (lstat) {
  8. if (!lstat.isSymbolicLink()) {
  9. return [false];
  10. }
  11. return Q.nfcall(fs.stat, file)
  12. .then(function (stat) {
  13. return [stat];
  14. });
  15. })
  16. .fail(function (err) {
  17. return [false, err];
  18. });
  19. }
  20. module.exports = validLink;