From 7bcb291880a9c76771c94d753dfa4b67626f1de6 Mon Sep 17 00:00:00 2001 From: 0x009922 Date: Thu, 21 Sep 2023 19:10:43 +0700 Subject: [PATCH] [fix]: `mkdir -r` with store path, not lock path (#3908) * [fix]: `mkdir -r` with store path, not lock path Signed-off-by: Dmitry Balashov * [fix]: use `store_path` in the err Signed-off-by: Dmitry Balashov * [refactor]: `&` Signed-off-by: Dmitry Balashov * [refactor]: apply lint Signed-off-by: Dmitry Balashov --------- Signed-off-by: Dmitry Balashov --- core/src/kura.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/kura.rs b/core/src/kura.rs index 80fa8975744..28f5515ada8 100644 --- a/core/src/kura.rs +++ b/core/src/kura.rs @@ -413,20 +413,20 @@ impl BlockStore { /// /// # Panics /// * if you pass in `LockStatus::Unlocked` and it is unable to lock the block store. - pub fn new(path: &Path, already_locked: LockStatus) -> Self { + pub fn new(store_path: &Path, already_locked: LockStatus) -> Self { if matches!(already_locked, LockStatus::Unlocked) { - let path = path.join(LOCK_FILE_NAME); + let lock_path = store_path.join(LOCK_FILE_NAME); if let Err(e) = fs::File::options() .read(true) .write(true) .create_new(true) - .open(path.clone()) + .open(&lock_path) { match e.kind() { - std::io::ErrorKind::AlreadyExists => Err(Error::Locked(path)), + std::io::ErrorKind::AlreadyExists => Err(Error::Locked(lock_path)), std::io::ErrorKind::NotFound => { - match std::fs::create_dir_all(&path) - .map_err(|e| Error::MkDir(e, path.clone())) + match std::fs::create_dir_all(store_path) + .map_err(|e| Error::MkDir(e, store_path.to_path_buf())) { Err(e) => Err(e), Ok(_) => { @@ -434,22 +434,22 @@ impl BlockStore { .read(true) .write(true) .create_new(true) - .open(path.clone()) + .open(&lock_path) { - Err(Error::IO(e, path)) + Err(Error::IO(e, lock_path)) } else { Ok(()) } } } } - _ => Err(Error::IO(e, path)), + _ => Err(Error::IO(e, lock_path)), } .expect("Kura must be able to lock the blockstore"); } } BlockStore { - path_to_blockchain: path.to_path_buf(), + path_to_blockchain: store_path.to_path_buf(), } }