diff options
author | 木杉 <zhmushan@qq.com> | 2019-12-02 03:23:35 +0800 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-12-01 11:23:35 -0800 |
commit | 537c6b3ed9a783b64bec0d41260c13ac84b7feb6 (patch) | |
tree | 89517c6e42cf2a585c837b19939b59291874c98e | |
parent | 81efa9d938aa169d16e67762d336d75738375cd6 (diff) |
fix realpath behavior in windows (#3425)
-rw-r--r-- | cli/js/realpath_test.ts | 12 | ||||
-rw-r--r-- | cli/ops/fs.rs | 6 |
2 files changed, 15 insertions, 3 deletions
diff --git a/cli/js/realpath_test.ts b/cli/js/realpath_test.ts index 1dc976578..1faac94cc 100644 --- a/cli/js/realpath_test.ts +++ b/cli/js/realpath_test.ts @@ -4,7 +4,11 @@ import { testPerm, assert, assertEquals } from "./test_util.ts"; testPerm({ read: true }, function realpathSyncSuccess(): void { const incompletePath = "cli/tests/fixture.json"; const realPath = Deno.realpathSync(incompletePath); - assert(realPath.startsWith("/")); + if (Deno.build.os !== "win") { + assert(realPath.startsWith("/")); + } else { + assert(/^[A-Z]/.test(realPath)); + } assert(realPath.endsWith(incompletePath)); }); @@ -47,7 +51,11 @@ testPerm({ read: true }, function realpathSyncNotFound(): void { testPerm({ read: true }, async function realpathSuccess(): Promise<void> { const incompletePath = "cli/tests/fixture.json"; const realPath = await Deno.realpath(incompletePath); - assert(realPath.startsWith("/")); + if (Deno.build.os !== "win") { + assert(realPath.startsWith("/")); + } else { + assert(/^[A-Z]/.test(realPath)); + } assert(realPath.endsWith(incompletePath)); }); diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs index 54ac1971b..c847931ab 100644 --- a/cli/ops/fs.rs +++ b/cli/ops/fs.rs @@ -300,7 +300,11 @@ fn op_realpath( // corresponds to the realpath on Unix and // CreateFile and GetFinalPathNameByHandle on Windows let realpath = fs::canonicalize(&path)?; - let realpath_str = realpath.to_str().unwrap().to_owned().replace("\\", "/"); + let mut realpath_str = + realpath.to_str().unwrap().to_owned().replace("\\", "/"); + if cfg!(windows) { + realpath_str = realpath_str.trim_start_matches("//?/").to_string(); + } Ok(json!(realpath_str)) }) } |