Skip to content
exec.rs 1.73 KiB
Newer Older
Luker's avatar
Luker committed
/*
 * Copyright (c) 2021, Luca Fulchir <luker@fenrirproject.org>
 *
 * This file is part of dfim.
 *
 * dfim is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * dfim is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with dfim.  If not, see <https://www.gnu.org/licenses/>.
 */

Luker's avatar
Luker committed
const fn def_dry_run() -> bool {
Luker's avatar
Luker committed
    false
}

#[derive(::serde::Deserialize, ::serde::Serialize, Clone)]
Luker's avatar
Luker committed
#[serde(deny_unknown_fields)]
pub struct Exec {
    pub id: String,
    pub path: ::std::path::PathBuf,
Luker's avatar
Luker committed
    #[serde(skip, default = "def_dry_run")]
Luker's avatar
Luker committed
    pub supports_dry_run: bool,
Luker's avatar
Luker committed
}

impl super::TargetCommon for Exec {
Luker's avatar
Luker committed
    fn id(&self) -> &str {
        self.id.as_str()
    }
    fn targets(&self) -> Vec<String> {
        Vec::new()
    }
}

impl crate::config::CfgVerify for Exec {
    fn standardize(&mut self) {}
    fn check_consistency(
        &self,
        logger: &slog::Logger,
    ) -> Result<(), crate::config::errors::ConfigError> {
        if !self.path.is_file() {
            ::slog::error!(logger, "Exec: no such file \"{:?}\"", self.path);
            return Err(crate::config::errors::ConfigError::Consistency(
                "No such file".to_owned(),
            ));
        }
        Ok(())
    }
}
Luker's avatar
Luker committed

impl PartialEq<Exec> for Exec {
    fn eq(&self, other: &Self) -> bool {
        self.path == other.path
    }
}