From 04f5efa80b5fd278203908e9fa6ff3f36194a6d3 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Sun, 1 Jul 2018 00:38:49 +0800 Subject: [PATCH] Add isSymbolicLinkDir & isSymbolicLinkFile --- README.md | 5 +++++ index.js | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bd562c4..9c973a5 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ readdir('/').then((files) => { // modeNum: 41453, // modeStr: 'lrwxr-xr-x', // isSymbolicLink: true, + // isSymbolicLinkDir: true, + // isSymbolicLinkFile: false, // symbolicLinkPath: 'private/var', // owner: { read: true, write: true, execute: true }, // group: { read: true, write: false, execute: true }, @@ -68,6 +70,7 @@ const { getStat } = require('reader-stat'); getStat('/var').then((Stats) => { console.log('Stats', Stats.isDirectory()); + console.log('Stats', Stats.isFile()); // output => true console.log('Stats', Stats); // output => @@ -94,6 +97,8 @@ getStat('/var').then((Stats) => { // modeNum: 41453, // modeStr: 'lrwxr-xr-x', // isSymbolicLink: true, + // isSymbolicLinkDir: true, + // isSymbolicLinkFile: false, // symbolicLinkPath: 'private/var', // owner: { read: true, write: true, execute: true }, // group: { read: true, write: false, execute: true }, diff --git a/index.js b/index.js index f10b44b..b5e5b47 100644 --- a/index.js +++ b/index.js @@ -32,7 +32,14 @@ exports.getStat = async (currentPath, names) => { } if (mode.isSymbolicLink()) { const link = await this.readLink(currentPath); - if (link) stat.extend.symbolicLinkPath = link; + if (link) { + stat.extend.symbolicLinkPath = link; + const linkStat = await this.getStat(/^\//.test(link) ? link : path.join(path.dirname(currentPath), link)); + if (linkStat) { + stat.extend.isSymbolicLinkDir = linkStat.isDirectory(); + stat.extend.isSymbolicLinkFile = linkStat.isFile(); + } + } } if (names && names[stat.uid]) { stat.extend.uidToName = names[stat.uid];