-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds implementation of copy_file_range() #1008
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,15 +49,49 @@ fn test_readlink() { | |
mod linux_android { | ||
use std::io::prelude::*; | ||
use std::os::unix::prelude::*; | ||
use std::io::SeekFrom; | ||
|
||
use libc::loff_t; | ||
|
||
use nix::fcntl::{SpliceFFlags, FallocateFlags, fallocate, splice, tee, vmsplice}; | ||
use nix::fcntl::{SpliceFFlags, FallocateFlags, fallocate, splice, tee, vmsplice, copy_file_range}; | ||
use nix::sys::uio::IoVec; | ||
use nix::unistd::{close, pipe, read, write}; | ||
|
||
use tempfile::{tempfile, NamedTempFile}; | ||
|
||
/// This test creates a temporary file containing the contents | ||
/// 'foobarbaz' and uses the `copy_file_range` call to transfer | ||
/// 3 bytes at offset 3 (`bar`) to another empty file at offset 0. The | ||
/// resulting file is read and should contain the contents `bar`. | ||
/// The from_offset should be updated by the call to reflect | ||
/// the 3 bytes read (6). | ||
/// | ||
/// Fix me: test is disabled for linux based builds, because Jenkins | ||
/// Linux version is too old for `copy_file_range`. Should work | ||
/// on netbsd build. | ||
#[test] | ||
#[cfg_attr(target_env = "linux", ignore)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linux is a target_os, not a target_env. Also, you should leave a message with the ignore attribute. And it's not going to work on a "netbsd build", because NetBSD doesn't have this syscall at all. Finally, we use Travis, not Jenkins. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anything else that is holding this PR back? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. The OP needs to address my last comments, fix the CI failures, and rebase. |
||
fn test_copy_file_range() { | ||
const CONTENTS: &[u8] = b"foobarbaz"; | ||
|
||
let mut tmp1 = tempfile().unwrap(); | ||
let mut tmp2 = tempfile().unwrap(); | ||
|
||
tmp1.write_all(CONTENTS).unwrap(); | ||
tmp1.flush().unwrap(); | ||
|
||
let mut from_offset: i64 = 3; | ||
copy_file_range(tmp1.as_raw_fd(), Some(&mut from_offset), | ||
tmp2.as_raw_fd(), None, 3).unwrap(); | ||
|
||
let mut res: String = String::new(); | ||
tmp2.seek(SeekFrom::Start(0)).unwrap(); | ||
tmp2.read_to_string(&mut res).unwrap(); | ||
|
||
assert_eq!(res, String::from("bar")); | ||
assert_eq!(from_offset, 6); | ||
} | ||
|
||
#[test] | ||
fn test_splice() { | ||
const CONTENTS: &[u8] = b"abcdef123456"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the last argument be
flags
instead of 0?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (flags removed)