summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJinho Bang <zino@chromium.org>2018-10-17 14:40:03 +0900
committerRyan Dahl <ry@tinyclouds.org>2018-10-17 08:24:31 -0400
commit32f07971284f05993cf702aa589859e7900406b4 (patch)
tree99c900df9df6fd8c60e8d2595e45a3818133f2dd
parentd4afbe6ef3206e53e2ddc7f59c6b90bbffcbe988 (diff)
Fix a bug that copyFile reports different error codes
This is a workaroud. Once the issue is resolved in Rust side, we should remove it. Fixes #895
-rw-r--r--js/copy_file_test.ts22
-rw-r--r--src/ops.rs10
2 files changed, 14 insertions, 18 deletions
diff --git a/js/copy_file_test.ts b/js/copy_file_test.ts
index 695d9b8c9..05f0a6f71 100644
--- a/js/copy_file_test.ts
+++ b/js/copy_file_test.ts
@@ -43,15 +43,8 @@ testPerm({ write: true }, function copyFileSyncFailure() {
err = e;
}
assert(!!err);
- if (deno.platform.os === "win") {
- assertEqual(err.kind, deno.ErrorKind.NotFound);
- assertEqual(err.name, "NotFound");
- } else {
- // On *nix, Rust deem non-existent path as invalid input
- // See https://github.com/rust-lang/rust/issues/54800
- assertEqual(err.kind, deno.ErrorKind.InvalidInput);
- assertEqual(err.name, "InvalidInput");
- }
+ assertEqual(err.kind, deno.ErrorKind.NotFound);
+ assertEqual(err.name, "NotFound");
});
testPerm({ write: true }, function copyFileSyncOverwrite() {
@@ -104,15 +97,8 @@ testPerm({ write: true }, async function copyFileFailure() {
err = e;
}
assert(!!err);
- if (deno.platform.os === "win") {
- assertEqual(err.kind, deno.ErrorKind.NotFound);
- assertEqual(err.name, "NotFound");
- } else {
- // On *nix, Rust deem non-existent path as invalid input
- // See https://github.com/rust-lang/rust/issues/54800
- assertEqual(err.kind, deno.ErrorKind.InvalidInput);
- assertEqual(err.name, "InvalidInput");
- }
+ assertEqual(err.kind, deno.ErrorKind.NotFound);
+ assertEqual(err.name, "NotFound");
});
testPerm({ write: true }, async function copyFileOverwrite() {
diff --git a/src/ops.rs b/src/ops.rs
index 53ed85b7f..d786dfa41 100644
--- a/src/ops.rs
+++ b/src/ops.rs
@@ -811,6 +811,16 @@ fn op_copy_file(
debug!("op_copy_file {} {}", from.display(), to.display());
blocking!(base.sync(), || {
+ // On *nix, Rust deem non-existent path as invalid input
+ // See https://github.com/rust-lang/rust/issues/54800
+ // Once the issue is reolved, we should remove this workaround.
+ if cfg!(unix) && !from.is_file() {
+ return Err(errors::new(
+ ErrorKind::NotFound,
+ "File not found".to_string(),
+ ));
+ }
+
fs::copy(&from, &to)?;
Ok(empty_buf())
})