diff --git a/README.md b/README.md index 8a42c4a..bd562c4 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ readdir('/').then((files) => { // modeNum: 41453, // modeStr: 'lrwxr-xr-x', // isSymbolicLink: true, + // symbolicLinkPath: 'private/var', // owner: { read: true, write: true, execute: true }, // group: { read: true, write: false, execute: true }, // others: { read: true, write: false, execute: true }, @@ -93,6 +94,7 @@ getStat('/var').then((Stats) => { // modeNum: 41453, // modeStr: 'lrwxr-xr-x', // isSymbolicLink: true, + // symbolicLinkPath: 'private/var', // owner: { read: true, write: true, execute: true }, // group: { read: true, write: false, execute: true }, // others: { read: true, write: false, execute: true }, diff --git a/index.js b/index.js index 49337a8..f10b44b 100644 --- a/index.js +++ b/index.js @@ -4,10 +4,21 @@ const nicki = require('nicki'); const Mode = require('stat-mode'); const deepExtend = require('deep-extend'); +exports.readLink = (currentPath) => { + return new Promise((resolve, reject) => { + fs.readlink(currentPath, (err, stat) => { + if (err) reject(err); + else { + resolve(stat); + } + }) + }); +} + exports.getStat = async (currentPath, names) => { if (!names) names = await this.uidToName(); return new Promise((resolve, reject) => { - fs.lstat(currentPath, (err, stat) => { + fs.lstat(currentPath, async (err, stat) => { if (err) reject(err); else { const mode = new Mode(stat); @@ -19,6 +30,10 @@ exports.getStat = async (currentPath, names) => { group: { ...mode.group }, others: { ...mode.others }, } + if (mode.isSymbolicLink()) { + const link = await this.readLink(currentPath); + if (link) stat.extend.symbolicLinkPath = link; + } if (names && names[stat.uid]) { stat.extend.uidToName = names[stat.uid]; }