2014-02-07 20:08:32 +01:00
|
|
|
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
2013-08-28 12:27:10 -07:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// This test can't be a unit test in std,
|
2013-10-11 15:55:37 +02:00
|
|
|
// because it needs TempDir, which is in extra
|
2013-08-28 12:27:10 -07:00
|
|
|
|
2015-03-22 13:13:15 -07:00
|
|
|
// pretty-expanded FIXME #23616
|
|
|
|
|
2015-03-05 18:33:58 -08:00
|
|
|
#![feature(tempdir, path_ext)]
|
|
|
|
|
2014-11-25 13:28:35 -08:00
|
|
|
use std::ffi::CString;
|
2015-03-17 13:33:26 -07:00
|
|
|
use std::fs::{self, TempDir, File, PathExt};
|
2013-08-28 12:27:10 -07:00
|
|
|
|
|
|
|
fn rename_directory() {
|
2015-03-17 13:33:26 -07:00
|
|
|
let tmpdir = TempDir::new("rename_directory").ok().expect("rename_directory failed");
|
|
|
|
let tmpdir = tmpdir.path();
|
|
|
|
let old_path = tmpdir.join("foo/bar/baz");
|
|
|
|
fs::create_dir_all(&old_path).unwrap();
|
|
|
|
let test_file = &old_path.join("temp.txt");
|
|
|
|
|
|
|
|
File::create(test_file).unwrap();
|
|
|
|
|
|
|
|
let new_path = tmpdir.join("quux/blat");
|
|
|
|
fs::create_dir_all(&new_path).unwrap();
|
|
|
|
fs::rename(&old_path, &new_path.join("newdir"));
|
|
|
|
assert!(new_path.join("newdir").is_dir());
|
|
|
|
assert!(new_path.join("newdir/temp.txt").exists());
|
2013-08-28 12:27:10 -07:00
|
|
|
}
|
|
|
|
|
2014-01-03 15:30:54 -08:00
|
|
|
pub fn main() { rename_directory() }
|