1#[allow(unused)]
2use {
3 anyhow::{Error, Result},
4 std::fs,
5 std::path::{Path, PathBuf},
6};
7
8pub fn scan_dir(p: &Path, cb: &mut dyn FnMut(PathBuf) -> bool) {
9 if p.is_dir() {
10 if let Ok(entrys) = fs::read_dir(p) {
11 for entry in entrys.flatten() {
12 if !cb(entry.path()) {
13 break;
14 }
15 }
16 }
17 }
18}
19
20pub fn scan_dir_for_dir(p: &Path, cb: &mut dyn FnMut(PathBuf) -> bool) {
21 if p.is_dir() {
22 if let Ok(entrys) = fs::read_dir(p) {
23 for entry in entrys.flatten() {
24 let p = entry.path();
25 if p.is_dir() && !cb(p) {
26 break;
27 }
28 }
29 }
30 }
31}
32
33pub fn scan_dir_for_file(p: &Path, cb: &mut dyn FnMut(PathBuf) -> Result<()>) -> Result<()> {
34 if p.is_dir() {
35 if let Ok(entrys) = fs::read_dir(p) {
36 for entry in entrys.flatten() {
37 let p = entry.path();
38 if p.is_file() {
39 cb(p)?;
40 }
41 }
42 }
43 }
44
45 Ok(())
46}
47
48pub fn verify_content(content: String) -> Option<String> {
49 let content = content.trim();
50 if !content.is_empty() {
51 Some(content.to_string())
52 } else {
53 None
54 }
55}