Adrian Heine
8 years ago
24 changed files with 108 additions and 193 deletions
-
2Cargo.toml
-
23src/command_runner.rs
-
1src/lib.rs
-
25src/symbols/acme/account_key.rs
-
33src/symbols/acme/cert.rs
-
13src/symbols/git/checkout.rs
-
9src/symbols/git/submodules.rs
-
10src/symbols/mariadb/database.rs
-
10src/symbols/mariadb/database_dump.rs
-
7src/symbols/mariadb/user.rs
-
2src/symbols/mod.rs
-
3src/symbols/nginx/server.rs
-
44src/symbols/not_a_symlink.rs
-
7src/symbols/npm.rs
-
3src/symbols/owner.rs
-
24src/symbols/stored_directory.rs
-
2src/symbols/systemd/node_js_user_service.rs
-
3src/symbols/systemd/reload.rs
-
10src/symbols/systemd/user_session.rs
-
16src/symbols/tls/csr.rs
-
20src/symbols/tls/key.rs
-
19src/symbols/tls/self_signed_cert.rs
-
7src/symbols/user.rs
-
2src/symbols/wordpress/translation.rs
@ -1,44 +0,0 @@ |
|||||
use std::error::Error;
|
|
||||
use std::fmt;
|
|
||||
use std::fs;
|
|
||||
use std::io;
|
|
||||
|
|
||||
use symbols::Symbol;
|
|
||||
|
|
||||
pub struct NotASymlink<D> where D: AsRef<str> + fmt::Display {
|
|
||||
path: D
|
|
||||
}
|
|
||||
|
|
||||
impl<D> NotASymlink<D> where D: AsRef<str> + fmt::Display {
|
|
||||
pub fn new(path: D) -> Self {
|
|
||||
NotASymlink {
|
|
||||
path: path
|
|
||||
}
|
|
||||
}
|
|
||||
}
|
|
||||
|
|
||||
impl<D> Symbol for NotASymlink<D> where D: AsRef<str> + fmt::Display {
|
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
|
||||
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<Error>> {
|
|
||||
try!(fs::remove_file(self.path.as_ref()));
|
|
||||
Ok(())
|
|
||||
}
|
|
||||
}
|
|
||||
|
|
||||
impl<D> fmt::Display for NotASymlink<D> where D: AsRef<str> + fmt::Display {
|
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{
|
|
||||
write!(f, "NotASymlink {}", self.path)
|
|
||||
}
|
|
||||
}
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue