scancode_rust/utils/
file.rs1use chrono::{TimeZone, Utc};
2use glob::Pattern;
3use std::fs;
4use std::path::Path;
5
6pub fn get_creation_date(metadata: &fs::Metadata) -> Option<String> {
8 metadata.created().ok().map(|time: std::time::SystemTime| {
9 let seconds_since_epoch = time
10 .duration_since(std::time::UNIX_EPOCH)
11 .unwrap()
12 .as_secs() as i64;
13
14 Utc.timestamp_opt(seconds_since_epoch, 0)
15 .single()
16 .unwrap_or_else(|| Utc::now())
17 .to_rfc3339()
18 })
19}
20
21pub fn is_path_excluded(path: &Path, exclude_patterns: &[Pattern]) -> bool {
23 let path_str = path.to_string_lossy();
24 let file_name = path
25 .file_name()
26 .map(|name| name.to_string_lossy())
27 .unwrap_or_default();
28
29 for pattern in exclude_patterns {
30 if pattern.matches(&path_str) {
32 return true;
33 }
34
35 if pattern.matches(&file_name) {
37 return true;
38 }
39 }
40
41 false
42}