From d0de1c913a1eceaba69c251fa4baa12e01c98f6e Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 3 Mar 2020 10:54:36 -0800 Subject: [PATCH] Use fs::rename which is much faster than move_items (#8579) (#8594) automerge --- runtime/src/accounts_db.rs | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 1b88f84f91..3271a4adef 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -528,23 +528,26 @@ impl AccountsDB { AppendVec::new_relative_path(slot_id, storage_entry.id); let append_vec_abs_path = append_vecs_path.as_ref().join(&append_vec_relative_path); - let mut copy_options = CopyOptions::new(); - copy_options.overwrite = true; - let e = fs_extra::move_items( - &vec![&append_vec_abs_path], - &local_dir, - ©_options, - ) - .map_err(|e| { - AccountsDB::get_io_error(&format!( - "Unable to move {:?} to {:?}: {}", - append_vec_abs_path, local_dir, e - )) - }); - if e.is_err() { - info!("{:?}", e); - continue; - } + let target = local_dir.join(append_vec_abs_path.file_name().unwrap()); + if std::fs::rename(append_vec_abs_path.clone(), target).is_err() { + let mut copy_options = CopyOptions::new(); + copy_options.overwrite = true; + let e = fs_extra::move_items( + &vec![&append_vec_abs_path], + &local_dir, + ©_options, + ) + .map_err(|e| { + AccountsDB::get_io_error(&format!( + "Unable to move {:?} to {:?}: {}", + append_vec_abs_path, local_dir, e + )) + }); + if e.is_err() { + info!("{:?}", e); + continue; + } + }; // Notify the AppendVec of the new file location let local_path = local_dir.join(append_vec_relative_path);