Skip to content

Commit

Permalink
fix: file symlink path shouldn't end with slash
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed Aug 25, 2024
1 parent 646e47c commit 8e3976b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion __tests__/fdir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ for (const type of apiTypes) {

const files = await api[type]();
t.expect(
files.indexOf(resolveSymlinkRoot("/some/dir/fileSymlink/")) > -1
files.indexOf(resolveSymlinkRoot("/some/dir/fileSymlink")) > -1
).toBeTruthy();

mock.restore();
Expand Down
20 changes: 9 additions & 11 deletions src/api/functions/resolve-symlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type ResolveSymlinkFunction = (
callback: (stat: fs.Stats, path: string) => void
) => void;

const resolveSymlinksAsync: ResolveSymlinkFunction = function(
const resolveSymlinksAsync: ResolveSymlinkFunction = function (
path,
state,
callback
Expand All @@ -24,12 +24,12 @@ const resolveSymlinksAsync: ResolveSymlinkFunction = function(
return;
}

callback(stat, path);
queue.dequeue(null, state);
callback(stat, path);
queue.dequeue(null, state);
});
};

const resolveSymlinksWithRealPathsAsync: ResolveSymlinkFunction = function(
const resolveSymlinksWithRealPathsAsync: ResolveSymlinkFunction = function (
path,
state,
callback
Expand All @@ -54,7 +54,7 @@ const resolveSymlinksWithRealPathsAsync: ResolveSymlinkFunction = function(
});
};

const resolveSymlinksSync: ResolveSymlinkFunction = function(
const resolveSymlinksSync: ResolveSymlinkFunction = function (
path,
state,
callback
Expand All @@ -67,7 +67,7 @@ const resolveSymlinksSync: ResolveSymlinkFunction = function(
}
};

const resolveSymlinksWithRealPathsSync: ResolveSymlinkFunction = function(
const resolveSymlinksWithRealPathsSync: ResolveSymlinkFunction = function (
path,
state,
callback
Expand All @@ -89,9 +89,7 @@ export function build(

if (options.useRealPaths)
return isSynchronous
? resolveSymlinksWithRealPathsSync
: resolveSymlinksWithRealPathsAsync;
return isSynchronous
? resolveSymlinksSync
: resolveSymlinksAsync;
? resolveSymlinksWithRealPathsSync
: resolveSymlinksWithRealPathsAsync;
return isSynchronous ? resolveSymlinksSync : resolveSymlinksAsync;
}
6 changes: 1 addition & 5 deletions src/api/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ export class Walker<TOutput extends Output> {
if (exclude && exclude(entry.name, path)) continue;
this.walkDirectory(this.state, path, depth - 1, this.walk);
} else if (entry.isSymbolicLink() && resolveSymlinks) {
let path = joinPath.joinDirectoryPath(
entry.name,
directoryPath,
this.state.options.pathSeparator
);
let path = this.joinPath(entry.name, directoryPath);
this.resolveSymlink!(path, this.state, (stat, resolvedPath) => {
if (stat.isDirectory()) {
resolvedPath = this.normalizePath(resolvedPath);
Expand Down

0 comments on commit 8e3976b

Please sign in to comment.