Skip to content

Commit

Permalink
Handle parent() error
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangzhu70 committed Apr 18, 2023
1 parent 07edcf3 commit 5c81d00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions runtime/src/snapshot_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
snapshot_archive_info::{SnapshotArchiveInfo, SnapshotArchiveInfoGetter},
snapshot_hash::SnapshotHash,
snapshot_utils::{
self, ArchiveFormat, BankSnapshotInfo, Result, SnapshotVersion,
self, ArchiveFormat, BankSnapshotInfo, Result, SnapshotVersion, SnapshotError,
SNAPSHOT_STATUS_CACHE_FILENAME, TMP_BANK_SNAPSHOT_PREFIX,
},
},
Expand Down Expand Up @@ -79,7 +79,9 @@ impl AccountsPackage {
}

// Hard link the snapshot into a tmpdir, to ensure its not removed prior to packaging.
let bank_snapshots_dir = bank_snapshot_info.snapshot_dir.parent().unwrap();
let bank_snapshot_dir = &bank_snapshot_info.snapshot_dir;
let bank_snapshots_dir = bank_snapshot_dir.parent()
.ok_or_else(|| SnapshotError::InvalidSnapshotDirPath(bank_snapshot_dir.clone()))?;
let snapshot_links = tempfile::Builder::new()
.prefix(&format!("{}{}-", TMP_BANK_SNAPSHOT_PREFIX, bank.slot()))
.tempdir_in(bank_snapshots_dir)?;
Expand All @@ -91,9 +93,7 @@ impl AccountsPackage {
let snapshot_path = bank_snapshot_info.snapshot_path();
let file_name = snapshot_utils::path_to_file_name_str(&snapshot_path)?;
fs::hard_link(&snapshot_path, snapshot_hardlink_dir.join(file_name))?;
let status_cache_path = bank_snapshot_info
.snapshot_dir
.join(SNAPSHOT_STATUS_CACHE_FILENAME);
let status_cache_path = bank_snapshot_dir.join(SNAPSHOT_STATUS_CACHE_FILENAME);
let status_cache_file_name = snapshot_utils::path_to_file_name_str(&status_cache_path)?;
fs::hard_link(
&status_cache_path,
Expand Down
3 changes: 3 additions & 0 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ pub enum SnapshotError {
#[error("bank_snapshot_info new_from_dir failed: {0}")]
NewFromDir(#[from] SnapshotNewFromDirError),

#[error("invalid snapshot dir path: {}", .0.display())]
InvalidSnapshotDirPath(PathBuf),

#[error("invalid AppendVec path: {}", .0.display())]
InvalidAppendVecPath(PathBuf),

Expand Down

0 comments on commit 5c81d00

Please sign in to comment.