mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-05 03:02:19 +00:00
working_copy: improve error handling when getting file stats
This commit is contained in:
parent
9feb786a51
commit
9aa2009320
1 changed files with 16 additions and 7 deletions
|
@ -201,8 +201,12 @@ pub struct CheckoutStats {
|
|||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SnapshotError {
|
||||
#[error("Failed to open file {path}: {err:?}")]
|
||||
FileOpenError { path: PathBuf, err: std::io::Error },
|
||||
#[error("{message}: {err:?}")]
|
||||
IoError {
|
||||
message: String,
|
||||
#[source]
|
||||
err: std::io::Error,
|
||||
},
|
||||
#[error("Working copy path {} is not valid UTF-8", path.to_string_lossy())]
|
||||
InvalidUtf8Path { path: OsString },
|
||||
#[error("Symlink {path} target is not valid UTF-8")]
|
||||
|
@ -338,8 +342,8 @@ impl TreeState {
|
|||
path: &RepoPath,
|
||||
disk_path: &Path,
|
||||
) -> Result<FileId, SnapshotError> {
|
||||
let file = File::open(disk_path).map_err(|err| SnapshotError::FileOpenError {
|
||||
path: disk_path.to_path_buf(),
|
||||
let file = File::open(disk_path).map_err(|err| SnapshotError::IoError {
|
||||
message: format!("Failed to open file {}", disk_path.display()),
|
||||
err,
|
||||
})?;
|
||||
Ok(self.store.write_file(path, &mut Box::new(file))?)
|
||||
|
@ -352,8 +356,8 @@ impl TreeState {
|
|||
) -> Result<SymlinkId, SnapshotError> {
|
||||
let target = disk_path
|
||||
.read_link()
|
||||
.map_err(|err| SnapshotError::FileOpenError {
|
||||
path: disk_path.to_path_buf(),
|
||||
.map_err(|err| SnapshotError::IoError {
|
||||
message: format!("Failed to read symlink {}", disk_path.display()),
|
||||
err,
|
||||
})?;
|
||||
let str_target =
|
||||
|
@ -461,7 +465,12 @@ impl TreeState {
|
|||
// ignore it.
|
||||
return Ok(());
|
||||
}
|
||||
let metadata = disk_path.symlink_metadata().unwrap();
|
||||
let metadata = disk_path
|
||||
.symlink_metadata()
|
||||
.map_err(|err| SnapshotError::IoError {
|
||||
message: format!("Failed to stat file {}", disk_path.display()),
|
||||
err,
|
||||
})?;
|
||||
let mut new_file_state = file_state(&metadata);
|
||||
match maybe_current_file_state {
|
||||
None => {
|
||||
|
|
Loading…
Reference in a new issue