From 6454a06c341de7f1c92f97222a6c37572176ee9b Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Thu, 11 Jul 2019 16:31:56 -0700 Subject: 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. --- test/test_fcntl.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'test') 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; @@ -27,6 +30,22 @@ fn test_openat() { close(dirfd).unwrap(); } +#[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(); -- cgit v1.2.3