1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // This test can't be a unit test in std,
12 // because it needs TempDir, which is in extra
17 use std::io::fs::PathExtensions;
22 fn rename_directory() {
24 static U_RWX: i32 = (libc::S_IRUSR | libc::S_IWUSR | libc::S_IXUSR) as i32;
26 let tmpdir = TempDir::new("rename_directory").ok().expect("rename_directory failed");
27 let tmpdir = tmpdir.path();
28 let old_path = tmpdir.join_many(&["foo", "bar", "baz"]);
29 fs::mkdir_recursive(&old_path, io::USER_RWX);
30 let test_file = &old_path.join("temp.txt");
32 /* Write the temp input file */
33 let ostream = test_file.with_c_str(|fromp| {
34 "w+b".with_c_str(|modebuf| {
35 libc::fopen(fromp, modebuf)
38 assert!((ostream as uint != 0u));
39 let s = "hello".to_string();
40 "hello".with_c_str(|buf| {
41 let write_len = libc::fwrite(buf as *const libc::c_void,
43 (s.len() + 1u) as libc::size_t,
45 assert_eq!(write_len, (s.len() + 1) as libc::size_t)
47 assert_eq!(libc::fclose(ostream), (0u as libc::c_int));
49 let new_path = tmpdir.join_many(&["quux", "blat"]);
50 fs::mkdir_recursive(&new_path, io::USER_RWX);
51 fs::rename(&old_path, &new_path.join("newdir"));
52 assert!(new_path.join("newdir").is_dir());
53 assert!(new_path.join_many(&["newdir", "temp.txt"]).exists());
57 pub fn main() { rename_directory() }