summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorScott Lamb <slamb@slamb.org>2019-07-11 16:31:56 -0700
committerScott Lamb <slamb@slamb.org>2019-07-17 14:13:21 -0700
commit6454a06c341de7f1c92f97222a6c37572176ee9b (patch)
tree88f43b27af20ffe1fb270d0266c626f19cc39989 /test
parent500036a206188dc8f57bf95a7c61616db417038e (diff)
downloadnix-6454a06c341de7f1c92f97222a6c37572176ee9b.zip
Add renameat
renameat is (somewhat oddly, imho) in stdio.h. I put it in nix::fcntl because there's no nix::stdio and all its friends (including the AT_* constants) are in nix::fcntl.
Diffstat (limited to 'test')
-rw-r--r--test/test_fcntl.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs
index 05851828..6b2bbd67 100644
--- a/test/test_fcntl.rs
+++ b/test/test_fcntl.rs
@@ -1,7 +1,10 @@
-use nix::fcntl::{openat, open, OFlag, readlink, readlinkat};
+use nix::Error;
+use nix::errno::*;
+use nix::fcntl::{openat, open, OFlag, readlink, readlinkat, renameat};
use nix::sys::stat::Mode;
use nix::unistd::{close, read};
use tempfile::{self, NamedTempFile};
+use std::fs::File;
use std::io::prelude::*;
use std::os::unix::fs;
@@ -28,6 +31,22 @@ fn test_openat() {
}
#[test]
+fn test_renameat() {
+ let old_dir = tempfile::tempdir().unwrap();
+ let old_dirfd = open(old_dir.path(), OFlag::empty(), Mode::empty()).unwrap();
+ let old_path = old_dir.path().join("old");
+ File::create(&old_path).unwrap();
+ let new_dir = tempfile::tempdir().unwrap();
+ let new_dirfd = open(new_dir.path(), OFlag::empty(), Mode::empty()).unwrap();
+ renameat(Some(old_dirfd), "old", Some(new_dirfd), "new").unwrap();
+ assert_eq!(renameat(Some(old_dirfd), "old", Some(new_dirfd), "new").unwrap_err(),
+ Error::Sys(Errno::ENOENT));
+ close(old_dirfd).unwrap();
+ close(new_dirfd).unwrap();
+ assert!(new_dir.path().join("new").exists());
+}
+
+#[test]
fn test_readlink() {
let tempdir = tempfile::tempdir().unwrap();
let src = tempdir.path().join("a");