Skip to content

Commit

Permalink
Replaces fs-err for HardLinkStoragesToSnapshotErrors (solana-labs#34838)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Jan 18, 2024
1 parent 8f9d915 commit 10590a3
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use {
std::{
cmp::Ordering,
collections::{HashMap, HashSet},
fmt,
fmt, fs,
io::{BufReader, BufWriter, Error as IoError, ErrorKind, Read, Seek, Write},
num::NonZeroUsize,
path::{Path, PathBuf},
Expand Down Expand Up @@ -429,17 +429,17 @@ pub enum AddBankSnapshotError {
/// Errors that can happen in `hard_link_storages_to_snapshot()`
#[derive(Error, Debug)]
pub enum HardLinkStoragesToSnapshotError {
#[error("failed to create accounts hard links dir: {0}")]
CreateAccountsHardLinksDir(#[source] IoError),
#[error("failed to create accounts hard links dir '{1}': {0}")]
CreateAccountsHardLinksDir(#[source] IoError, PathBuf),

#[error("failed to flush storage: {0}")]
FlushStorage(#[source] AccountsFileError),

#[error("failed to get the snapshot's accounts hard link dir: {0}")]
GetSnapshotHardLinksDir(#[from] GetSnapshotAccountsHardLinkDirError),

#[error("failed to hard link storage: {0}")]
HardLinkStorage(#[source] IoError),
#[error("failed to hard link storage from '{1}' to '{2}': {0}")]
HardLinkStorage(#[source] IoError, PathBuf, PathBuf),
}

/// Errors that can happen in `get_snapshot_accounts_hardlink_dir()`
Expand Down Expand Up @@ -1163,8 +1163,12 @@ pub fn hard_link_storages_to_snapshot(
snapshot_storages: &[Arc<AccountStorageEntry>],
) -> std::result::Result<(), HardLinkStoragesToSnapshotError> {
let accounts_hardlinks_dir = bank_snapshot_dir.as_ref().join(SNAPSHOT_ACCOUNTS_HARDLINKS);
fs_err::create_dir_all(&accounts_hardlinks_dir)
.map_err(HardLinkStoragesToSnapshotError::CreateAccountsHardLinksDir)?;
fs::create_dir_all(&accounts_hardlinks_dir).map_err(|err| {
HardLinkStoragesToSnapshotError::CreateAccountsHardLinksDir(
err,
accounts_hardlinks_dir.clone(),
)
})?;

let mut account_paths: HashSet<PathBuf> = HashSet::new();
for storage in snapshot_storages {
Expand All @@ -1182,8 +1186,9 @@ pub fn hard_link_storages_to_snapshot(
// Use the storage slot and id to compose a consistent file name for the hard-link file.
let hardlink_filename = AppendVec::file_name(storage.slot(), storage.append_vec_id());
let hard_link_path = snapshot_hardlink_dir.join(hardlink_filename);
fs_err::hard_link(&storage_path, &hard_link_path)
.map_err(HardLinkStoragesToSnapshotError::HardLinkStorage)?;
fs::hard_link(&storage_path, &hard_link_path).map_err(|err| {
HardLinkStoragesToSnapshotError::HardLinkStorage(err, storage_path, hard_link_path)
})?;
}
Ok(())
}
Expand Down

0 comments on commit 10590a3

Please sign in to comment.