tests.nixpkgs-check-by-name: Intermediate CaseSensitiveDuplicate error
This commit is contained in:
parent
e7d9cc96ed
commit
935f82267a
2 changed files with 33 additions and 12 deletions
|
@ -2,11 +2,17 @@ use crate::utils::PACKAGE_NIX_FILENAME;
|
||||||
use crate::ErrorWriter;
|
use crate::ErrorWriter;
|
||||||
use itertools::{Either, Itertools};
|
use itertools::{Either, Itertools};
|
||||||
use rnix::parser::ParseError;
|
use rnix::parser::ParseError;
|
||||||
|
use std::ffi::OsString;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub enum CheckError {
|
pub enum CheckError {
|
||||||
|
CaseSensitiveDuplicate {
|
||||||
|
relative_shard_path: PathBuf,
|
||||||
|
first: OsString,
|
||||||
|
second: OsString,
|
||||||
|
},
|
||||||
InvalidPackageName {
|
InvalidPackageName {
|
||||||
relative_package_dir: PathBuf,
|
relative_package_dir: PathBuf,
|
||||||
package_name: String,
|
package_name: String,
|
||||||
|
@ -83,6 +89,12 @@ impl CheckError {
|
||||||
impl fmt::Display for CheckError {
|
impl fmt::Display for CheckError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
CheckError::CaseSensitiveDuplicate { relative_shard_path, first, second } =>
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"{}: Duplicate case-sensitive package directories {first:?} and {second:?}.",
|
||||||
|
relative_shard_path.display(),
|
||||||
|
),
|
||||||
CheckError::InvalidPackageName { relative_package_dir, package_name } =>
|
CheckError::InvalidPackageName { relative_package_dir, package_name } =>
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -3,7 +3,6 @@ use crate::utils;
|
||||||
use crate::utils::{ErrorWriter, BASE_SUBPATH, PACKAGE_NIX_FILENAME};
|
use crate::utils::{ErrorWriter, BASE_SUBPATH, PACKAGE_NIX_FILENAME};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
@ -79,9 +78,28 @@ impl Nixpkgs {
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut unique_package_names = HashMap::new();
|
let entries = utils::read_dir_sorted(&shard_path)?;
|
||||||
|
|
||||||
for package_entry in utils::read_dir_sorted(&shard_path)? {
|
let duplicate_check_results = entries
|
||||||
|
.iter()
|
||||||
|
.zip(entries.iter().skip(1))
|
||||||
|
.filter(|(l, r)| {
|
||||||
|
l.file_name().to_ascii_lowercase() == r.file_name().to_ascii_lowercase()
|
||||||
|
})
|
||||||
|
.map(|(l, r)| {
|
||||||
|
CheckError::CaseSensitiveDuplicate {
|
||||||
|
relative_shard_path: relative_shard_path.clone(),
|
||||||
|
first: l.file_name(),
|
||||||
|
second: r.file_name(),
|
||||||
|
}
|
||||||
|
.into_result::<()>()
|
||||||
|
});
|
||||||
|
|
||||||
|
let duplicate_check_result = flatten_check_results(duplicate_check_results, |_| ());
|
||||||
|
|
||||||
|
write_check_result(error_writer, duplicate_check_result)?;
|
||||||
|
|
||||||
|
for package_entry in entries {
|
||||||
let package_path = package_entry.path();
|
let package_path = package_entry.path();
|
||||||
let package_name = package_entry.file_name().to_string_lossy().into_owned();
|
let package_name = package_entry.file_name().to_string_lossy().into_owned();
|
||||||
let relative_package_dir =
|
let relative_package_dir =
|
||||||
|
@ -95,15 +113,6 @@ impl Nixpkgs {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(duplicate_package_name) =
|
|
||||||
unique_package_names.insert(package_name.to_lowercase(), package_name.clone())
|
|
||||||
{
|
|
||||||
error_writer.write(&format!(
|
|
||||||
"{}: Duplicate case-sensitive package directories \"{duplicate_package_name}\" and \"{package_name}\".",
|
|
||||||
relative_shard_path.display(),
|
|
||||||
))?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let package_name_valid = PACKAGE_NAME_REGEX.is_match(&package_name);
|
let package_name_valid = PACKAGE_NAME_REGEX.is_match(&package_name);
|
||||||
let name_check_result = if !package_name_valid {
|
let name_check_result = if !package_name_valid {
|
||||||
CheckError::InvalidPackageName {
|
CheckError::InvalidPackageName {
|
||||||
|
|
Loading…
Reference in a new issue