diff --git a/README.md b/README.md index 9c973a5..7301e2b 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ readdir('/').then((files) => { // others: { read: true, write: false, execute: true }, // uidToName: 'root', // path: '/var', + // fullpath: '/private/var', // basename: 'var', // extname: '' // } @@ -105,6 +106,7 @@ getStat('/var').then((Stats) => { // others: { read: true, write: false, execute: true }, // uidToName: 'root', // path: '/var', + // fullpath: '/private/var', // basename: 'var', // extname: '' // } diff --git a/index.js b/index.js index b5e5b47..76e5fc1 100644 --- a/index.js +++ b/index.js @@ -30,11 +30,17 @@ exports.getStat = async (currentPath, names) => { group: { ...mode.group }, others: { ...mode.others }, } + stat.extend.path = currentPath; + stat.extend.fullpath = currentPath; + stat.extend.basename = path.basename(currentPath); + stat.extend.extname = path.extname(stat.extend.basename); if (mode.isSymbolicLink()) { const link = await this.readLink(currentPath); if (link) { stat.extend.symbolicLinkPath = link; - const linkStat = await this.getStat(/^\//.test(link) ? link : path.join(path.dirname(currentPath), link)); + const fullpath = /^\//.test(link) ? link : path.join(path.dirname(currentPath), link) + const linkStat = await this.getStat(fullpath); + stat.extend.fullpath = fullpath; if (linkStat) { stat.extend.isSymbolicLinkDir = linkStat.isDirectory(); stat.extend.isSymbolicLinkFile = linkStat.isFile(); @@ -44,9 +50,6 @@ exports.getStat = async (currentPath, names) => { if (names && names[stat.uid]) { stat.extend.uidToName = names[stat.uid]; } - stat.extend.path = currentPath; - stat.extend.basename = path.basename(currentPath); - stat.extend.extname = path.extname(stat.extend.basename); resolve(stat); }; })