From 10590a3bcbf4751205c614557ca221f8161c88ce Mon Sep 17 00:00:00 2001 From: Brooks Date: Thu, 18 Jan 2024 16:49:49 -0500 Subject: [PATCH] Replaces fs-err for HardLinkStoragesToSnapshotErrors (#34838) --- runtime/src/snapshot_utils.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index cc1266631..b267dde03 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -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}, @@ -429,8 +429,8 @@ 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), @@ -438,8 +438,8 @@ pub enum HardLinkStoragesToSnapshotError { #[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()` @@ -1163,8 +1163,12 @@ pub fn hard_link_storages_to_snapshot( snapshot_storages: &[Arc], ) -> 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 = HashSet::new(); for storage in snapshot_storages { @@ -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(()) }