Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

symlink-type.js 698B

12345678910111213141516171819202122232425262728293031
  1. 'use strict'
  2. const fs = require('graceful-fs')
  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, (err, stats) => {
  8. if (err) return callback(null, 'file')
  9. type = (stats && stats.isDirectory()) ? 'dir' : 'file'
  10. callback(null, type)
  11. })
  12. }
  13. function symlinkTypeSync (srcpath, type) {
  14. let stats
  15. if (type) return type
  16. try {
  17. stats = fs.lstatSync(srcpath)
  18. } catch (e) {
  19. return 'file'
  20. }
  21. return (stats && stats.isDirectory()) ? 'dir' : 'file'
  22. }
  23. module.exports = {
  24. symlinkType,
  25. symlinkTypeSync
  26. }