@@ -56,14 +56,35 @@ mode=bare-split-xattrs
5656/// System calls are expensive.
5757const BUF_CAPACITY : usize = 131072 ;
5858
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+ }
6373 _ => Cow :: Borrowed ( p) ,
6474 }
6575}
6676
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+
6788/// Convert usr/etc back to etc for the tar stream.
6889fn map_path_v1 ( p : & Utf8Path ) -> & Utf8Path {
6990 debug_assert ! ( !p. starts_with( "/" ) && !p. starts_with( "." ) ) ;
0 commit comments