1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-01 16:51:13 -05:00

fix: fs.exists not work for symlink (denoland/deno_std#291)

Original: 264a51c093
This commit is contained in:
Axetroy 2019-03-19 00:34:54 +08:00 committed by Ryan Dahl
parent 2e1ed890b8
commit e12d5521bf
3 changed files with 13 additions and 2 deletions

View file

@ -2,7 +2,7 @@
/** Test whether or not the given path exists by checking with the file system */ /** Test whether or not the given path exists by checking with the file system */
export async function exists(filePath: string): Promise<boolean> { export async function exists(filePath: string): Promise<boolean> {
return Deno.stat(filePath) return Deno.lstat(filePath)
.then(() => true) .then(() => true)
.catch(() => false); .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 */ /** Test whether or not the given path exists by checking with the file system */
export function existsSync(filePath: string): boolean { export function existsSync(filePath: string): boolean {
try { try {
Deno.statSync(filePath); Deno.lstatSync(filePath);
return true; return true;
} catch { } catch {
return false; return false;

View file

@ -34,3 +34,13 @@ test(function existsDirectorySync() {
); );
assertEquals(existsSync(testdataDir), true); 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
View file

@ -0,0 +1 @@
./fs/testdata/0.ts