Skip to content

Commit

Permalink
Implement unlinkat - Update error handling to use unwrap_err
Browse files Browse the repository at this point in the history
The previous patch failed testing on two targets that returned EPERM
as the Sys error instead of EISDIR. This patch changes from using the
should_panic attribute to using the unwrap_err and matching against
the result.
  • Loading branch information
jlb6740 committed Jun 25, 2019
1 parent 94fe4b0 commit 8d7467e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Add `sched_yield`
([#1050](https://github.com/nix-rust/nix/pull/1050))
- Add `unlinkat`
([#TBD](https://github.com/nix-rust/nix/pull/1058))
([#1058](https://github.com/nix-rust/nix/pull/1058))

### Changed
- `PollFd` event flags renamed to `PollFlags` ([#1024](https://github.com/nix-rust/nix/pull/1024/))
Expand Down
10 changes: 7 additions & 3 deletions test/test_unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use nix::sys::signal::{SaFlags, SigAction, SigHandler, SigSet, Signal, sigaction
use nix::sys::wait::*;
use nix::sys::stat::{self, Mode, SFlag};
use nix::errno::Errno;
use nix::Error;
use std::{env, iter};
use std::ffi::CString;
use std::fs::{self, DirBuilder, File};
use std::io::Write;
use std::os::unix::prelude::*;
use std::panic;
use tempfile::{self, tempfile};
use libc::{self, _exit, off_t};

Expand Down Expand Up @@ -602,7 +602,6 @@ fn test_symlinkat() {


#[test]
#[should_panic (expected="`Err` value: Sys(EISDIR)")]
fn test_unlinkat_dir_noremovedir() {
let tempdir = tempfile::tempdir().unwrap();
let dirname = "foo_dir";
Expand All @@ -615,7 +614,12 @@ fn test_unlinkat_dir_noremovedir() {
let dirfd = fcntl::open(tempdir.path(), fcntl::OFlag::empty(), stat::Mode::empty()).unwrap();

// Attempt unlink dir at relative path without proper flag
unlinkat(Some(dirfd), dirname, UnlinkatFlags::NoRemoveDir).unwrap();
let err_result = unlinkat(Some(dirfd), dirname, UnlinkatFlags::NoRemoveDir).unwrap_err();
match err_result {
Error::Sys(Errno::EISDIR) => println!("{}", err_result),
Error::Sys(Errno::EPERM) => println!("{}", err_result),
_ => panic!("Unlinkat did not fail as expected: {}", err_result),
}
}

#[test]
Expand Down

0 comments on commit 8d7467e

Please sign in to comment.