mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-05 20:55:05 +00:00
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.
This commit is contained in:
parent
35b8dad890
commit
dd325c089c
3 changed files with 9 additions and 16 deletions
|
@ -95,14 +95,14 @@ pub fn normalize_path(path: &Path) -> PathBuf {
|
|||
pub fn persist_content_addressed_temp_file<P: AsRef<Path>>(
|
||||
temp_file: NamedTempFile,
|
||||
new_path: P,
|
||||
) -> Result<File, PersistError> {
|
||||
) -> io::Result<File> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<PersistError> 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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T> = Result<T, TableStoreError>;
|
||||
|
||||
|
|
Loading…
Reference in a new issue