]> git.lizzy.rs Git - rust.git/commitdiff
fs: copy: Add EPERM to fallback error conditions
authorNicolas Koch <nioko1337@gmail.com>
Fri, 1 Jun 2018 07:32:20 +0000 (09:32 +0200)
committerNicolas Koch <nioko1337@gmail.com>
Fri, 1 Jun 2018 07:32:20 +0000 (09:32 +0200)
Fixes #51266

src/libstd/sys/unix/fs.rs

index c4092dcd3889d40004c2a30284c57400dee4bd28..774340388e1db9b7fe38a3646aec42e5c8d13813 100644 (file)
@@ -890,8 +890,11 @@ unsafe fn copy_file_range(
                     )
             };
             if let Err(ref copy_err) = copy_result {
-                if let Some(libc::ENOSYS) = copy_err.raw_os_error() {
-                    HAS_COPY_FILE_RANGE.store(false, Ordering::Relaxed);
+                match copy_err.raw_os_error() {
+                    Some(libc::ENOSYS) | Some(libc::EPERM) => {
+                        HAS_COPY_FILE_RANGE.store(false, Ordering::Relaxed);
+                    }
+                    _ => {}
                 }
             }
             copy_result
@@ -902,9 +905,13 @@ unsafe fn copy_file_range(
             Ok(ret) => written += ret as u64,
             Err(err) => {
                 match err.raw_os_error() {
-                    Some(os_err) if os_err == libc::ENOSYS || os_err == libc::EXDEV => {
-                        // Either kernel is too old or the files are not mounted on the same fs.
-                        // Try again with fallback method
+                    Some(os_err) if os_err == libc::ENOSYS
+                                 || os_err == libc::EXDEV
+                                 || os_err == libc::EPERM => {
+                        // Try fallback io::copy if either:
+                        // - Kernel version is < 4.5 (ENOSYS)
+                        // - Files are mounted on different fs (EXDEV)
+                        // - copy_file_range is disallowed, for example by seccomp (EPERM)
                         assert_eq!(written, 0);
                         let ret = io::copy(&mut reader, &mut writer)?;
                         writer.set_permissions(perm)?;