diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-19 02:32:09 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-24 01:15:56 +0200 |
commit | a755aa7d0251e4282ebdfdd33cbb00382b9a004c (patch) | |
tree | 8ef42a484427a32f69df0a5783eb0e83968ef4a6 /pkgs/test | |
parent | ed56d74c089d6b058a28eaf4a5ef04b190ed3651 (diff) |
tests.nixpkgs-check-by-name: Intermediate SearchPath error
Diffstat (limited to 'pkgs/test')
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/check_result.rs | 14 | ||||
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/references.rs | 64 |
2 files changed, 46 insertions, 32 deletions
diff --git a/pkgs/test/nixpkgs-check-by-name/src/check_result.rs b/pkgs/test/nixpkgs-check-by-name/src/check_result.rs index 79d3dbe676621..cc004e0129313 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/check_result.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/check_result.rs @@ -5,6 +5,12 @@ use std::io; use std::path::PathBuf; pub enum CheckError { + SearchPath { + relative_package_dir: PathBuf, + subpath: PathBuf, + line: usize, + text: String, + }, OutsidePathReference { relative_package_dir: PathBuf, subpath: PathBuf, @@ -29,6 +35,14 @@ impl CheckError { impl fmt::Display for CheckError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { + CheckError::SearchPath { relative_package_dir, subpath, line, text } => + write!( + f, + "{}: File {} at line {line} contains the nix search path expression \"{}\" which may point outside the directory of that package.", + relative_package_dir.display(), + subpath.display(), + text + ), CheckError::OutsidePathReference { relative_package_dir, subpath, line, text } => write!( f, diff --git a/pkgs/test/nixpkgs-check-by-name/src/references.rs b/pkgs/test/nixpkgs-check-by-name/src/references.rs index 30eaee0d7484f..dacac9c9ee5ce 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/references.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/references.rs @@ -144,43 +144,43 @@ fn check_nix_file<W: io::Write>( } // Filters out search paths like <nixpkgs> - if text.starts_with('<') { - context.error_writer.write(&format!( - "{}: File {} at line {line} contains the nix search path expression \"{}\" which may point outside the directory of that package.", - context.relative_package_dir.display(), - subpath.display(), - text - ))?; - continue; - } - - // Resolves the reference of the Nix path - // turning `../baz` inside `/foo/bar/default.nix` to `/foo/baz` - let check_result = match parent_dir.join(Path::new(&text)).canonicalize() { - Ok(target) => { - // Then checking if it's still in the package directory - // No need to handle the case of it being inside the directory, since we scan through the - // entire directory recursively anyways - if let Err(_prefix_error) = target.strip_prefix(context.absolute_package_dir) { - CheckError::OutsidePathReference { - relative_package_dir: context.relative_package_dir.clone(), - subpath: subpath.to_path_buf(), - line, - text, - } - .into_result() - } else { - pass(()) - } - } - Err(e) => CheckError::UnresolvablePathReference { + let check_result = if text.starts_with('<') { + CheckError::SearchPath { relative_package_dir: context.relative_package_dir.clone(), subpath: subpath.to_path_buf(), line, text, - io_error: e, } - .into_result(), + .into_result() + } else { + // Resolves the reference of the Nix path + // turning `../baz` inside `/foo/bar/default.nix` to `/foo/baz` + match parent_dir.join(Path::new(&text)).canonicalize() { + Ok(target) => { + // Then checking if it's still in the package directory + // No need to handle the case of it being inside the directory, since we scan through the + // entire directory recursively anyways + if let Err(_prefix_error) = target.strip_prefix(context.absolute_package_dir) { + CheckError::OutsidePathReference { + relative_package_dir: context.relative_package_dir.clone(), + subpath: subpath.to_path_buf(), + line, + text, + } + .into_result() + } else { + pass(()) + } + } + Err(e) => CheckError::UnresolvablePathReference { + relative_package_dir: context.relative_package_dir.clone(), + subpath: subpath.to_path_buf(), + line, + text, + io_error: e, + } + .into_result(), + } }; write_check_result(context.error_writer, check_result)?; |