Skip to content

Commit 9db196b

Browse files
committed
feat: add SymlinkCheck::verified_path_allow_nonexisting()
1 parent 807c2de commit 9db196b

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

gix-status/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "A crate of the gitoxide project dealing with 'git status'-like fu
99
authors = ["Sebastian Thiel <[email protected]>", "Pascal Kuthe <[email protected]>"]
1010
edition = "2021"
1111
include = ["src/**/*", "LICENSE-*"]
12-
rust-version = "1.70"
12+
rust-version = "1.74"
1313
autotests = false
1414

1515
[lib]

gix-status/src/stack.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use std::path::{Path, PathBuf};
2-
1+
use bstr::BStr;
32
use gix_fs::Stack;
3+
use std::borrow::Cow;
4+
use std::path::{Path, PathBuf};
45

56
use crate::SymlinkCheck;
67

@@ -27,6 +28,22 @@ impl SymlinkCheck {
2728
self.inner.make_relative_path_current(relative_path, &mut Delegate)?;
2829
Ok(self.inner.current())
2930
}
31+
32+
/// Like [`Self::verified_path()`], but do not fail if there is no directory entry at `relative_path` or on the way
33+
/// to `relative_path`. Instead.
34+
/// For convenience, this incarnation is tuned to be easy to use with Git paths, i.e. slash-separated `BString` path.
35+
pub fn verified_path_allow_nonexisting(&mut self, relative_path: &BStr) -> std::io::Result<Cow<'_, Path>> {
36+
let rela_path = gix_path::try_from_bstr(relative_path).map_err(std::io::Error::other)?;
37+
if let Err(err) = self.verified_path(&rela_path) {
38+
if err.kind() == std::io::ErrorKind::NotFound {
39+
Ok(Cow::Owned(self.inner.root().join(rela_path)))
40+
} else {
41+
Err(err)
42+
}
43+
} else {
44+
Ok(Cow::Borrowed(self.inner.current()))
45+
}
46+
}
3047
}
3148

3249
struct Delegate;

0 commit comments

Comments
 (0)