From b8518f6d481b7aea3afbe2e1a74c6e0fd9970d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Mon, 29 Aug 2022 17:17:29 +0200 Subject: [PATCH] flake-info: fix compilation warnings (#503) Removes some dead code, including the unimplemented `--elastic-user`, `--elastic-pw` and `--gc` flags. Builds and tests with no warnings. --- flake-info/src/bin/flake-info.rs | 58 ++++++++-------------- flake-info/src/commands/mod.rs | 2 - flake-info/src/commands/nix_flake_attrs.rs | 1 - flake-info/src/commands/nix_gc.rs | 54 -------------------- flake-info/src/commands/nixpkgs_info.rs | 2 +- flake-info/src/data/export.rs | 4 +- flake-info/src/data/import.rs | 12 ++--- flake-info/src/data/pandoc.rs | 1 - flake-info/src/data/source.rs | 4 +- flake-info/src/data/system.rs | 5 -- flake-info/src/elastic.rs | 15 ++---- flake-info/src/lib.rs | 2 - 12 files changed, 33 insertions(+), 127 deletions(-) delete mode 100644 flake-info/src/commands/nix_gc.rs diff --git a/flake-info/src/bin/flake-info.rs b/flake-info/src/bin/flake-info.rs index 2ac8154..3183fe3 100644 --- a/flake-info/src/bin/flake-info.rs +++ b/flake-info/src/bin/flake-info.rs @@ -1,19 +1,15 @@ use anyhow::{Context, Result}; -use commands::run_gc; use flake_info::commands::NixCheckError; -use flake_info::data::import::{Kind, NixOption}; -use flake_info::data::{self, Export, Nixpkgs, Source}; -use flake_info::elastic::{ElasticsearchError, ExistsStrategy}; -use flake_info::{commands, elastic}; +use flake_info::data::import::Kind; +use flake_info::data::{self, Export, Source}; +use flake_info::elastic::{self, ElasticsearchError, ExistsStrategy}; use lazy_static::lazy_static; -use log::{debug, error, info, warn}; -use semver::VersionReq; +use log::{error, info, warn}; use serde::Deserialize; use sha2::Digest; -use std::path::{Path, PathBuf}; -use std::ptr::hash; +use std::io; +use std::path::PathBuf; use std::str::FromStr; -use std::{fs, io}; use structopt::{clap::ArgGroup, StructOpt}; use thiserror::Error; use tokio::fs::File; @@ -58,9 +54,6 @@ enum Command { help = "Whether to use a temporary store or not. Located at /tmp/flake-info-store" )] temp_store: bool, - - #[structopt(long, help = "Whether to gc the store after info or not")] - gc: bool, }, #[structopt(about = "Import official nixpkgs channel")] Nixpkgs { @@ -95,9 +88,6 @@ enum Command { )] temp_store: bool, - #[structopt(long, help = "Whether to gc the store after info or not")] - gc: bool, - #[structopt(long, help = "Whether write an error report about failed packages")] report: bool, }, @@ -115,22 +105,21 @@ struct ElasticOpts { )] enable: bool, - #[structopt( - long, - short = "u", - env = "FI_ES_USER", - help = "Elasticsearch username (unimplemented)" - )] - elastic_user: Option, - - #[structopt( - long, - short = "p", - env = "FI_ES_PASSWORD", - help = "Elasticsearch password (unimplemented)" - )] - elastic_pw: Option, + // #[structopt( + // long, + // short = "u", + // env = "FI_ES_USER", + // help = "Elasticsearch username (unimplemented)" + // )] + // elastic_user: Option, + // #[structopt( + // long, + // short = "p", + // env = "FI_ES_PASSWORD", + // help = "Elasticsearch password (unimplemented)" + // )] + // elastic_pw: Option, #[structopt( long, env = "FI_ES_URL", @@ -222,11 +211,7 @@ async fn run_command( flake_info::commands::check_nix_version(env!("MIN_NIX_VERSION"))?; match command { - Command::Flake { - flake, - temp_store, - gc, - } => { + Command::Flake { flake, temp_store } => { let source = Source::Git { url: flake }; let (info, exports) = flake_info::process_flake(&source, &kind, temp_store, extra) .map_err(FlakeInfoError::Flake)?; @@ -271,7 +256,6 @@ async fn run_command( Command::Group { targets, temp_store, - gc, name, report, } => { diff --git a/flake-info/src/commands/mod.rs b/flake-info/src/commands/mod.rs index 1ad6420..3ed6098 100644 --- a/flake-info/src/commands/mod.rs +++ b/flake-info/src/commands/mod.rs @@ -1,10 +1,8 @@ mod nix_check_version; mod nix_flake_attrs; mod nix_flake_info; -mod nix_gc; mod nixpkgs_info; pub use nix_check_version::{check_nix_version, NixCheckError}; pub use nix_flake_attrs::get_derivation_info; pub use nix_flake_info::get_flake_info; -pub use nix_gc::run_gc; pub use nixpkgs_info::{get_nixpkgs_info, get_nixpkgs_options}; diff --git a/flake-info/src/commands/nix_flake_attrs.rs b/flake-info/src/commands/nix_flake_attrs.rs index 8b3d7d6..064be5c 100644 --- a/flake-info/src/commands/nix_flake_attrs.rs +++ b/flake-info/src/commands/nix_flake_attrs.rs @@ -1,7 +1,6 @@ use crate::data::import::{FlakeEntry, Kind}; use anyhow::{Context, Result}; use command_run::{Command, LogTo}; -use log::debug; use serde_json::Deserializer; use std::fmt::Display; use std::fs::File; diff --git a/flake-info/src/commands/nix_gc.rs b/flake-info/src/commands/nix_gc.rs deleted file mode 100644 index ad968c3..0000000 --- a/flake-info/src/commands/nix_gc.rs +++ /dev/null @@ -1,54 +0,0 @@ -use anyhow::{Context, Result}; -use log::warn; -use std::{ - path::{self, PathBuf}, - process::Command, -}; -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum GCError { - #[error("Unexpected exit status: {0}")] - ExitStatusError(String), -} - -pub fn run_gc() -> Result<()> { - let temp_store_path = PathBuf::from("/tmp/flake-info-store"); - if !temp_store_path.exists() { - warn!("Temporary store path does not exist, was a temporary store used?"); - return Ok(()); - } - - let mut command = Command::new("nix-store"); - command.args(&[ - "--gc", - "--store", - temp_store_path.canonicalize()?.to_str().unwrap(), - ]); - - dbg!(&command); - - let mut child = command - .spawn() - .with_context(|| "failed to start `nix-store gc` subprocess")?; - - let result = child.wait()?; - - if !result.success() { - return Err(GCError::ExitStatusError(format!("Code: {}", result.code().unwrap())).into()); - } - - std::fs::remove_dir_all(temp_store_path).with_context(|| "failed to clean up temp dir")?; - - Ok(()) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_gc() { - run_gc().unwrap(); - } -} diff --git a/flake-info/src/commands/nixpkgs_info.rs b/flake-info/src/commands/nixpkgs_info.rs index cb82da2..ddab90a 100644 --- a/flake-info/src/commands/nixpkgs_info.rs +++ b/flake-info/src/commands/nixpkgs_info.rs @@ -4,7 +4,7 @@ use std::io::Write; use std::{collections::HashMap, fmt::Display, fs::File}; use command_run::{Command, LogTo}; -use log::{debug, error}; +use log::error; use crate::data::import::{NixOption, NixpkgsEntry, Package}; diff --git a/flake-info/src/data/export.rs b/flake-info/src/data/export.rs index 2b423c8..1ad7316 100644 --- a/flake-info/src/data/export.rs +++ b/flake-info/src/data/export.rs @@ -12,13 +12,10 @@ use super::{ }; use crate::data::import::NixOption; use anyhow::Context; -use log::error; use serde::{Deserialize, Serialize}; -use serde_json::Value; use super::{ import, - prettyprint::print_value, system::System, utility::{AttributeQuery, Flatten, OneOrMany, Reverse}, }; @@ -66,6 +63,7 @@ impl From for License { #[serde(tag = "type")] pub enum Derivation { #[serde(rename = "package")] + #[allow(non_snake_case)] Package { package_attr_name: String, package_attr_name_reverse: Reverse, diff --git a/flake-info/src/data/import.rs b/flake-info/src/data/import.rs index 76ecf12..93c5b82 100644 --- a/flake-info/src/data/import.rs +++ b/flake-info/src/data/import.rs @@ -1,19 +1,16 @@ -use std::collections::{BTreeMap, HashMap}; -use std::convert::TryInto; -use std::fmt::{self, write, Display}; +use std::collections::HashMap; +use std::fmt; use std::marker::PhantomData; use std::{path::PathBuf, str::FromStr}; use clap::arg_enum; use log::warn; -use pandoc::PandocError; use serde::de::{self, MapAccess, Visitor}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde_json::Value; -use thiserror::Error; use super::pandoc::PandocExt; -use super::prettyprint::{self, print_value}; +use super::prettyprint::print_value; use super::system::System; use super::utility::{Flatten, OneOrMany}; @@ -226,6 +223,7 @@ pub enum License { Simple { license: String, }, + #[allow(non_snake_case)] Full { fullName: String, // shortName: String, @@ -313,8 +311,6 @@ where mod tests { use std::collections::HashMap; - use serde_json::Value; - use super::*; #[test] diff --git a/flake-info/src/data/pandoc.rs b/flake-info/src/data/pandoc.rs index 5314914..4ebe4e5 100644 --- a/flake-info/src/data/pandoc.rs +++ b/flake-info/src/data/pandoc.rs @@ -3,7 +3,6 @@ use std::io::Write; use std::path::PathBuf; use lazy_static::lazy_static; -use log::debug; use pandoc::{ InputFormat, InputKind, OutputFormat, OutputKind, PandocError, PandocOption, PandocOutput, }; diff --git a/flake-info/src/data/source.rs b/flake-info/src/data/source.rs index 96320b4..55508dd 100644 --- a/flake-info/src/data/source.rs +++ b/flake-info/src/data/source.rs @@ -1,8 +1,8 @@ -use anyhow::{Context, Result}; +use anyhow::Result; use serde::{Deserialize, Serialize}; use std::{ ffi::OsStr, - fs::{self, File}, + fs::File, io::{self, Read}, path::Path, }; diff --git a/flake-info/src/data/system.rs b/flake-info/src/data/system.rs index 8ef8bc3..1ebe319 100644 --- a/flake-info/src/data/system.rs +++ b/flake-info/src/data/system.rs @@ -31,8 +31,3 @@ pub struct InstancePlatform { system: System, version: String, } - -#[cfg(test)] -mod tests { - use super::*; -} diff --git a/flake-info/src/elastic.rs b/flake-info/src/elastic.rs index 5184094..9bf0c89 100644 --- a/flake-info/src/elastic.rs +++ b/flake-info/src/elastic.rs @@ -1,15 +1,8 @@ -use std::{borrow::Borrow, collections::HashMap}; +use std::collections::HashMap; use clap::arg_enum; pub use elasticsearch::http::transport::Transport; -use elasticsearch::{ - http::response::{self, Response}, - indices::{ - IndicesCreateParts, IndicesDeleteAliasParts, IndicesDeleteParts, IndicesExistsParts, - IndicesGetAliasParts, IndicesPutAliasParts, IndicesUpdateAliasesParts, - }, - BulkOperation, Elasticsearch as Client, -}; +use elasticsearch::{http::response, indices::*, BulkOperation, Elasticsearch as Client}; use lazy_static::lazy_static; use log::{info, warn}; use serde_json::{json, Value}; @@ -380,7 +373,7 @@ impl Elasticsearch { pub async fn write_alias( &self, - config: &Config<'_>, + _config: &Config<'_>, index: &str, alias: &str, ) -> Result<(), ElasticsearchError> { @@ -499,7 +492,7 @@ mod tests { let exports = sources .iter() .flat_map(|s| process_flake(s, &Kind::All, false, &[])) - .map(|(info, exports)| exports) + .map(|(_info, exports)| exports) .flatten() .collect::>(); println!("{}", serde_json::to_string(&exports[1]).unwrap()); diff --git a/flake-info/src/lib.rs b/flake-info/src/lib.rs index 65dc6f1..c55d278 100644 --- a/flake-info/src/lib.rs +++ b/flake-info/src/lib.rs @@ -1,7 +1,5 @@ #![recursion_limit = "256"] -use std::path::PathBuf; - use anyhow::Result; use data::{import::Kind, Export, Flake, Source};