-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(error): improve error messages and file handling #334
base: main
Are you sure you want to change the base?
Conversation
- Update error messages for file operations in the `LocalBackendErrorKind` enum. - Refactor the `ReadBackend` and `WriteBackend` implementations in the `LocalBackend` module to handle file opening errors more accurately. - Add error variants `OpeningFileForPartialReadingFailed` and `OpeningFileForWritingFailed` to provide specific information about file opening failures. - Create parent directory if it does not exist before opening the file for writing. Fixes #rustic-rs/rustic#1315 Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
I kept: for i in 0u8..=255 {
let filename = self.path.join("data").join(hex::encode([i]));
fs::create_dir_all(&filename).map_err(|err| {
LocalBackendErrorKind::DirectoryCreationFailed {
path: filename.clone(),
source: err,
}
})?;
} as that impacts compatibility with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
I have just found a small thing I would change in this PR...
crates/backend/src/local.rs
Outdated
fn write_bytes(&self, tpe: FileType, id: &Id, _cacheable: bool, buf: Bytes) -> Result<()> { | ||
trace!("writing tpe: {:?}, id: {}", &tpe, &id); | ||
let filename = self.path(tpe, id); | ||
|
||
// create parent directory if it does not exist | ||
if let Some(parent) = filename.parent() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make a method parent_path
and then just use self.parent_path(tpe,id)
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added! Not sure how we would handle a non-existing parent? e.g. in a root path, that should never happen right? Or do you have another idea?
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
|
Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
Do not merge: will be rebased after #321 lands
LocalBackendErrorKind
enum.ReadBackend
andWriteBackend
implementations in theLocalBackend
module to handle file opening errors more accurately.OpeningFileForPartialReadingFailed
andOpeningFileForWritingFailed
to provide specific information about file opening failures.Fixes rustic-rs/rustic#1315
Fixes #310