Skip to content
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

[[licenses.clarify]]: license-files can't contain files that don't start with LICENSE #524

Closed
str4d opened this issue Jun 27, 2023 · 1 comment · Fixed by #533
Closed
Assignees
Labels
bug Something isn't working

Comments

@str4d
Copy link

str4d commented Jun 27, 2023

I am trying to add two license files to a [[licenses.clarify]]: one named LICENSE-FOO (describing the base license), and one named COPYING (describing how the base license applies to the project). The former file can be found and pinned, but the latter cannot.

The problem is that the license-files in each clarification are not directly searched for, but instead checked against the list of discovered license files, obtained from LicensePack::read, which filters out any file that doesn't start with LICENSE:

for clarification in iter_clarifications(&cfg.clarifications, krate) {
let lp = if let Some(lp) = &license_pack {
lp
} else {
license_pack = Some(LicensePack::read(krate));
license_pack.as_ref().unwrap()
};
// Check to see if the clarification provided exactly matches
// the set of detected licenses, if they do, we use the clarification's
// license expression as the license requirements for this crate
let clarifications_match = clarification.license_files.iter().all(|clf| {
match lp.license_files_match(clf) {
Ok(_) => true,
Err(reason) => {
if let MismatchReason::FileNotFound = reason {
labels.push(
super::diags::MissingClarificationFile {
expected: &clf.path,
cfg_file_id: cfg.file_id,
}
.into(),
);
}

impl LicensePack {
fn read(krate: &Krate) -> Self {
let root_path = krate.manifest_path.parent().unwrap();
let mut lic_paths = match find_license_files(root_path) {

if p.is_file() && p.file_name().map_or(false, |f| f.starts_with("LICENSE")) {
Some(p)
} else {
None
}

@str4d str4d added the bug Something isn't working label Jun 27, 2023
@str4d
Copy link
Author

str4d commented Jun 27, 2023

If the filtering is intentional (i.e. cargo-deny has an allow-list of filenames that can be considered to contain licenses), then it would be good to both add COPYING as an allowed filename (or filename prefix, though IDK how common the latter is), and return an error message that tells the user about the filter mismatch (rather than the more obtuse "file not found").

@Jake-Shadle Jake-Shadle self-assigned this Jul 25, 2023
Jake-Shadle added a commit that referenced this issue Jul 26, 2023
- Fixup license clarification
- Add clarification example
- Add test

Resolves: #521 
Resolves: #524
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants