Skip to content

Commit

Permalink
fixup! fs: introduce dirent.parentPath
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Dec 3, 2023
1 parent b44b3de commit 181eca5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ function readdirSyncRecursive(basePath, options) {
const dirent = getDirent(path, readdirResult[0][i], readdirResult[1][i]);
ArrayPrototypePush(readdirResults, dirent);
if (dirent.isDirectory()) {
ArrayPrototypePush(pathsQueue, pathModule.join(dirent.parentPath, dirent.name));
ArrayPrototypePush(pathsQueue, pathModule.join(dirent.path, dirent.name));
}
}
} else {
Expand Down
16 changes: 8 additions & 8 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ function assertEncoding(encoding) {
}

class Dirent {
constructor(name, type, path) {
constructor(name, type, path, filepath = path && join(path, name)) {
this.name = name;
this.parentPath = path;
this.path = pathModule.join(path, name);
this.path = filepath;
this[kType] = type;
}

Expand Down Expand Up @@ -198,8 +198,8 @@ class Dirent {
}

class DirentFromStats extends Dirent {
constructor(name, stats, path) {
super(name, null, path);
constructor(name, stats, path, filepath) {
super(name, null, path, filepath);
this[kStats] = stats;
}
}
Expand Down Expand Up @@ -234,7 +234,7 @@ function join(path, name) {
}

if (typeof path === 'string' && typeof name === 'string') {
return pathModule.join(path, name);
return pathModule.basename(path) === name ? path : pathModule.join(path, name);
}

if (isUint8Array(path) && isUint8Array(name)) {
Expand Down Expand Up @@ -269,7 +269,7 @@ function getDirents(path, { 0: names, 1: types }, callback) {
callback(err);
return;
}
names[idx] = new DirentFromStats(name, stats, path);
names[idx] = new DirentFromStats(name, stats, path, filepath);
if (--toFinish === 0) {
callback(null, names);
}
Expand Down Expand Up @@ -305,15 +305,15 @@ function getDirent(path, name, type, callback) {
callback(err);
return;
}
callback(null, new DirentFromStats(name, stats, filepath));
callback(null, new DirentFromStats(name, stats, path, filepath));
});
} else {
callback(null, new Dirent(name, type, path));
}
} else if (type === UV_DIRENT_UNKNOWN) {
const filepath = join(path, name);
const stats = lazyLoadFs().lstatSync(filepath);
return new DirentFromStats(name, stats, path);
return new DirentFromStats(name, stats, path, filepath);
} else {
return new Dirent(name, type, path);
}
Expand Down

0 comments on commit 181eca5

Please sign in to comment.