-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update error code for fs ops in isolation
Change the code to either `EACCES` (if the op is performed on the path), or `EBADF` (if the op is performed the fd) Updated ops: `stat`, `opendir`, `ftruncate64`, and `readlink` Add a new test for fs ops in isolation.
- Loading branch information
Showing
3 changed files
with
100 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// ignore-windows: File handling is not implemented yet | ||
// compile-flags: -Zmiri-isolation-error=warn-nobacktrace | ||
// normalize-stderr-test "(stat|statx)" -> "$$STAT" | ||
|
||
#![feature(rustc_private)] | ||
|
||
extern crate libc; | ||
|
||
use std::ffi::CString; | ||
use std::os::unix; | ||
use std::fs::{self, File}; | ||
use std::io::{Error, ErrorKind}; | ||
|
||
fn main() { | ||
// test `open` | ||
assert_eq!(File::create("foo.txt").unwrap_err().kind(), ErrorKind::PermissionDenied); | ||
|
||
// test `fcntl` | ||
unsafe { | ||
assert_eq!(libc::fcntl(1, libc::F_DUPFD, 0), -1); | ||
assert_eq!(Error::last_os_error().raw_os_error(), Some(libc::EPERM)); | ||
} | ||
|
||
// test `unlink` | ||
assert_eq!(fs::remove_file("foo.txt").unwrap_err().kind(), ErrorKind::PermissionDenied); | ||
|
||
// test `symlink` | ||
assert_eq!(unix::fs::symlink("foo.txt", "foo_link.txt").unwrap_err().kind(), ErrorKind::PermissionDenied); | ||
|
||
// test `readlink` | ||
let symlink_c_str = CString::new("foo.txt").unwrap(); | ||
let mut buf = vec![0; "foo_link.txt".len() + 1]; | ||
unsafe { | ||
assert_eq!(libc::readlink(symlink_c_str.as_ptr(), buf.as_mut_ptr(), buf.len()), -1); | ||
assert_eq!(Error::last_os_error().raw_os_error(), Some(libc::EACCES)); | ||
} | ||
|
||
// test `stat` | ||
assert_eq!(fs::metadata("foo.txt").unwrap_err().kind(), ErrorKind::PermissionDenied); | ||
assert_eq!(Error::last_os_error().raw_os_error(), Some(libc::EACCES)); | ||
|
||
// test `rename` | ||
assert_eq!(fs::rename("a.txt", "b.txt").unwrap_err().kind(), ErrorKind::PermissionDenied); | ||
|
||
// test `mkdir` | ||
assert_eq!(fs::create_dir("foo/bar").unwrap_err().kind(), ErrorKind::PermissionDenied); | ||
|
||
// test `rmdir` | ||
assert_eq!(fs::remove_dir("foo/bar").unwrap_err().kind(), ErrorKind::PermissionDenied); | ||
|
||
// test `opendir` | ||
assert_eq!(fs::read_dir("foo/bar").unwrap_err().kind(), ErrorKind::PermissionDenied); | ||
assert_eq!(Error::last_os_error().raw_os_error(), Some(libc::EACCES)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
warning: `open` was made to return an error due to isolation | ||
|
||
warning: `fcntl` was made to return an error due to isolation | ||
|
||
warning: `unlink` was made to return an error due to isolation | ||
|
||
warning: `symlink` was made to return an error due to isolation | ||
|
||
warning: `readlink` was made to return an error due to isolation | ||
|
||
warning: `$STAT` was made to return an error due to isolation | ||
|
||
warning: `rename` was made to return an error due to isolation | ||
|
||
warning: `mkdir` was made to return an error due to isolation | ||
|
||
warning: `rmdir` was made to return an error due to isolation | ||
|
||
warning: `opendir` was made to return an error due to isolation | ||
|