diff --git a/src/dist/temp.rs b/src/dist/temp.rs index e5eb54b1e5..ac10c1d72e 100644 --- a/src/dist/temp.rs +++ b/src/dist/temp.rs @@ -22,24 +22,29 @@ pub(crate) enum CreatingError { } #[derive(Debug)] -pub enum Notification<'a> { - CreatingRoot(&'a Path), - CreatingFile(&'a Path), - CreatingDirectory(&'a Path), - FileDeletion(&'a Path, io::Result<()>), - DirectoryDeletion(&'a Path, io::Result<()>), +pub(crate) struct Dir<'a> { + cfg: &'a Cfg, + path: PathBuf, } -pub struct Cfg { - root_directory: PathBuf, - pub dist_server: String, - notify_handler: Box)>, +impl<'a> ops::Deref for Dir<'a> { + type Target = Path; + + fn deref(&self) -> &Path { + self.path.as_path() + } } -#[derive(Debug)] -pub(crate) struct Dir<'a> { - cfg: &'a Cfg, - path: PathBuf, +impl<'a> Drop for Dir<'a> { + fn drop(&mut self) { + if raw::is_directory(&self.path) { + let n = Notification::DirectoryDeletion( + &self.path, + remove_dir_all::remove_dir_all(&self.path), + ); + (self.cfg.notify_handler)(n); + } + } } #[derive(Debug)] @@ -48,6 +53,32 @@ pub struct File<'a> { path: PathBuf, } +impl<'a> ops::Deref for File<'a> { + type Target = Path; + + fn deref(&self) -> &Path { + self.path.as_path() + } +} + +impl<'a> Drop for File<'a> { + fn drop(&mut self) { + if raw::is_file(&self.path) { + let n = Notification::FileDeletion(&self.path, fs::remove_file(&self.path)); + (self.cfg.notify_handler)(n); + } + } +} + +#[derive(Debug)] +pub enum Notification<'a> { + CreatingRoot(&'a Path), + CreatingFile(&'a Path), + CreatingDirectory(&'a Path), + FileDeletion(&'a Path, io::Result<()>), + DirectoryDeletion(&'a Path, io::Result<()>), +} + impl<'a> Notification<'a> { pub(crate) fn level(&self) -> NotificationLevel { use self::Notification::*; @@ -89,6 +120,12 @@ impl<'a> Display for Notification<'a> { } } +pub struct Cfg { + root_directory: PathBuf, + pub dist_server: String, + notify_handler: Box)>, +} + impl Cfg { pub fn new( root_directory: PathBuf, @@ -170,40 +207,3 @@ impl fmt::Debug for Cfg { .finish() } } - -impl<'a> ops::Deref for Dir<'a> { - type Target = Path; - - fn deref(&self) -> &Path { - self.path.as_path() - } -} - -impl<'a> ops::Deref for File<'a> { - type Target = Path; - - fn deref(&self) -> &Path { - self.path.as_path() - } -} - -impl<'a> Drop for Dir<'a> { - fn drop(&mut self) { - if raw::is_directory(&self.path) { - let n = Notification::DirectoryDeletion( - &self.path, - remove_dir_all::remove_dir_all(&self.path), - ); - (self.cfg.notify_handler)(n); - } - } -} - -impl<'a> Drop for File<'a> { - fn drop(&mut self) { - if raw::is_file(&self.path) { - let n = Notification::FileDeletion(&self.path, fs::remove_file(&self.path)); - (self.cfg.notify_handler)(n); - } - } -}