summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAxetroy <troy450409405@gmail.com>2019-03-19 00:34:54 +0800
committerRyan Dahl <ry@tinyclouds.org>2019-03-18 12:34:54 -0400
commite12d5521bf80396d0782f9ad3f1d162a88adadaa (patch)
tree69bb94a32f9499ed66d4c725a44edb47045198c7
parent2e1ed890b85d4ecf1a6332cf2e0c121d5640b496 (diff)
fix: fs.exists not work for symlink (denoland/deno_std#291)
Original: https://github.com/denoland/deno_std/commit/264a51c093e00f3538f735ce8f0c25d20471a33d
-rw-r--r--fs/exists.ts4
-rw-r--r--fs/exists_test.ts10
l---------fs/testdata/0-link.ts1
3 files changed, 13 insertions, 2 deletions
diff --git a/fs/exists.ts b/fs/exists.ts
index 41961a0f2..ce4b83a4c 100644
--- a/fs/exists.ts
+++ b/fs/exists.ts
@@ -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;
diff --git a/fs/exists_test.ts b/fs/exists_test.ts
index 3d781108e..1e94c7f69 100644
--- a/fs/exists_test.ts
+++ b/fs/exists_test.ts
@@ -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);
+});
diff --git a/fs/testdata/0-link.ts b/fs/testdata/0-link.ts
new file mode 120000
index 000000000..24c6b8053
--- /dev/null
+++ b/fs/testdata/0-link.ts
@@ -0,0 +1 @@
+./fs/testdata/0.ts \ No newline at end of file