diff --git a/README.md b/README.md index 27c91ac..4f293f1 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,10 @@ [![Continuous integration](https://github.com/AdamIsrael/ieee-registry/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/AdamIsrael/ieee-registry/actions/workflows/ci.yaml) -Premise: To cache the IEEE Registries public listings to the users ~/.local directory in order to be used for lookup purposes. +The IEEE-Registry crate provides a locally cached copy of the IEEE Registration Authority's public listings in the current users `~/.local/share/ieee/` directory in order to be used for lookup purposes. + + +```rust +use ieee_registry::ieee::*; + +``` diff --git a/src/ieee/cid.rs b/src/cid.rs similarity index 100% rename from src/ieee/cid.rs rename to src/cid.rs diff --git a/src/ieee/eth.rs b/src/eth.rs similarity index 100% rename from src/ieee/eth.rs rename to src/eth.rs diff --git a/src/ieee/iab.rs b/src/iab.rs similarity index 100% rename from src/ieee/iab.rs rename to src/iab.rs diff --git a/src/ieee/mod.rs b/src/ieee/mod.rs deleted file mode 100644 index 8942301..0000000 --- a/src/ieee/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -mod cid; -mod eth; -mod iab; -mod mam; -mod manid; -mod opid; -mod oui; -mod oui36; -mod utils; - -pub use cid::get_cid_path; -pub use eth::get_eth_path; -pub use iab::get_iab_path; -pub use mam::get_mam_path; -pub use manid::get_manid_path; -pub use opid::get_opid_path; -pub use oui::get_oui_path; -pub use oui36::get_oui36_path; diff --git a/src/lib.rs b/src/lib.rs index 5834a31..8942301 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,16 +1,18 @@ -pub mod ieee; +mod cid; +mod eth; +mod iab; +mod mam; +mod manid; +mod opid; +mod oui; +mod oui36; +mod utils; -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} +pub use cid::get_cid_path; +pub use eth::get_eth_path; +pub use iab::get_iab_path; +pub use mam::get_mam_path; +pub use manid::get_manid_path; +pub use opid::get_opid_path; +pub use oui::get_oui_path; +pub use oui36::get_oui36_path; diff --git a/src/main.rs b/src/main.rs index 14647c1..6b281ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,16 @@ /// A CLI interface to the ieee-registry library -/// -/// -use ieee_registry::ieee::*; +use expanduser::expanduser; + +use ieee_registry::*; fn main() { - println!("Caching file(s)..."); - println!("\t{:?}", get_cid_path().unwrap()); - println!("\t{:?}", get_eth_path().unwrap()); - println!("\t{:?}", get_iab_path().unwrap()); - println!("\t{:?}", get_mam_path().unwrap()); - println!("\t{:?}", get_manid_path().unwrap()); - println!("\t{:?}", get_opid_path().unwrap()); - println!("\t{:?}", get_oui_path().unwrap()); - println!("\t{:?}", get_oui36_path().unwrap()); + println!("Caching IEEE registry file(s)..."); + println!("✔ {}", expanduser(get_cid_path().unwrap()).unwrap().display()); + println!("✔ {}", expanduser(get_eth_path().unwrap()).unwrap().display()); + println!("✔ {}", expanduser(get_iab_path().unwrap()).unwrap().display()); + println!("✔ {}", expanduser(get_mam_path().unwrap()).unwrap().display()); + println!("✔ {}", expanduser(get_manid_path().unwrap()).unwrap().display()); + println!("✔ {}", expanduser(get_opid_path().unwrap()).unwrap().display()); + println!("✔ {}", expanduser(get_oui_path().unwrap()).unwrap().display()); + println!("✔ {}", expanduser(get_oui36_path().unwrap()).unwrap().display()); } diff --git a/src/ieee/mam.rs b/src/mam.rs similarity index 100% rename from src/ieee/mam.rs rename to src/mam.rs diff --git a/src/ieee/manid.rs b/src/manid.rs similarity index 100% rename from src/ieee/manid.rs rename to src/manid.rs diff --git a/src/ieee/opid.rs b/src/opid.rs similarity index 100% rename from src/ieee/opid.rs rename to src/opid.rs diff --git a/src/ieee/oui.rs b/src/oui.rs similarity index 100% rename from src/ieee/oui.rs rename to src/oui.rs diff --git a/src/ieee/oui36.rs b/src/oui36.rs similarity index 100% rename from src/ieee/oui36.rs rename to src/oui36.rs diff --git a/src/ieee/utils.rs b/src/utils.rs similarity index 88% rename from src/ieee/utils.rs rename to src/utils.rs index fb8b039..2f20d43 100644 --- a/src/ieee/utils.rs +++ b/src/utils.rs @@ -10,18 +10,18 @@ const MAX_AGE: u64 = 86400 * 30; /// Download the file to a specific destination pub fn download(url: &str, destination: &str) -> BoxResult<()> { - // If the file exists and is less than MAX_AGE, don't download it again - if metadata(destination).is_ok() { - let age = age(destination)?; + let path = expanduser(destination)?; + + // Short-circuit if the file is already downloaded and less than MAX_AGE old + if let Ok(age) = age(path.clone().into_os_string().to_str().unwrap()) { if age < MAX_AGE { return Ok(()); } } + // Download the file match reqwest::blocking::get(url) { Ok(response) => { - let path = expanduser(destination)?; - // make sure the path exists create_dir_all(path.parent().unwrap())?; @@ -66,7 +66,8 @@ mod tests { let md = fs::metadata(tmp).unwrap(); assert_ne!(0, md.len()); } - Err(_) => { + Err(e) => { + println!("Error: {}", e); assert!(false); } }