File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ description = "A crate of the gitoxide project dealing with 'git status'-like fu
9
9
authors = [" Sebastian Thiel <sebastian.thiel@icloud.com>" , " Pascal Kuthe <pascal.kuthe@semimod.de>" ]
10
10
edition = " 2021"
11
11
include = [" src/**/*" , " LICENSE-*" ]
12
- rust-version = " 1.70 "
12
+ rust-version = " 1.74 "
13
13
autotests = false
14
14
15
15
[lib ]
Original file line number Diff line number Diff line change 1
- use std:: path:: { Path , PathBuf } ;
2
-
1
+ use bstr:: BStr ;
3
2
use gix_fs:: Stack ;
3
+ use std:: borrow:: Cow ;
4
+ use std:: path:: { Path , PathBuf } ;
4
5
5
6
use crate :: SymlinkCheck ;
6
7
@@ -27,6 +28,22 @@ impl SymlinkCheck {
27
28
self . inner . make_relative_path_current ( relative_path, & mut Delegate ) ?;
28
29
Ok ( self . inner . current ( ) )
29
30
}
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
+ }
30
47
}
31
48
32
49
struct Delegate ;
You can’t perform that action at this time.
0 commit comments