summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-02-15 09:45:45 +0100
committerGitHub <noreply@github.com>2020-02-15 09:45:45 +0100
commit728be34ebc716aa90cc525b42282d6c9f461b67b (patch)
treeb9b6cacd2e1e035bd534c76392262ef83ef4596e
parentRollup merge of #66721 - maxbla:exp-format-integers, r=KodrAus (diff)
parentFix std::fs::copy on WASI target (diff)
downloadrust-728be34ebc716aa90cc525b42282d6c9f461b67b.tar.gz
rust-728be34ebc716aa90cc525b42282d6c9f461b67b.tar.bz2
rust-728be34ebc716aa90cc525b42282d6c9f461b67b.tar.xz
Rollup merge of #69106 - RReverser:wasi-fs-copy, r=KodrAus
Fix std::fs::copy on WASI target Previously `std::fs::copy` on wasm32-wasi would reuse code from the `sys_common` module and would successfully copy contents of the file just to fail right before closing it. This was happening because `sys_common::copy` tries to copy permissions of the file, but permissions are not a thing in WASI (at least yet) and `set_permissions` is implemented as an unconditional runtime error. This change instead adds a custom working implementation of `std::fs::copy` (like Rust already has on some other targets) that doesn't try to call `set_permissions` and is essentially a thin wrapper around `std::io::copy`. Fixes #68560.
-rw-r--r--src/libstd/sys/wasi/fs.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/libstd/sys/wasi/fs.rs b/src/libstd/sys/wasi/fs.rs
index 04bfdf6..a11f61f 100644
--- a/src/libstd/sys/wasi/fs.rs
+++ b/src/libstd/sys/wasi/fs.rs
@@ -12,7 +12,6 @@ use crate::sys::time::SystemTime;
12use crate::sys::unsupported; 12use crate::sys::unsupported;
13use crate::sys_common::FromInner; 13use crate::sys_common::FromInner;
14 14
15pub use crate::sys_common::fs::copy;
16pub use crate::sys_common::fs::remove_dir_all; 15pub use crate::sys_common::fs::remove_dir_all;
17 16
18pub struct File { 17pub struct File {
@@ -647,3 +646,12 @@ fn open_parent(p: &Path) -> io::Result<(ManuallyDrop<WasiFd>, PathBuf)> {
647pub fn osstr2str(f: &OsStr) -> io::Result<&str> { 646pub fn osstr2str(f: &OsStr) -> io::Result<&str> {
648 f.to_str().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "input must be utf-8")) 647 f.to_str().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "input must be utf-8"))
649} 648}
649
650pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
651 use crate::fs::File;
652
653 let mut reader = File::open(from)?;
654 let mut writer = File::create(to)?;
655
656 io::copy(&mut reader, &mut writer)
657}