diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-19 23:07:54 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-24 01:15:57 +0200 |
commit | 4897b63ae67d6f56a0d9a7f0db421467ebe8828b (patch) | |
tree | 130c244ad0dce1cdaf9a55d94df8d46bddb56bbe /pkgs/test | |
parent | 9a3abc4383da1a430525902b87db02ddcfc279ee (diff) |
tests.nixpkgs-check-by-name: Intermediate Symlink errors
Diffstat (limited to 'pkgs/test')
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/check_result.rs | 23 | ||||
-rw-r--r-- | pkgs/test/nixpkgs-check-by-name/src/references.rs | 42 |
2 files changed, 47 insertions, 18 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 42468a29e809a..32d43edc153a1 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/check_result.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/check_result.rs @@ -6,6 +6,15 @@ use std::io; use std::path::PathBuf; pub enum CheckError { + OutsideSymlink { + relative_package_dir: PathBuf, + subpath: PathBuf, + }, + UnresolvableSymlink { + relative_package_dir: PathBuf, + subpath: PathBuf, + io_error: io::Error, + }, CouldNotParseNix { relative_package_dir: PathBuf, subpath: PathBuf, @@ -47,6 +56,20 @@ impl CheckError { impl fmt::Display for CheckError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { + CheckError::OutsideSymlink { relative_package_dir, subpath } => + write!( + f, + "{}: Path {} is a symlink pointing to a path outside the directory of that package.", + relative_package_dir.display(), + subpath.display(), + ), + CheckError::UnresolvableSymlink { relative_package_dir, subpath, io_error } => + write!( + f, + "{}: Path {} is a symlink which cannot be resolved: {io_error}.", + relative_package_dir.display(), + subpath.display(), + ), CheckError::CouldNotParseNix { relative_package_dir, subpath, error } => 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 9c88507ff99b1..f72074483b142 100644 --- a/pkgs/test/nixpkgs-check-by-name/src/references.rs +++ b/pkgs/test/nixpkgs-check-by-name/src/references.rs @@ -52,26 +52,28 @@ fn check_path<W: io::Write>(context: &mut PackageContext<W>, subpath: &Path) -> if path.is_symlink() { // Check whether the symlink resolves to outside the package directory - match path.canonicalize() { + let check_result = match path.canonicalize() { Ok(target) => { // 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) { - context.error_writer.write(&format!( - "{}: Path {} is a symlink pointing to a path outside the directory of that package.", - context.relative_package_dir.display(), - subpath.display(), - ))?; + CheckError::OutsideSymlink { + relative_package_dir: context.relative_package_dir.clone(), + subpath: subpath.to_path_buf(), + } + .into_result() + } else { + pass(()) } } - Err(e) => { - context.error_writer.write(&format!( - "{}: Path {} is a symlink which cannot be resolved: {e}.", - context.relative_package_dir.display(), - subpath.display(), - ))?; + Err(io_error) => CheckError::UnresolvableSymlink { + relative_package_dir: context.relative_package_dir.clone(), + subpath: subpath.to_path_buf(), + io_error, } - } + .into_result(), + }; + write_check_result(context.error_writer, check_result)?; } else if path.is_dir() { // Recursively check each entry for entry in utils::read_dir_sorted(&path)? { @@ -81,15 +83,19 @@ fn check_path<W: io::Write>(context: &mut PackageContext<W>, subpath: &Path) -> } } else if path.is_file() { // Only check Nix files - if let Some(ext) = path.extension() { + let check_result = if let Some(ext) = path.extension() { if ext == OsStr::new("nix") { - let check_result = check_nix_file(context, subpath).context(format!( + check_nix_file(context, subpath).context(format!( "Error while checking Nix file {}", subpath.display() - )); - write_check_result(context.error_writer, check_result)?; + )) + } else { + pass(()) } - } + } else { + pass(()) + }; + write_check_result(context.error_writer, check_result)?; } else { // This should never happen, git doesn't support other file types anyhow::bail!("Unsupported file type for path {}", subpath.display()); |