-
-
Notifications
You must be signed in to change notification settings - Fork 14
File ratchet checks #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
File ratchet checks #144
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| use relative_path::RelativePath; | ||
| use relative_path::RelativePathBuf; | ||
| use std::collections::BTreeMap; | ||
| use std::path::Path; | ||
|
|
||
| use crate::nix_file::NixFileStore; | ||
| use crate::validation::ResultIteratorExt; | ||
| use crate::validation::Validation::Success; | ||
| use crate::{nix_file, ratchet, structure, validation}; | ||
|
|
||
| /// Runs check on all Nix files, returning a ratchet result for each | ||
| pub fn check_files( | ||
| nixpkgs_path: &Path, | ||
| nix_file_store: &mut NixFileStore, | ||
| ) -> validation::Result<BTreeMap<RelativePathBuf, ratchet::File>> { | ||
| process_nix_files(nixpkgs_path, nix_file_store, |_nix_file| { | ||
| // Noop for now, only boilerplate to make it easier to add future file-based checks | ||
| Ok(Success(ratchet::File {})) | ||
|
Comment on lines
+17
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or is this the place that #142 will go?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the logic goes yes :) |
||
| }) | ||
| } | ||
|
|
||
| /// Processes all Nix files in a Nixpkgs directory according to a given function `f`, collecting the | ||
| /// results into a mapping from each file to a ratchet value. | ||
| fn process_nix_files( | ||
| nixpkgs_path: &Path, | ||
| nix_file_store: &mut NixFileStore, | ||
| f: impl Fn(&nix_file::NixFile) -> validation::Result<ratchet::File>, | ||
| ) -> validation::Result<BTreeMap<RelativePathBuf, ratchet::File>> { | ||
| // Get all Nix files | ||
| let files = { | ||
| let mut files = vec![]; | ||
| collect_nix_files(nixpkgs_path, &RelativePathBuf::new(), &mut files)?; | ||
| files | ||
| }; | ||
philiptaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| let results = files | ||
| .into_iter() | ||
| .map(|path| { | ||
| // Get the (optionally-cached) parsed Nix file | ||
| let nix_file = nix_file_store.get(&path.to_path(nixpkgs_path))?; | ||
| let result = f(nix_file)?; | ||
| let val = result.map(|ratchet| (path, ratchet)); | ||
| Ok::<_, anyhow::Error>(val) | ||
| }) | ||
| .collect_vec()?; | ||
philiptaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Ok(validation::sequence(results).map(|entries| { | ||
| // Convert the Vec to a BTreeMap | ||
| entries.into_iter().collect() | ||
| })) | ||
| } | ||
|
|
||
| /// Recursively collects all Nix files in the relative `dir` within `base` | ||
| /// into the `files` `Vec`. | ||
| fn collect_nix_files( | ||
| base: &Path, | ||
| dir: &RelativePath, | ||
| files: &mut Vec<RelativePathBuf>, | ||
| ) -> anyhow::Result<()> { | ||
| for entry in structure::read_dir_sorted(&dir.to_path(base))? { | ||
| let mut relative_path = dir.to_relative_path_buf(); | ||
| relative_path.push(entry.file_name().to_string_lossy().into_owned()); | ||
|
|
||
| let absolute_path = entry.path(); | ||
|
|
||
| // We'll get to every file based on directory recursion, no need to follow symlinks. | ||
| if absolute_path.is_symlink() { | ||
| continue; | ||
| } | ||
| if absolute_path.is_dir() { | ||
| collect_nix_files(base, &relative_path, files)? | ||
| } else if absolute_path.extension().is_some_and(|x| x == "nix") { | ||
| files.push(relative_path) | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.