mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
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
This commit is contained in:
parent
d4afbe6ef3
commit
32f0797128
2 changed files with 14 additions and 18 deletions
|
@ -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() {
|
||||
|
|
10
src/ops.rs
10
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())
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue