Fixed moving dirs on windows

This commit is contained in:
arkpar 2016-12-14 01:33:57 +01:00
parent be5fefe772
commit 3280f071b1

View File

@ -139,7 +139,9 @@ fn file_exists(path: &Path) -> bool {
}
pub fn upgrade_key_location(from: &PathBuf, to: &PathBuf) {
match fs::create_dir_all(to).and_then(|()| fs::read_dir(from)) {
let mut parent = to.clone();
parent.pop();
match fs::create_dir_all(&parent).and_then(|()| fs::read_dir(from)) {
Ok(entries) => {
let files: Vec<_> = entries.filter_map(|f| f.ok().and_then(|f| if f.file_type().ok().map_or(false, |f| f.is_file()) { f.file_name().to_str().map(|s| s.to_owned()) } else { None })).collect();
let mut num: usize = 0;
@ -171,8 +173,10 @@ pub fn upgrade_key_location(from: &PathBuf, to: &PathBuf) {
fn upgrade_dir_location(source: &PathBuf, dest: &PathBuf) {
if file_exists(&source) {
if !file_exists(&dest) {
if let Err(e) = fs::create_dir_all(&dest).and_then(|()| fs::rename(&source, &dest)) {
debug!("Skipped path {:?}:{:?}", dest, e);
let mut parent = dest.clone();
parent.pop();
if let Err(e) = fs::create_dir_all(&parent).and_then(|()| fs::rename(&source, &dest)) {
debug!("Skipped path {:?} -> {:?} :{:?}", source, dest, e);
} else {
info!("Moved {} to {}", source.to_string_lossy(), dest.to_string_lossy());
}