@@ -33,6 +33,7 @@ fn get_paths_for(format: Option<FileType>, file_path: &Path) -> anyhow::Result<V
33
33
fn get_paths_of_interest (
34
34
format : Option < FileType > ,
35
35
file_path : & Path ,
36
+ ignore : Option < String > ,
36
37
) -> anyhow:: Result < Vec < PathBuf > > {
37
38
let paths = if file_path. is_file ( ) {
38
39
// single file case
@@ -55,6 +56,15 @@ fn get_paths_of_interest(
55
56
unique. into_iter ( ) . collect :: < Vec < PathBuf > > ( )
56
57
} ;
57
58
59
+ let paths = if let Some ( ignore_pattern) = ignore {
60
+ paths
61
+ . into_iter ( )
62
+ . filter ( |path| !path. to_string_lossy ( ) . contains ( & ignore_pattern) )
63
+ . collect ( )
64
+ } else {
65
+ paths
66
+ } ;
67
+
58
68
if paths. is_empty ( ) {
59
69
return Err ( anyhow ! ( "no compatible paths found" ) ) ;
60
70
}
@@ -79,7 +89,7 @@ pub(crate) fn sign(args: SignArgs) -> anyhow::Result<()> {
79
89
// load the private key for signing
80
90
let signing_key = crate :: core:: signing:: load_key ( & args. key_path ) ?;
81
91
// get the paths to sign
82
- let mut paths_to_sign = get_paths_of_interest ( args. format , & args. file_path ) ?;
92
+ let mut paths_to_sign = get_paths_of_interest ( args. format , & args. file_path , args . ignore ) ?;
83
93
let base_path = if args. file_path . is_file ( ) {
84
94
args. file_path . parent ( ) . unwrap ( ) . to_path_buf ( )
85
95
} else {
@@ -119,7 +129,7 @@ pub(crate) fn verify(args: VerifyArgs) -> anyhow::Result<()> {
119
129
// load the public key to verify against
120
130
let mut manifest = Manifest :: from_public_key_path ( & base_path, & args. key_path ) ?;
121
131
// get the paths to verify
122
- let mut paths_to_verify = get_paths_of_interest ( args. format , & args. file_path ) ?;
132
+ let mut paths_to_verify = get_paths_of_interest ( args. format , & args. file_path , args . ignore ) ?;
123
133
// remove the signature file from the list
124
134
paths_to_verify. retain ( |p| p != & signature_path) ;
125
135
@@ -144,7 +154,7 @@ mod tests {
144
154
145
155
File :: create ( & file_path) ?;
146
156
147
- let paths = get_paths_of_interest ( None , & file_path) ?;
157
+ let paths = get_paths_of_interest ( None , & file_path, None ) ?;
148
158
assert_eq ! ( paths. len( ) , 1 ) ;
149
159
assert_eq ! ( paths[ 0 ] , file_path. canonicalize( ) ?) ;
150
160
@@ -160,7 +170,7 @@ mod tests {
160
170
File :: create ( temp_dir. path ( ) . join ( "model.bin" ) ) ?;
161
171
File :: create ( temp_dir. path ( ) . join ( "other.txt" ) ) ?;
162
172
163
- let paths = get_paths_of_interest ( None , temp_dir. path ( ) ) ?;
173
+ let paths = get_paths_of_interest ( None , temp_dir. path ( ) , None ) ?;
164
174
assert_eq ! ( paths. len( ) , 3 ) ;
165
175
166
176
// Sort paths for consistent comparison
@@ -186,6 +196,7 @@ mod tests {
186
196
let paths = get_paths_of_interest (
187
197
Some ( FileType :: SafeTensors ) ,
188
198
& temp_dir. path ( ) . join ( "model.custom" ) ,
199
+ None ,
189
200
) ?;
190
201
assert_eq ! ( paths. len( ) , 1 ) ;
191
202
assert ! ( paths[ 0 ] . to_string_lossy( ) . ends_with( "model.custom" ) ) ;
@@ -202,7 +213,7 @@ mod tests {
202
213
File :: create ( temp_dir. path ( ) . join ( "model-00002-of-00002.safetensors" ) ) ?;
203
214
File :: create ( temp_dir. path ( ) . join ( "other.txt" ) ) ?;
204
215
205
- let paths = get_paths_of_interest ( None , temp_dir. path ( ) ) ?;
216
+ let paths = get_paths_of_interest ( None , temp_dir. path ( ) , None ) ?;
206
217
assert_eq ! ( paths. len( ) , 3 ) ;
207
218
208
219
let mut paths: Vec < String > = paths
@@ -225,7 +236,7 @@ mod tests {
225
236
226
237
#[ test]
227
238
fn test_get_paths_nonexistent ( ) {
228
- let result = get_paths_of_interest ( None , & PathBuf :: from ( "/nonexistent/path" ) ) ;
239
+ let result = get_paths_of_interest ( None , & PathBuf :: from ( "/nonexistent/path" ) , None ) ;
229
240
assert ! ( result. is_err( ) ) ;
230
241
}
231
242
@@ -246,7 +257,7 @@ mod tests {
246
257
File :: create ( deep_dir. join ( ".very_hidden" ) ) ?;
247
258
File :: create ( deep_dir. join ( "deep.dat" ) ) ?;
248
259
249
- let paths = get_paths_of_interest ( None , temp_dir. path ( ) ) ?;
260
+ let paths = get_paths_of_interest ( None , temp_dir. path ( ) , None ) ?;
250
261
assert_eq ! ( paths. len( ) , 6 ) ; // Should find all 6 files
251
262
252
263
let mut paths: Vec < String > = paths
@@ -277,7 +288,7 @@ mod tests {
277
288
File :: create ( & file_path) ?;
278
289
279
290
// Get paths using absolute path first to verify it works
280
- let paths = get_paths_of_interest ( None , & file_path) ?;
291
+ let paths = get_paths_of_interest ( None , & file_path, None ) ?;
281
292
assert_eq ! ( paths. len( ) , 1 ) ;
282
293
let canonical_path = file_path. canonicalize ( ) ?;
283
294
assert_eq ! ( & paths[ 0 ] , & canonical_path) ;
@@ -287,7 +298,7 @@ mod tests {
287
298
288
299
// Get paths using relative path
289
300
let relative_path = PathBuf :: from ( "test.txt" ) ;
290
- let paths = get_paths_of_interest ( None , & relative_path) ?;
301
+ let paths = get_paths_of_interest ( None , & relative_path, None ) ?;
291
302
292
303
assert_eq ! ( paths. len( ) , 1 ) ;
293
304
let returned_path = & paths[ 0 ] ;
@@ -298,4 +309,28 @@ mod tests {
298
309
299
310
Ok ( ( ) )
300
311
}
312
+
313
+ #[ test]
314
+ fn test_paths_with_huggingface_cache_ignore ( ) -> anyhow:: Result < ( ) > {
315
+ let temp_dir = TempDir :: new ( ) ?;
316
+
317
+ // Create a .cache/huggingface directory with a file
318
+ let cache_dir = temp_dir. path ( ) . join ( ".cache" ) . join ( "huggingface" ) ;
319
+ std:: fs:: create_dir_all ( & cache_dir) ?;
320
+ File :: create ( cache_dir. join ( "cached_file.bin" ) ) ?;
321
+
322
+ // Create a regular file
323
+ let regular_file = temp_dir. path ( ) . join ( "model.onnx" ) ;
324
+ File :: create ( & regular_file) ?;
325
+
326
+ // Get paths with huggingface cache ignore pattern
327
+ let paths =
328
+ get_paths_of_interest ( None , & regular_file, Some ( ".cache/huggingface" . to_string ( ) ) ) ?;
329
+
330
+ // Should only return the regular file
331
+ assert_eq ! ( paths. len( ) , 1 ) ;
332
+ assert_eq ! ( & paths[ 0 ] , & regular_file. canonicalize( ) ?) ;
333
+
334
+ Ok ( ( ) )
335
+ }
301
336
}
0 commit comments