Skip to content

Commit

Permalink
Add isSymbolicLinkDir & isSymbolicLinkFile
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 30, 2018
1 parent 2ba590d commit 04f5efa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 =>
Expand All @@ -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 },
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 04f5efa

Please sign in to comment.