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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#![forbid(unsafe_code)]
#![doc = include_str!("../README.md")]
pub mod build;
pub mod imports;
pub mod inputs;
pub mod outputs;
pub mod package;
pub mod root;
pub mod source;
use leo_errors::{PackageError, Result};
use std::fs::ReadDir;
use std::{fs, path::PathBuf};
pub static LEO_FILE_EXTENSION: &str = ".leo";
pub(crate) fn parse_file_paths(directory: ReadDir, file_paths: &mut Vec<PathBuf>) -> Result<()> {
for file_entry in directory {
let file_entry = file_entry.map_err(PackageError::failed_to_get_leo_file_entry)?;
let file_path = file_entry.path();
if file_path.is_dir() {
let directory =
fs::read_dir(&file_path).map_err(|err| PackageError::failed_to_read_file(file_path.display(), err))?;
parse_file_paths(directory, file_paths)?;
continue;
} else {
let file_extension = file_path
.extension()
.ok_or_else(|| PackageError::failed_to_get_leo_file_extension(file_path.as_os_str().to_owned()))?;
if file_extension != LEO_FILE_EXTENSION.trim_start_matches('.') {
return Err(PackageError::invalid_leo_file_extension(
file_path.as_os_str().to_owned(),
file_extension.to_owned(),
)
.into());
}
file_paths.push(file_path);
}
}
Ok(())
}