1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use crate::constants;
use std::ffi::OsStr;
use std::fs;
use std::path::{Path, PathBuf};
#[allow(clippy::branches_sharing_code)]
pub fn find_manifest_dir(starter_path: &Path) -> Option<PathBuf> {
let mut path = std::fs::canonicalize(starter_path).ok()?;
let empty_path = PathBuf::from("/");
while path != empty_path {
path.push(crate::constants::MANIFEST_FILE_NAME);
if path.exists() {
path.pop();
return Some(path);
} else {
path.pop();
path.pop();
}
}
None
}
pub fn get_sway_files(path: PathBuf) -> Vec<PathBuf> {
let mut files = vec![];
let mut dir_entries = vec![path];
while let Some(next_dir) = dir_entries.pop() {
if let Ok(read_dir) = fs::read_dir(next_dir) {
for entry in read_dir.filter_map(|res| res.ok()) {
let path = entry.path();
if path.is_dir() {
dir_entries.push(path);
} else if is_sway_file(&path) {
files.push(path)
}
}
}
}
files
}
pub fn is_sway_file(file: &Path) -> bool {
let res = file.extension();
Some(OsStr::new(constants::SWAY_EXTENSION)) == res
}