Skip to content
Snippets Groups Projects
Commit 29fc9a2b authored by Georges Racinet's avatar Georges Racinet
Browse files

RHGitaly: mapping file not found errors to `None`

When a file contains a list of values, it is a common pattern that
the absence of the file is equivalent to the list being empty.
This `io_error_not_found_as_none` will help keeping duplication low
(even if fairly trivial).
parent 6576937e
No related branches found
No related tags found
2 merge requests!169Protocol v15.9 and stable branch merge",!166RHGitaly: reading GitLab ref state files, implementing RefService.RefExists
......@@ -21,6 +21,7 @@
pub mod repository;
pub mod service;
pub mod streaming;
pub mod util;
pub use config::*;
pub use gitaly::*;
// Copyright 2023 Georges Racinet <georges.racinet@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
// SPDX-License-Identifier: GPL-2.0-or-later
//! Common utilities
use std::io;
/// Convert `NotFound` I/O error to `None`
///
/// To be used when a file missing is logically equivalent to empty high level contents.
pub fn io_error_not_found_as_none<T>(res: io::Result<T>) -> io::Result<Option<T>> {
match res {
Ok(t) => Ok(Some(t)),
Err(e) => {
if e.kind() == io::ErrorKind::NotFound {
Ok(None)
} else {
Err(e)
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment