1
0

lib.rs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #[macro_use]
  2. extern crate lazy_static;
  3. use std::collections::HashMap;
  4. use crate::fs::mounts::MountedFs;
  5. use proc_mounts::MountList;
  6. use std::path::PathBuf;
  7. // A lazily initialised static map of all mounted file systems.
  8. //
  9. // The map contains a mapping from the mounted directory path to the
  10. // corresponding mount information. On Linux systems, this map is populated
  11. // using the `proc-mounts` crate. If there's an error retrieving the mount
  12. // list or if we're not running on Linux, the map will be empty.
  13. //
  14. // Initialise this at application start so we don't have to look the details
  15. // up for every directory. Ideally this would only be done if the --mounts
  16. // option is specified which will be significantly easier once the move
  17. // to `clap` is complete.
  18. lazy_static! {
  19. static ref ALL_MOUNTS: HashMap<PathBuf, MountedFs> = {
  20. #[cfg(target_os = "linux")]
  21. match MountList::new() {
  22. Ok(mount_list) => {
  23. let mut m = HashMap::new();
  24. mount_list.0.iter().for_each(|mount| {
  25. m.insert(mount.dest.clone(), MountedFs {
  26. dest: mount.dest.to_string_lossy().into_owned(),
  27. fstype: mount.fstype.clone(),
  28. source: mount.source.to_string_lossy().into(),
  29. });
  30. });
  31. m
  32. }
  33. Err(_) => HashMap::new()
  34. }
  35. #[cfg(not(target_os = "linux"))]
  36. HashMap::new()
  37. };
  38. }
  39. #[allow(unused)]
  40. pub mod fs;
  41. #[allow(unused)]
  42. pub mod info;
  43. #[allow(unused)]
  44. pub mod logger;
  45. #[allow(unused)]
  46. pub mod options;
  47. #[allow(unused)]
  48. pub mod output;
  49. #[allow(unused)]
  50. pub mod theme;