1#[allow(unused)]
2use {
3 crate::recipe::Recipe,
4 crate::utils::{scan_dir, scan_dir_for_dir, scan_dir_for_file, verify_content},
5 anyhow::{Context, Error, Result},
6 jlogger::{jdebug, jerror, jinfo, jwarn},
7 log::{debug, error, info, warn},
8 std::collections::HashMap,
9 std::env,
10 std::ffi::OsStr,
11 std::fmt::Display,
12 std::fs,
13 std::path::{Path, PathBuf},
14};
15
16pub struct MetaTopDir {
17 topdir: String,
18}
19
20impl MetaTopDir {
21 pub fn new(dir: &str) -> Result<Self> {
22 let meta_top = fs::canonicalize(dir)?;
23 let mut result = false;
24
25 if meta_top.is_dir() {
26 scan_dir(meta_top.as_path(), &mut |dp: PathBuf| -> bool {
27 if let Some(a) = dp.file_name() {
28 if a == OsStr::new("poky") {
29 result = true;
30 return false;
31 }
32 }
33 true
34 });
35 }
36
37 if !result {
38 return Err(Error::msg("Invalid meta top directory."));
39 }
40
41 Ok(MetaTopDir {
42 topdir: meta_top.to_str().unwrap().to_string(),
43 })
44 }
45
46 pub fn as_str(&self) -> &str {
47 self.topdir.as_str()
48 }
49
50 pub fn pathbuf(&self) -> PathBuf {
51 Path::new(self.topdir.as_str()).to_path_buf()
52 }
53}
54
55impl Display for MetaTopDir {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 write!(f, "{}", self.topdir)
58 }
59}