diff --git a/Cargo.lock b/Cargo.lock index 3b2c0d3b..0dc4cada 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1140,8 +1140,8 @@ dependencies = [ ] [[package]] -name = "result" -version = "1.0.0" +name = "rust-ini" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1261,16 +1261,6 @@ dependencies = [ "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "serde_ini" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "result 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "serde_json" version = "1.0.39" @@ -1596,9 +1586,9 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-ini 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "self_update 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_ini 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "shellexpand 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1945,7 +1935,7 @@ dependencies = [ "checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum reqwest 0.9.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ddcfd2c13c6af0f9c45a1086be3b9c68af79e4430b42790759e2d34cce2a6c60" -"checksum result 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "194d8e591e405d1eecf28819740abed6d719d1a2db87fc0bcdedee9a26d55560" +"checksum rust-ini 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2" "checksum rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc78bfd5acd7bf3e89cffcf899e5cb1a52d6fafa8dec2739ad70c9577a57288" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" @@ -1961,7 +1951,6 @@ dependencies = [ "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)" = "a72e9b96fa45ce22a4bc23da3858dfccfd60acd28a25bcd328a98fdd6bea43fd" "checksum serde_derive 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)" = "101b495b109a3e3ca8c4cbe44cf62391527cdfb6ba15821c5ce80bcd5ea23f9f" -"checksum serde_ini 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eb236687e2bb073a7521c021949be944641e671b8505a94069ca37b656c81139" "checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" "checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a" "checksum shellexpand 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de7a5b5a9142fd278a10e0209b021a1b85849352e6951f4f914735c976737564" diff --git a/Cargo.toml b/Cargo.toml index 05a8e592..58197a68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ walkdir = "2.2.7" console = "0.7.5" self_update_crate = { version = "0.5.1", optional = true, package = "self_update" } lazy_static = "1.2.0" -serde_ini = "0.2.0" +rust-ini = "0.13.0" [target.'cfg(unix)'.dependencies] nix = "0.13.0" diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index 6635a9ff..cbf28f4f 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -3,9 +3,8 @@ use crate::executor::RunType; use crate::terminal::{print_separator, print_warning}; use crate::utils::{require, require_option, which}; use failure::ResultExt; +use ini::Ini; use serde::Deserialize; -use serde_ini; -use std::fs; use std::path::PathBuf; use walkdir::WalkDir; @@ -31,26 +30,25 @@ pub enum Distribution { } impl Distribution { - fn parse_os_release(os_release: &OsRelease) -> Result { - Ok( - match (os_release.id.as_ref(), os_release.id_like.as_ref().map(String::as_str)) { - ("debian", _) | (_, Some("debian")) | (_, Some("ubuntu")) => Distribution::Debian, - (_, Some("\"suse\"")) => Distribution::Suse, - ("arch", _) | (_, Some("archlinux")) | (_, Some("\"arch\"")) | (_, Some("arch")) => Distribution::Arch, - ("\"centos\"", _) | ("\"ol\"", _) => Distribution::CentOS, - ("fedora", _) => Distribution::Fedora, - ("void", _) => Distribution::Void, - ("solus", _) => Distribution::Solus, - _ => Err(ErrorKind::UnknownLinuxDistribution)?, - }, - ) + fn parse_os_release(os_release: &ini::Ini) -> Result { + let section = os_release.section::<&str>(None).unwrap(); + let id = section.get("ID").map(String::as_str); + let id_like = section.get("ID_LIKE").map(String::as_str); + Ok(match (id, id_like) { + (Some("debian"), _) | (_, Some("debian")) | (_, Some("ubuntu")) => Distribution::Debian, + (_, Some("suse")) => Distribution::Suse, + (Some("arch"), _) | (_, Some("archlinux")) | (_, Some("arch")) => Distribution::Arch, + (Some("centos"), _) | (Some("ol"), _) => Distribution::CentOS, + (Some("fedora"), _) => Distribution::Fedora, + (Some("void"), _) => Distribution::Void, + (Some("solus"), _) => Distribution::Solus, + _ => Err(ErrorKind::UnknownLinuxDistribution)?, + }) } pub fn detect() -> Result { if PathBuf::from(OS_RELEASE_PATH).exists() { - let os_release: OsRelease = - serde_ini::de::from_read(fs::File::open(OS_RELEASE_PATH).context(ErrorKind::UnknownLinuxDistribution)?) - .context(ErrorKind::UnknownLinuxDistribution)?; + let os_release = Ini::load_from_file(OS_RELEASE_PATH).context(ErrorKind::UnknownLinuxDistribution)?; return Self::parse_os_release(&os_release); } @@ -334,7 +332,7 @@ mod tests { use super::*; fn test_template(os_release_file: &str, expected_distribution: Distribution) { - let os_release: OsRelease = serde_ini::de::from_str(os_release_file).unwrap(); + let os_release = Ini::load_from_str(os_release_file).unwrap(); assert_eq!( Distribution::parse_os_release(&os_release).unwrap(), expected_distribution