Newer
Older
CVSS_3.0_GUI / node_modules / nwjs-builder-phoenix / node_modules / fs-extra / lib / ensure / symlink-type.js
root on 7 May 2019 698 bytes Initial commit
  1. 'use strict'
  2.  
  3. const fs = require('graceful-fs')
  4.  
  5. function symlinkType (srcpath, type, callback) {
  6. callback = (typeof type === 'function') ? type : callback
  7. type = (typeof type === 'function') ? false : type
  8. if (type) return callback(null, type)
  9. fs.lstat(srcpath, (err, stats) => {
  10. if (err) return callback(null, 'file')
  11. type = (stats && stats.isDirectory()) ? 'dir' : 'file'
  12. callback(null, type)
  13. })
  14. }
  15.  
  16. function symlinkTypeSync (srcpath, type) {
  17. let stats
  18.  
  19. if (type) return type
  20. try {
  21. stats = fs.lstatSync(srcpath)
  22. } catch (e) {
  23. return 'file'
  24. }
  25. return (stats && stats.isDirectory()) ? 'dir' : 'file'
  26. }
  27.  
  28. module.exports = {
  29. symlinkType,
  30. symlinkTypeSync
  31. }
Buy Me A Coffee