@@ -56,14 +56,35 @@ mode=bare-split-xattrs
56
56
/// System calls are expensive.
57
57
const BUF_CAPACITY : usize = 131072 ;
58
58
59
- /// Convert /usr/etc back to /etc
60
- fn map_path ( p : & Utf8Path ) -> std:: borrow:: Cow < Utf8Path > {
61
- match p. strip_prefix ( "./usr/etc" ) {
62
- Ok ( r) => Cow :: Owned ( Utf8Path :: new ( "./etc" ) . join ( r) ) ,
59
+ /// Convert `from` to `to`
60
+ fn map_path_inner < ' p > (
61
+ p : & ' p Utf8Path ,
62
+ from : & ' _ str ,
63
+ to : & ' _ str ,
64
+ ) -> std:: borrow:: Cow < ' p , Utf8Path > {
65
+ match p. strip_prefix ( from) {
66
+ Ok ( r) => {
67
+ if r. components ( ) . count ( ) > 0 {
68
+ Cow :: Owned ( Utf8Path :: new ( to) . join ( r) )
69
+ } else {
70
+ Cow :: Owned ( Utf8PathBuf :: from ( to) )
71
+ }
72
+ }
63
73
_ => Cow :: Borrowed ( p) ,
64
74
}
65
75
}
66
76
77
+ /// Convert /usr/etc back to /etc
78
+ fn map_path ( p : & Utf8Path ) -> std:: borrow:: Cow < Utf8Path > {
79
+ map_path_inner ( p, "./usr/etc" , "./etc" )
80
+ }
81
+
82
+ /// Convert etc to usr/etc
83
+ /// Note: no leading '/' or './'
84
+ fn unmap_path ( p : & Utf8Path ) -> std:: borrow:: Cow < Utf8Path > {
85
+ map_path_inner ( p, "etc" , "usr/etc" )
86
+ }
87
+
67
88
/// Convert usr/etc back to etc for the tar stream.
68
89
fn map_path_v1 ( p : & Utf8Path ) -> & Utf8Path {
69
90
debug_assert ! ( !p. starts_with( "/" ) && !p. starts_with( "." ) ) ;
0 commit comments