summaryrefslogtreecommitdiffstats
path: root/vendor/gix-config/src/file
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/gix-config/src/file
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-config/src/file')
-rw-r--r--vendor/gix-config/src/file/access/raw.rs2
-rw-r--r--vendor/gix-config/src/file/init/comfort.rs16
-rw-r--r--vendor/gix-config/src/file/init/from_paths.rs53
-rw-r--r--vendor/gix-config/src/file/init/types.rs4
-rw-r--r--vendor/gix-config/src/file/section/body.rs2
5 files changed, 59 insertions, 18 deletions
diff --git a/vendor/gix-config/src/file/access/raw.rs b/vendor/gix-config/src/file/access/raw.rs
index 46f1fb006..44b318f24 100644
--- a/vendor/gix-config/src/file/access/raw.rs
+++ b/vendor/gix-config/src/file/access/raw.rs
@@ -136,7 +136,7 @@ impl<'event> File<'event> {
/// ain order of occurrence.
///
/// The ordering means that the last of the returned values is the one that would be the
- /// value used in the single-value case.nd key.
+ /// value used in the single-value case.and key.
///
/// # Examples
///
diff --git a/vendor/gix-config/src/file/init/comfort.rs b/vendor/gix-config/src/file/init/comfort.rs
index ffe859a1a..aa77fb9c0 100644
--- a/vendor/gix-config/src/file/init/comfort.rs
+++ b/vendor/gix-config/src/file/init/comfort.rs
@@ -1,5 +1,3 @@
-use std::path::PathBuf;
-
use crate::{
file::{init, Metadata},
path, source, File, Source,
@@ -30,7 +28,7 @@ impl File<'static> {
.flat_map(|kind| kind.sources())
.filter_map(|source| {
let path = source
- .storage_location(&mut |name| std::env::var_os(name))
+ .storage_location(&mut gix_path::env::var)
.and_then(|p| p.is_file().then_some(p))
.map(|p| p.into_owned());
@@ -43,7 +41,7 @@ impl File<'static> {
.into()
});
- let home = std::env::var("HOME").ok().map(PathBuf::from);
+ let home = gix_path::env::home_dir();
let options = init::Options {
includes: init::includes::Options::follow_without_conditional(home.as_deref()),
..Default::default()
@@ -59,7 +57,7 @@ impl File<'static> {
///
/// [`gix-config`'s documentation]: https://git-scm.com/docs/gix-config#Documentation/gix-config.txt-GITCONFIGCOUNT
pub fn from_environment_overrides() -> Result<File<'static>, init::from_env::Error> {
- let home = std::env::var("HOME").ok().map(PathBuf::from);
+ let home = gix_path::env::home_dir();
let options = init::Options {
includes: init::includes::Options::follow_without_conditional(home.as_deref()),
..Default::default()
@@ -88,7 +86,7 @@ impl File<'static> {
let mut path = dir.into();
path.push(
source
- .storage_location(&mut |n| std::env::var_os(n))
+ .storage_location(&mut gix_path::env::var)
.expect("location available for local"),
);
let local = Self::from_path_no_includes(&path, source)?;
@@ -101,7 +99,7 @@ impl File<'static> {
let source = Source::Worktree;
let path = git_dir.join(
source
- .storage_location(&mut |n| std::env::var_os(n))
+ .storage_location(&mut gix_path::env::var)
.expect("location available for worktree"),
);
Self::from_path_no_includes(path, source)
@@ -110,7 +108,7 @@ impl File<'static> {
}
.transpose()?;
- let home = std::env::var("HOME").ok().map(PathBuf::from);
+ let home = gix_path::env::home_dir();
let options = init::Options {
includes: init::includes::Options::follow(
path::interpolate::Context {
@@ -122,7 +120,7 @@ impl File<'static> {
branch_name: None,
},
),
- lossy: false,
+ ..Default::default()
};
let mut globals = Self::from_globals()?;
diff --git a/vendor/gix-config/src/file/init/from_paths.rs b/vendor/gix-config/src/file/init/from_paths.rs
index 5d671b69e..73737075e 100644
--- a/vendor/gix-config/src/file/init/from_paths.rs
+++ b/vendor/gix-config/src/file/init/from_paths.rs
@@ -9,8 +9,11 @@ use crate::{
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
- #[error(transparent)]
- Io(#[from] std::io::Error),
+ #[error("The configuration file at \"{}\" could not be read", path.display())]
+ Io {
+ source: std::io::Error,
+ path: std::path::PathBuf,
+ },
#[error(transparent)]
Init(#[from] init::Error),
}
@@ -22,10 +25,22 @@ impl File<'static> {
/// Note that the path will be checked for ownership to derive trust.
pub fn from_path_no_includes(path: impl Into<std::path::PathBuf>, source: crate::Source) -> Result<Self, Error> {
let path = path.into();
- let trust = gix_sec::Trust::from_path_ownership(&path)?;
+ let trust = match gix_sec::Trust::from_path_ownership(&path) {
+ Ok(t) => t,
+ Err(err) => return Err(Error::Io { source: err, path }),
+ };
let mut buf = Vec::new();
- std::io::copy(&mut std::fs::File::open(&path)?, &mut buf)?;
+ match std::io::copy(
+ &mut match std::fs::File::open(&path) {
+ Ok(f) => f,
+ Err(err) => return Err(Error::Io { source: err, path }),
+ },
+ &mut buf,
+ ) {
+ Ok(_) => {}
+ Err(err) => return Err(Error::Io { source: err, path }),
+ }
Ok(File::from_bytes_owned(
&mut buf,
@@ -69,14 +84,38 @@ impl File<'static> {
}
buf.clear();
- std::io::copy(
+ match std::io::copy(
&mut match std::fs::File::open(&path) {
Ok(f) => f,
Err(err) if !err_on_non_existing_paths && err.kind() == std::io::ErrorKind::NotFound => continue,
- Err(err) => return Err(err.into()),
+ Err(err) => {
+ let err = Error::Io { source: err, path };
+ if options.ignore_io_errors {
+ log::warn!("ignoring: {err:#?}");
+ continue;
+ } else {
+ return Err(err);
+ }
+ }
},
buf,
- )?;
+ ) {
+ Ok(_) => {}
+ Err(err) => {
+ if options.ignore_io_errors {
+ log::warn!(
+ "ignoring: {:#?}",
+ Error::Io {
+ source: err,
+ path: path.clone()
+ }
+ );
+ buf.clear();
+ } else {
+ return Err(Error::Io { source: err, path });
+ }
+ }
+ };
meta.path = Some(path);
let config = Self::from_bytes_owned(buf, meta, options)?;
diff --git a/vendor/gix-config/src/file/init/types.rs b/vendor/gix-config/src/file/init/types.rs
index fcb17c0ca..952d1910b 100644
--- a/vendor/gix-config/src/file/init/types.rs
+++ b/vendor/gix-config/src/file/init/types.rs
@@ -22,6 +22,10 @@ pub struct Options<'a> {
/// Note that doing so will degenerate [`write_to()`][crate::File::write_to()] and strip it off its comments
/// and additional whitespace entirely, but will otherwise be a valid configuration file.
pub lossy: bool,
+ /// If true, any IO error happening when reading a configuration file will be ignored.
+ ///
+ /// That way it's possible to pass multiple files and read as many as possible, to have 'something' instead of nothing.
+ pub ignore_io_errors: bool,
}
impl Options<'_> {
diff --git a/vendor/gix-config/src/file/section/body.rs b/vendor/gix-config/src/file/section/body.rs
index e1a53efd9..ad196d133 100644
--- a/vendor/gix-config/src/file/section/body.rs
+++ b/vendor/gix-config/src/file/section/body.rs
@@ -121,7 +121,7 @@ impl<'event> Body<'event> {
&self.0
}
- /// Returns the the range containing the value events for the `key`, with value range being `None` if there is no key-value separator
+ /// Returns the range containing the value events for the `key`, with value range being `None` if there is no key-value separator
/// and only a 'fake' Value event with an empty string in side.
/// If the value is not found, `None` is returned.
pub(crate) fn key_and_value_range_by(&self, key: &Key<'_>) -> Option<(Range<usize>, Option<Range<usize>>)> {