mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
fix: fs.exists not work for symlink (denoland/deno_std#291)
Original: 264a51c093
This commit is contained in:
parent
2e1ed890b8
commit
e12d5521bf
3 changed files with 13 additions and 2 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
/** Test whether or not the given path exists by checking with the file system */
|
||||
export async function exists(filePath: string): Promise<boolean> {
|
||||
return Deno.stat(filePath)
|
||||
return Deno.lstat(filePath)
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ export async function exists(filePath: string): Promise<boolean> {
|
|||
/** Test whether or not the given path exists by checking with the file system */
|
||||
export function existsSync(filePath: string): boolean {
|
||||
try {
|
||||
Deno.statSync(filePath);
|
||||
Deno.lstatSync(filePath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
|
|
|
@ -34,3 +34,13 @@ test(function existsDirectorySync() {
|
|||
);
|
||||
assertEquals(existsSync(testdataDir), true);
|
||||
});
|
||||
|
||||
test(function existsLinkSync() {
|
||||
// TODO(axetroy): generate link file use Deno api instead of set a link file in repository
|
||||
assertEquals(existsSync(path.join(testdataDir, "0-link.ts")), true);
|
||||
});
|
||||
|
||||
test(async function existsLink() {
|
||||
// TODO(axetroy): generate link file use Deno api instead of set a link file in repository
|
||||
assertEquals(await exists(path.join(testdataDir, "0-link.ts")), true);
|
||||
});
|
||||
|
|
1
fs/testdata/0-link.ts
vendored
Symbolic link
1
fs/testdata/0-link.ts
vendored
Symbolic link
|
@ -0,0 +1 @@
|
|||
./fs/testdata/0.ts
|
Loading…
Reference in a new issue