@@ -62,6 +62,22 @@ fn map_path_v1(p: &Utf8Path) -> &Utf8Path {
6262 }
6363}
6464
65+ /// Given two paths, which may be absolute (starting with /) or
66+ /// start with `./`, return true if they are equal after removing
67+ /// those prefixes. This is effectively "would these paths be equal"
68+ /// when processed as a tar entry.
69+ pub ( crate ) fn path_equivalent_for_tar ( a : impl AsRef < Utf8Path > , b : impl AsRef < Utf8Path > ) -> bool {
70+ fn strip_prefix ( p : & Utf8Path ) -> & Utf8Path {
71+ if let Ok ( p) = p. strip_prefix ( "/" ) {
72+ return p;
73+ } else if let Ok ( p) = p. strip_prefix ( "./" ) {
74+ return p;
75+ }
76+ return p;
77+ }
78+ strip_prefix ( a. as_ref ( ) ) == strip_prefix ( b. as_ref ( ) )
79+ }
80+
6581struct OstreeTarWriter < ' a , W : std:: io:: Write > {
6682 repo : & ' a ostree:: Repo ,
6783 commit_checksum : & ' a str ,
@@ -496,7 +512,7 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
496512
497513 // Record if the ostree commit includes /var/tmp; if so we don't need to synthesize
498514 // it in `append_standard_var()`.
499- if dirpath == "var/tmp" {
515+ if path_equivalent_for_tar ( dirpath, "var/tmp" ) {
500516 self . wrote_vartmp = true ;
501517 }
502518
@@ -724,6 +740,14 @@ pub fn update_detached_metadata<D: std::io::Write, C: IsA<gio::Cancellable>>(
724740mod tests {
725741 use super :: * ;
726742
743+ #[ test]
744+ fn test_path_equivalent ( ) {
745+ assert ! ( path_equivalent_for_tar( "var/tmp" , "./var/tmp" ) ) ;
746+ assert ! ( path_equivalent_for_tar( "./var/tmp" , "var/tmp" ) ) ;
747+ assert ! ( path_equivalent_for_tar( "/var/tmp" , "var/tmp" ) ) ;
748+ assert ! ( !path_equivalent_for_tar( "var/tmp" , "var" ) ) ;
749+ }
750+
727751 #[ test]
728752 fn test_map_path ( ) {
729753 assert_eq ! ( map_path( "/" . into( ) ) , Utf8Path :: new( "/" ) ) ;
0 commit comments