@@ -48,8 +48,32 @@ fn test_purge_caches() -> Result<(), Error> {
48
48
Ok ( ( ) )
49
49
}
50
50
51
+ /// Define which files should be ignored when comparing the two workspaces. If there are expected
52
+ /// changes, update the function to match them.
53
+ fn should_ignore ( base : & Path , path : & Path ) -> bool {
54
+ let components = match path. strip_prefix ( base) {
55
+ Ok ( stripped) => stripped
56
+ . components ( )
57
+ . map ( |component| component. as_os_str ( ) . to_string_lossy ( ) . to_string ( ) )
58
+ . collect :: < Vec < _ > > ( ) ,
59
+ Err ( _) => return false ,
60
+ } ;
61
+
62
+ let components = components. iter ( ) . map ( |c| c. as_str ( ) ) . collect :: < Vec < _ > > ( ) ;
63
+ match components. as_slice ( ) {
64
+ // The indexes could be updated during the build. The index is not considered a cache
65
+ // though, so it's fine to ignore it during the comparison.
66
+ [ "cargo-home" , "registry" , "index" , _, ".git" , ..] => true ,
67
+ [ "cargo-home" , "registry" , "index" , _, ".cargo-index-lock" ] => true ,
68
+ [ "cargo-home" , "registry" , "index" , _, ".last-updated" ] => true ,
69
+
70
+ _ => false ,
71
+ }
72
+ }
73
+
51
74
#[ derive( Debug , PartialEq , Eq ) ]
52
75
struct WorkspaceContents {
76
+ base : PathBuf ,
53
77
files : HashMap < PathBuf , Digest > ,
54
78
}
55
79
@@ -69,7 +93,10 @@ impl WorkspaceContents {
69
93
files. insert ( entry. path ( ) . into ( ) , sha. digest ( ) ) ;
70
94
}
71
95
72
- Ok ( Self { files } )
96
+ Ok ( Self {
97
+ base : path. into ( ) ,
98
+ files,
99
+ } )
73
100
}
74
101
75
102
fn assert_same ( self , mut other : Self ) {
@@ -78,6 +105,10 @@ impl WorkspaceContents {
78
105
println ! ( "=== start directory differences ===" ) ;
79
106
80
107
for ( path, start_digest) in self . files . into_iter ( ) {
108
+ if should_ignore ( & self . base , & path) {
109
+ continue ;
110
+ }
111
+
81
112
if let Some ( end_digest) = other. files . remove ( & path) {
82
113
if start_digest != end_digest {
83
114
println ! ( "file {} changed" , path. display( ) ) ;
@@ -90,6 +121,10 @@ impl WorkspaceContents {
90
121
}
91
122
92
123
for ( path, _) in other. files . into_iter ( ) {
124
+ if should_ignore ( & other. base , & path) {
125
+ continue ;
126
+ }
127
+
93
128
println ! ( "file {} was added" , path. display( ) ) ;
94
129
same = false ;
95
130
}
0 commit comments