Skip to content

Commit

Permalink
Add symbolicLinkPath.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 30, 2018
1 parent a08ad2c commit 623b697
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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 },
Expand Down
17 changes: 16 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];
}
Expand Down

0 comments on commit 623b697

Please sign in to comment.