use std::error::Error; use std::fmt; use std::fs; use std::io; use std::ops::Deref; use std::path::Path; use symbols::Symbol; use resources::{DirResource, Resource}; pub struct NotASymlink where D: AsRef + fmt::Display { path: D } impl NotASymlink where D: AsRef + fmt::Display { pub fn new(path: D) -> Self { NotASymlink { path: path } } } impl Symbol for NotASymlink where D: AsRef + fmt::Display { fn target_reached(&self) -> Result> { let metadata = fs::symlink_metadata(self.path.as_ref()); // Check if file exists if let Err(e) = metadata { return if e.kind() == io::ErrorKind::NotFound { Ok(true) } else { Err(Box::new(e)) }; } Ok(!metadata.unwrap().file_type().is_symlink()) } fn execute(&self) -> Result<(), Box> { try!(fs::remove_file(self.path.as_ref())); Ok(()) } } impl fmt::Display for NotASymlink where D: AsRef + fmt::Display { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{ write!(f, "NotASymlink {}", self.path) } }