From dd325c089cdbf7d007df59fbd8da5b7aec5c101e Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 16 Dec 2023 17:20:48 +0900 Subject: [PATCH] file_util: drop open file instance from PersistError PersistError is basically a pair of io::Error and NamedTempFile instance. It's unlikely that we would want to propagate the open file instance to the CLI error handler, leaving the temporary file alive. --- lib/src/file_util.rs | 6 +++--- lib/src/simple_op_store.rs | 14 +++++--------- lib/src/stacked_table.rs | 5 +---- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/src/file_util.rs b/lib/src/file_util.rs index 56cdbd9b5..e32f87841 100644 --- a/lib/src/file_util.rs +++ b/lib/src/file_util.rs @@ -95,14 +95,14 @@ pub fn normalize_path(path: &Path) -> PathBuf { pub fn persist_content_addressed_temp_file>( temp_file: NamedTempFile, new_path: P, -) -> Result { +) -> io::Result { match temp_file.persist(&new_path) { Ok(file) => Ok(file), - Err(PersistError { error, file }) => { + Err(PersistError { error, file: _ }) => { if let Ok(existing_file) = File::open(new_path) { Ok(existing_file) } else { - Err(PersistError { error, file }) + Err(error) } } } diff --git a/lib/src/simple_op_store.rs b/lib/src/simple_op_store.rs index 453098989..88f1f775e 100644 --- a/lib/src/simple_op_store.rs +++ b/lib/src/simple_op_store.rs @@ -21,7 +21,7 @@ use std::io::{ErrorKind, Write}; use std::path::{Path, PathBuf}; use prost::Message; -use tempfile::{NamedTempFile, PersistError}; +use tempfile::NamedTempFile; use thiserror::Error; use crate::backend::{CommitId, MillisSinceEpoch, ObjectId, Timestamp}; @@ -34,12 +34,6 @@ use crate::op_store::{ }; use crate::{git, op_store}; -impl From for OpStoreError { - fn from(err: PersistError) -> Self { - OpStoreError::Other(err.into()) - } -} - #[derive(Debug, Error)] #[error("Failed to read {kind} with ID {id}: {err}")] struct DecodeError { @@ -119,7 +113,8 @@ impl OpStore for SimpleOpStore { let id = ViewId::new(blake2b_hash(view).to_vec()); - persist_content_addressed_temp_file(temp_file, self.view_path(&id))?; + persist_content_addressed_temp_file(temp_file, self.view_path(&id)) + .map_err(|err| io_to_write_error(err, "view"))?; Ok(id) } @@ -148,7 +143,8 @@ impl OpStore for SimpleOpStore { let id = OperationId::new(blake2b_hash(operation).to_vec()); - persist_content_addressed_temp_file(temp_file, self.operation_path(&id))?; + persist_content_addressed_temp_file(temp_file, self.operation_path(&id)) + .map_err(|err| io_to_write_error(err, "operation"))?; Ok(id) } } diff --git a/lib/src/stacked_table.rs b/lib/src/stacked_table.rs index 75c9319f0..1cc91cbc1 100644 --- a/lib/src/stacked_table.rs +++ b/lib/src/stacked_table.rs @@ -359,10 +359,7 @@ impl TableSegment for MutableTable { #[derive(Debug, Error)] #[error(transparent)] -pub enum TableStoreError { - IoError(#[from] io::Error), - PersistError(#[from] tempfile::PersistError), -} +pub struct TableStoreError(#[from] pub io::Error); pub type TableStoreResult = Result;