Use rust_ini instead of serde_ini

serde_ini isn't very popular and doesn't strip quotes from the values
This commit is contained in:
Roey Darwish Dror
2019-05-16 15:29:35 +03:00
parent 9e89bfc84b
commit 763e8b84eb
3 changed files with 22 additions and 35 deletions

19
Cargo.lock generated
View File

@@ -1140,8 +1140,8 @@ dependencies = [
] ]
[[package]] [[package]]
name = "result" name = "rust-ini"
version = "1.0.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
@@ -1261,16 +1261,6 @@ dependencies = [
"syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.39" version = "1.0.39"
@@ -1596,9 +1586,9 @@ dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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 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)", "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)", "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)", "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 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 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 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-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 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" "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 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 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_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_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 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" "checksum shellexpand 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de7a5b5a9142fd278a10e0209b021a1b85849352e6951f4f914735c976737564"

View File

@@ -25,7 +25,7 @@ walkdir = "2.2.7"
console = "0.7.5" console = "0.7.5"
self_update_crate = { version = "0.5.1", optional = true, package = "self_update" } self_update_crate = { version = "0.5.1", optional = true, package = "self_update" }
lazy_static = "1.2.0" lazy_static = "1.2.0"
serde_ini = "0.2.0" rust-ini = "0.13.0"
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
nix = "0.13.0" nix = "0.13.0"

View File

@@ -3,9 +3,8 @@ use crate::executor::RunType;
use crate::terminal::{print_separator, print_warning}; use crate::terminal::{print_separator, print_warning};
use crate::utils::{require, require_option, which}; use crate::utils::{require, require_option, which};
use failure::ResultExt; use failure::ResultExt;
use ini::Ini;
use serde::Deserialize; use serde::Deserialize;
use serde_ini;
use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
use walkdir::WalkDir; use walkdir::WalkDir;
@@ -31,26 +30,25 @@ pub enum Distribution {
} }
impl Distribution { impl Distribution {
fn parse_os_release(os_release: &OsRelease) -> Result<Self, Error> { fn parse_os_release(os_release: &ini::Ini) -> Result<Self, Error> {
Ok( let section = os_release.section::<&str>(None).unwrap();
match (os_release.id.as_ref(), os_release.id_like.as_ref().map(String::as_str)) { let id = section.get("ID").map(String::as_str);
("debian", _) | (_, Some("debian")) | (_, Some("ubuntu")) => Distribution::Debian, let id_like = section.get("ID_LIKE").map(String::as_str);
(_, Some("\"suse\"")) => Distribution::Suse, Ok(match (id, id_like) {
("arch", _) | (_, Some("archlinux")) | (_, Some("\"arch\"")) | (_, Some("arch")) => Distribution::Arch, (Some("debian"), _) | (_, Some("debian")) | (_, Some("ubuntu")) => Distribution::Debian,
("\"centos\"", _) | ("\"ol\"", _) => Distribution::CentOS, (_, Some("suse")) => Distribution::Suse,
("fedora", _) => Distribution::Fedora, (Some("arch"), _) | (_, Some("archlinux")) | (_, Some("arch")) => Distribution::Arch,
("void", _) => Distribution::Void, (Some("centos"), _) | (Some("ol"), _) => Distribution::CentOS,
("solus", _) => Distribution::Solus, (Some("fedora"), _) => Distribution::Fedora,
_ => Err(ErrorKind::UnknownLinuxDistribution)?, (Some("void"), _) => Distribution::Void,
}, (Some("solus"), _) => Distribution::Solus,
) _ => Err(ErrorKind::UnknownLinuxDistribution)?,
})
} }
pub fn detect() -> Result<Self, Error> { pub fn detect() -> Result<Self, Error> {
if PathBuf::from(OS_RELEASE_PATH).exists() { if PathBuf::from(OS_RELEASE_PATH).exists() {
let os_release: OsRelease = let os_release = Ini::load_from_file(OS_RELEASE_PATH).context(ErrorKind::UnknownLinuxDistribution)?;
serde_ini::de::from_read(fs::File::open(OS_RELEASE_PATH).context(ErrorKind::UnknownLinuxDistribution)?)
.context(ErrorKind::UnknownLinuxDistribution)?;
return Self::parse_os_release(&os_release); return Self::parse_os_release(&os_release);
} }
@@ -334,7 +332,7 @@ mod tests {
use super::*; use super::*;
fn test_template(os_release_file: &str, expected_distribution: Distribution) { 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!( assert_eq!(
Distribution::parse_os_release(&os_release).unwrap(), Distribution::parse_os_release(&os_release).unwrap(),
expected_distribution expected_distribution