Skip to content

Commit

Permalink
Add fullpath.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 30, 2018
1 parent 2901906 commit 37af69c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ readdir('/').then((files) => {
// others: { read: true, write: false, execute: true },
// uidToName: 'root',
// path: '/var',
// fullpath: '/private/var',
// basename: 'var',
// extname: ''
// }
Expand Down Expand Up @@ -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: ''
// }
Expand Down
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
};
})
Expand Down

0 comments on commit 37af69c

Please sign in to comment.