Skip to content

Commit

Permalink
deps: update tempfile to 3
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Gnatenko <[email protected]>
  • Loading branch information
ignatenkobrain committed Jul 4, 2018
1 parent c62f1f8 commit 6d9e090
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 41 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ cc = "1"
bytes = "0.4.8"
lazy_static = "1"
rand = "0.4"
tempdir = "0.3"
tempfile = "2"
tempfile = "3"

[target.'cfg(target_os = "freebsd")'.dev-dependencies]
sysctl = "0.1"
Expand Down
12 changes: 6 additions & 6 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,15 @@ pub fn fchdir(dirfd: RawFd) -> Result<()> {
/// # Example
///
/// ```rust
/// extern crate tempdir;
/// extern crate tempfile;
/// extern crate nix;
///
/// use nix::unistd;
/// use nix::sys::stat;
/// use tempdir::TempDir;
/// use tempfile::TempDir;
///
/// fn main() {
/// let tmp_dir1 = TempDir::new("test_mkdir").unwrap();
/// let tmp_dir1 = TempDir::new().unwrap();
/// let tmp_dir2 = tmp_dir1.path().join("new_dir");
///
/// // create new directory and give read, write and execute rights to the owner
Expand Down Expand Up @@ -464,15 +464,15 @@ pub fn mkdir<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()> {
/// # Example
///
/// ```rust
/// extern crate tempdir;
/// extern crate tempfile;
/// extern crate nix;
///
/// use nix::unistd;
/// use nix::sys::stat;
/// use tempdir::TempDir;
/// use tempfile::TempDir;
///
/// fn main() {
/// let tmp_dir = TempDir::new("test_fifo").unwrap();
/// let tmp_dir = TempDir::new().unwrap();
/// let fifo_path = tmp_dir.path().join("foo.pipe");
///
/// // create new fifo and give read, write and execute rights to the owner
Expand Down
8 changes: 4 additions & 4 deletions test/sys/test_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ pub fn test_abstract_uds_addr() {
pub fn test_getsockname() {
use nix::sys::socket::{socket, AddressFamily, SockType, SockFlag};
use nix::sys::socket::{bind, SockAddr};
use tempdir::TempDir;
use tempfile;

let tempdir = TempDir::new("test_getsockname").unwrap();
let tempdir = tempfile::tempdir().unwrap();
let sockname = tempdir.path().join("sock");
let sock = socket(AddressFamily::Unix, SockType::Stream, SockFlag::empty(), None)
.expect("socket failed");
Expand Down Expand Up @@ -209,9 +209,9 @@ pub fn test_unixdomain() {
use nix::sys::socket::{bind, socket, connect, listen, accept, SockAddr};
use nix::unistd::{read, write, close};
use std::thread;
use tempdir::TempDir;
use tempfile;

let tempdir = TempDir::new("test_unixdomain").unwrap();
let tempdir = tempfile::tempdir().unwrap();
let sockname = tempdir.path().join("sock");
let s1 = socket(AddressFamily::Unix, SockType::Stream,
SockFlag::empty(), None).expect("socket failed");
Expand Down
9 changes: 4 additions & 5 deletions test/sys/test_uio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::{cmp, iter};
use std::fs::{OpenOptions};
use std::os::unix::io::AsRawFd;

use tempdir::TempDir;
use tempfile::tempfile;
use tempfile::{self, tempfile};

#[test]
fn test_writev() {
Expand Down Expand Up @@ -114,7 +113,7 @@ fn test_pwrite() {
fn test_pread() {
use std::io::Write;

let tempdir = TempDir::new("nix-test_pread").unwrap();
let tempdir = tempfile::tempdir().unwrap();

let path = tempdir.path().join("pread_test_file");
let mut file = OpenOptions::new().write(true).read(true).create(true)
Expand Down Expand Up @@ -142,7 +141,7 @@ fn test_pwritev() {
IoVec::from_slice(&to_write[64..128]),
];

let tempdir = TempDir::new("nix-test_pwritev").unwrap();
let tempdir = tempfile::tempdir().unwrap()

// pwritev them into a temporary file
let path = tempdir.path().join("pwritev_test_file");
Expand All @@ -166,7 +165,7 @@ fn test_preadv() {
let to_write: Vec<u8> = (0..200).collect();
let expected: Vec<u8> = (100..200).collect();

let tempdir = TempDir::new("nix-test_preadv").unwrap();
let tempdir = tempfile::tempdir().unwrap();

let path = tempdir.path().join("preadv_test_file");

Expand Down
1 change: 0 additions & 1 deletion test/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extern crate nix;
extern crate lazy_static;
extern crate libc;
extern crate rand;
extern crate tempdir;
extern crate tempfile;

mod sys;
Expand Down
7 changes: 4 additions & 3 deletions test/test_fcntl.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use nix::fcntl::{openat, open, OFlag, readlink, readlinkat};
use nix::sys::stat::Mode;
use nix::unistd::{close, read};
use tempdir::TempDir;
use tempfile::NamedTempFile;
use tempfile::{self, NamedTempFile};
use std::io::prelude::*;
use std::os::unix::fs;

Expand Down Expand Up @@ -30,7 +29,9 @@ fn test_openat() {

#[test]
fn test_readlink() {
let tempdir = TempDir::new("nix-test_readdir")
let tempdir = tempfile::Builder::new()
.prefix("nix-test_readdir")
.tempdir()
.unwrap_or_else(|e| panic!("tempdir failed: {}", e));
let src = tempdir.path().join("a");
let dst = tempdir.path().join("b");
Expand Down
24 changes: 17 additions & 7 deletions test/test_mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

extern crate libc;
extern crate nix;
extern crate tempdir;
extern crate tempfile;

#[cfg(target_os = "linux")]
mod test_mount {
Expand All @@ -23,7 +23,7 @@ mod test_mount {
use nix::sys::stat::{self, Mode};
use nix::unistd::getuid;

use tempdir::TempDir;
use tempfile;

static SCRIPT_CONTENTS: &'static [u8] = b"#!/bin/sh
exit 23";
Expand All @@ -32,7 +32,9 @@ exit 23";

const NONE: Option<&'static [u8]> = None;
pub fn test_mount_tmpfs_without_flags_allows_rwx() {
let tempdir = TempDir::new("nix-test_mount")
let tempdir = tempfile::Builder::new()
.prefix("nix-test_mount")
.tempdir()
.unwrap_or_else(|e| panic!("tempdir failed: {}", e));

mount(NONE,
Expand Down Expand Up @@ -89,7 +91,9 @@ exit 23";
}

pub fn test_mount_rdonly_disallows_write() {
let tempdir = TempDir::new("nix-test_mount")
let tempdir = tempfile::Builder::new()
.prefix("nix-test_mount")
.tempdir()
.unwrap_or_else(|e| panic!("tempdir failed: {}", e));

mount(NONE,
Expand All @@ -107,7 +111,9 @@ exit 23";
}

pub fn test_mount_noexec_disallows_exec() {
let tempdir = TempDir::new("nix-test_mount")
let tempdir = tempfile::Builder::new()
.prefix("nix-test_mount")
.tempdir()
.unwrap_or_else(|e| panic!("tempdir failed: {}", e));

mount(NONE,
Expand Down Expand Up @@ -146,12 +152,16 @@ exit 23";
}

pub fn test_mount_bind() {
let tempdir = TempDir::new("nix-test_mount")
let tempdir = tempfile::Builder::new()
.prefix("nix-test_mount")
.tempdir()
.unwrap_or_else(|e| panic!("tempdir failed: {}", e));
let file_name = "test";

{
let mount_point = TempDir::new("nix-test_mount")
let mount_point = tempfile::Builder::new()
.prefix("nix-test_mount")
.tempdir()
.unwrap_or_else(|e| panic!("tempdir failed: {}", e));

mount(Some(tempdir.path()),
Expand Down
27 changes: 21 additions & 6 deletions test/test_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use nix::sys::stat::{self, fchmod, fchmodat, fstat, lstat, stat};
use nix::sys::stat::{FileStat, Mode, FchmodatFlags};
use nix::unistd::chdir;
use nix::Result;
use tempdir::TempDir;
use tempfile;

#[allow(unused_comparisons)]
// uid and gid are signed on Windows, but not on other platforms. This function
Expand Down Expand Up @@ -56,7 +56,10 @@ fn assert_lstat_results(stat_result: Result<FileStat>) {

#[test]
fn test_stat_and_fstat() {
let tempdir = TempDir::new("nix-test_stat_and_fstat").unwrap();
let tempdir = tempfile::Builder::new()
.prefix("nix-test_stat_and_fstat")
.tempdir()
.unwrap();
let filename = tempdir.path().join("foo.txt");
let file = File::create(&filename).unwrap();

Expand All @@ -69,7 +72,10 @@ fn test_stat_and_fstat() {

#[test]
fn test_fstatat() {
let tempdir = TempDir::new("nix-test_fstatat").unwrap();
let tempdir = tempfile::Builder::new()
.prefix("nix-test_fstatat")
.tempdir()
.unwrap();
let filename = tempdir.path().join("foo.txt");
File::create(&filename).unwrap();
let dirfd = fcntl::open(tempdir.path(),
Expand All @@ -84,7 +90,10 @@ fn test_fstatat() {

#[test]
fn test_stat_fstat_lstat() {
let tempdir = TempDir::new("nix-test_stat_fstat_lstat").unwrap();
let tempdir = tempfile::Builder::new()
.prefix("nix-test_stat_fstat_lstat")
.tempdir()
.unwrap();
let filename = tempdir.path().join("bar.txt");
let linkname = tempdir.path().join("barlink");

Expand All @@ -106,7 +115,10 @@ fn test_stat_fstat_lstat() {

#[test]
fn test_fchmod() {
let tempdir = TempDir::new("nix-test_fchmod").unwrap();
let tempdir = tempfile::Builder::new()
.prefix("nix-test_fchmod")
.tempdir()
.unwrap();
let filename = tempdir.path().join("foo.txt");
let file = File::create(&filename).unwrap();

Expand All @@ -128,7 +140,10 @@ fn test_fchmod() {

#[test]
fn test_fchmodat() {
let tempdir = TempDir::new("nix-test_fchmodat").unwrap();
let tempdir = tempfile::Builder::new()
.prefix("nix-test_fchmodat")
.tempdir()
.unwrap();
let filename = "foo.txt";
let fullpath = tempdir.path().join(filename);
File::create(&fullpath).unwrap();
Expand Down
20 changes: 13 additions & 7 deletions test/test_unistd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate tempdir;

use nix::fcntl::{fcntl, FcntlArg, FdFlag, OFlag};
use nix::unistd::*;
use nix::unistd::ForkResult::*;
Expand All @@ -11,8 +9,7 @@ use std::ffi::CString;
use std::fs::File;
use std::io::Write;
use std::os::unix::prelude::*;
use tempfile::tempfile;
use tempdir::TempDir;
use tempfile::{self, tempfile};
use libc::{self, _exit, off_t};

#[test]
Expand Down Expand Up @@ -84,7 +81,10 @@ fn test_mkstemp_directory() {

#[test]
fn test_mkfifo() {
let tempdir = TempDir::new("nix-test_mkfifo").unwrap();
let tempdir = tempfile::Builder::new()
.prefix("nix-test_mkfifo")
.tempdir()
.unwrap();
let mkfifo_fifo = tempdir.path().join("mkfifo_fifo");

mkfifo(&mkfifo_fifo, Mode::S_IRUSR).unwrap();
Expand Down Expand Up @@ -286,7 +286,10 @@ fn test_fchdir() {
#[allow(unused_variables)]
let m = ::CWD_MTX.lock().expect("Mutex got poisoned by another test");

let tmpdir = TempDir::new("test_fchdir").unwrap();
let tmpdir = tempfile::Builder::new()
.prefix("test_fchdir")
.tempdir()
.unwrap();
let tmpdir_path = tmpdir.path().canonicalize().unwrap();
let tmpdir_fd = File::open(&tmpdir_path).unwrap().into_raw_fd();

Expand All @@ -302,7 +305,10 @@ fn test_getcwd() {
#[allow(unused_variables)]
let m = ::CWD_MTX.lock().expect("Mutex got poisoned by another test");

let tmpdir = TempDir::new("test_getcwd").unwrap();
let tmpdir = tempfile::Builder::new()
.prefix("test_getcwd")
.tempdir()
.unwrap();
let tmpdir_path = tmpdir.path().canonicalize().unwrap();
assert!(chdir(&tmpdir_path).is_ok());
assert_eq!(getcwd().unwrap(), tmpdir_path);
Expand Down

0 comments on commit 6d9e090

Please sign in to comment.