Adds SnapshotError::IoWithSourceAndFile (#29527)
This commit is contained in:
parent
832302485e
commit
05d5aed4d8
|
@ -229,6 +229,9 @@ pub enum SnapshotError {
|
||||||
#[error("source({1}) - I/O error: {0}")]
|
#[error("source({1}) - I/O error: {0}")]
|
||||||
IoWithSource(std::io::Error, &'static str),
|
IoWithSource(std::io::Error, &'static str),
|
||||||
|
|
||||||
|
#[error("source({1}) - I/O error: {0}, file: {2}")]
|
||||||
|
IoWithSourceAndFile(#[source] std::io::Error, &'static str, PathBuf),
|
||||||
|
|
||||||
#[error("could not get file name from path: {}", .0.display())]
|
#[error("could not get file name from path: {}", .0.display())]
|
||||||
PathToFileNameError(PathBuf),
|
PathToFileNameError(PathBuf),
|
||||||
|
|
||||||
|
@ -413,8 +416,9 @@ pub fn archive_snapshot_package(
|
||||||
.parent()
|
.parent()
|
||||||
.expect("Tar output path is invalid");
|
.expect("Tar output path is invalid");
|
||||||
|
|
||||||
fs::create_dir_all(tar_dir)
|
fs::create_dir_all(tar_dir).map_err(|e| {
|
||||||
.map_err(|e| SnapshotError::IoWithSource(e, "create archive path"))?;
|
SnapshotError::IoWithSourceAndFile(e, "create archive path", tar_dir.into())
|
||||||
|
})?;
|
||||||
|
|
||||||
// Create the staging directories
|
// Create the staging directories
|
||||||
let staging_dir_prefix = TMP_SNAPSHOT_ARCHIVE_PREFIX;
|
let staging_dir_prefix = TMP_SNAPSHOT_ARCHIVE_PREFIX;
|
||||||
|
@ -430,8 +434,9 @@ pub fn archive_snapshot_package(
|
||||||
let staging_accounts_dir = staging_dir.path().join("accounts");
|
let staging_accounts_dir = staging_dir.path().join("accounts");
|
||||||
let staging_snapshots_dir = staging_dir.path().join("snapshots");
|
let staging_snapshots_dir = staging_dir.path().join("snapshots");
|
||||||
let staging_version_file = staging_dir.path().join("version");
|
let staging_version_file = staging_dir.path().join("version");
|
||||||
fs::create_dir_all(&staging_accounts_dir)
|
fs::create_dir_all(&staging_accounts_dir).map_err(|e| {
|
||||||
.map_err(|e| SnapshotError::IoWithSource(e, "create staging path"))?;
|
SnapshotError::IoWithSourceAndFile(e, "create staging path", staging_accounts_dir.clone())
|
||||||
|
})?;
|
||||||
|
|
||||||
// Add the snapshots to the staging directory
|
// Add the snapshots to the staging directory
|
||||||
symlink::symlink_dir(
|
symlink::symlink_dir(
|
||||||
|
@ -462,8 +467,9 @@ pub fn archive_snapshot_package(
|
||||||
|
|
||||||
// Write version file
|
// Write version file
|
||||||
{
|
{
|
||||||
let mut f = fs::File::create(staging_version_file)
|
let mut f = fs::File::create(&staging_version_file).map_err(|e| {
|
||||||
.map_err(|e| SnapshotError::IoWithSource(e, "create version file"))?;
|
SnapshotError::IoWithSourceAndFile(e, "create version file", staging_version_file)
|
||||||
|
})?;
|
||||||
f.write_all(snapshot_package.snapshot_version.as_str().as_bytes())
|
f.write_all(snapshot_package.snapshot_version.as_str().as_bytes())
|
||||||
.map_err(|e| SnapshotError::IoWithSource(e, "write version file"))?;
|
.map_err(|e| SnapshotError::IoWithSource(e, "write version file"))?;
|
||||||
}
|
}
|
||||||
|
@ -522,8 +528,9 @@ pub fn archive_snapshot_package(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Atomically move the archive into position for other validators to find
|
// Atomically move the archive into position for other validators to find
|
||||||
let metadata = fs::metadata(&archive_path)
|
let metadata = fs::metadata(&archive_path).map_err(|e| {
|
||||||
.map_err(|e| SnapshotError::IoWithSource(e, "archive path stat"))?;
|
SnapshotError::IoWithSourceAndFile(e, "archive path stat", archive_path.clone())
|
||||||
|
})?;
|
||||||
fs::rename(&archive_path, snapshot_package.path())
|
fs::rename(&archive_path, snapshot_package.path())
|
||||||
.map_err(|e| SnapshotError::IoWithSource(e, "archive path rename"))?;
|
.map_err(|e| SnapshotError::IoWithSource(e, "archive path rename"))?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue