@@ -62,6 +62,22 @@ fn map_path_v1(p: &Utf8Path) -> &Utf8Path {
62
62
}
63
63
}
64
64
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
+
65
81
struct OstreeTarWriter < ' a , W : std:: io:: Write > {
66
82
repo : & ' a ostree:: Repo ,
67
83
commit_checksum : & ' a str ,
@@ -496,7 +512,7 @@ impl<'a, W: std::io::Write> OstreeTarWriter<'a, W> {
496
512
497
513
// Record if the ostree commit includes /var/tmp; if so we don't need to synthesize
498
514
// it in `append_standard_var()`.
499
- if dirpath == "var/tmp" {
515
+ if path_equivalent_for_tar ( dirpath, "var/tmp" ) {
500
516
self . wrote_vartmp = true ;
501
517
}
502
518
@@ -724,6 +740,14 @@ pub fn update_detached_metadata<D: std::io::Write, C: IsA<gio::Cancellable>>(
724
740
mod tests {
725
741
use super :: * ;
726
742
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
+
727
751
#[ test]
728
752
fn test_map_path ( ) {
729
753
assert_eq ! ( map_path( "/" . into( ) ) , Utf8Path :: new( "/" ) ) ;
0 commit comments