Skip to content

Commit

Permalink
[fix]: mkdir -r with store path, not lock path (#3908)
Browse files Browse the repository at this point in the history
* [fix]: `mkdir -r` with store path, not lock path

Signed-off-by: Dmitry Balashov <[email protected]>

* [fix]: use `store_path` in the err

Signed-off-by: Dmitry Balashov <[email protected]>

* [refactor]: `&`

Signed-off-by: Dmitry Balashov <[email protected]>

* [refactor]: apply lint

Signed-off-by: Dmitry Balashov <[email protected]>

---------

Signed-off-by: Dmitry Balashov <[email protected]>
  • Loading branch information
0x009922 authored and 6r1d committed Oct 17, 2023
1 parent 76da488 commit 08866f3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions core/src/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,43 +413,43 @@ 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(_) => {
if let Err(e) = fs::File::options()
.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(),
}
}

Expand Down

0 comments on commit 08866f3

Please sign in to comment.