1
1
// don't warn about try_from paths conversion on unix
2
2
#![ allow( clippy:: unnecessary_fallible_conversions) ]
3
3
4
- use std:: {
5
- path:: { Path , PathBuf } ,
6
- str:: FromStr ,
7
- } ;
4
+ use std:: { path:: PathBuf , str:: FromStr } ;
8
5
9
6
use anyhow:: Result ;
10
7
use globset:: Glob ;
@@ -13,6 +10,7 @@ use rstest::rstest;
13
10
14
11
use rustic_core:: {
15
12
repofile:: { Node , SnapshotFile } ,
13
+ util:: GlobMatcherExt ,
16
14
BackupOptions , FindMatches , FindNode ,
17
15
} ;
18
16
use typed_path:: UnixPath ;
@@ -39,9 +37,8 @@ fn test_find(tar_gz_testdata: Result<TestSource>, set_up_repo: Result<RepoOpen>)
39
37
assert_with_win ( "find-nodes-not-found" , not_found) ;
40
38
// test non-existing match
41
39
let glob = Glob :: new ( "not_existing" ) ?. compile_matcher ( ) ;
42
- let not_found = repo. find_matching_nodes ( vec ! [ snapshot. tree] , & |path, _| {
43
- glob. is_match ( PathBuf :: try_from ( path) . unwrap ( ) )
44
- } ) ?;
40
+ let not_found =
41
+ repo. find_matching_nodes ( vec ! [ snapshot. tree] , & |path, _| glob. is_unix_match ( path) ) ?;
45
42
assert_debug_snapshot ! ( "find-matching-nodes-not-found" , not_found) ;
46
43
47
44
// test existing path
@@ -51,21 +48,15 @@ fn test_find(tar_gz_testdata: Result<TestSource>, set_up_repo: Result<RepoOpen>)
51
48
// test existing match
52
49
let glob = Glob :: new ( "testfile" ) ?. compile_matcher ( ) ;
53
50
let match_func = |path : & UnixPath , _: & Node | {
54
- glob. is_match ( PathBuf :: try_from ( path) . unwrap ( ) )
55
- || path
56
- . file_name ( )
57
- . is_some_and ( |f| glob. is_match ( Path :: new ( & String :: from_utf8 ( f. to_vec ( ) ) . unwrap ( ) ) ) )
51
+ glob. is_unix_match ( path) || path. file_name ( ) . is_some_and ( |f| glob. is_unix_match ( f) )
58
52
} ;
59
53
let FindMatches { paths, matches, .. } =
60
54
repo. find_matching_nodes ( vec ! [ snapshot. tree] , & match_func) ?;
61
55
assert_debug_snapshot ! ( "find-matching-existing" , ( paths, matches) ) ;
62
56
// test existing match
63
57
let glob = Glob :: new ( "testfile*" ) ?. compile_matcher ( ) ;
64
58
let match_func = |path : & UnixPath , _: & Node | {
65
- glob. is_match ( PathBuf :: try_from ( path) . unwrap ( ) )
66
- || path
67
- . file_name ( )
68
- . is_some_and ( |f| glob. is_match ( Path :: new ( & String :: from_utf8 ( f. to_vec ( ) ) . unwrap ( ) ) ) )
59
+ glob. is_unix_match ( path) || path. file_name ( ) . is_some_and ( |f| glob. is_unix_match ( f) )
69
60
} ;
70
61
let FindMatches { paths, matches, .. } =
71
62
repo. find_matching_nodes ( vec ! [ snapshot. tree] , & match_func) ?;
0 commit comments