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

Ensure lockfiles are files #1202

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Incorrect line numbers when printing errors in TypeScript extensions
- Absolute paths submitted when analyzing manifest files
- Ecosystem extensions not pre-checking `remove`/`uninstall` operations
- Directories matching lockfile formats being detected as lockfiles

## [5.6.0] - 2023-08-08

Expand Down
4 changes: 2 additions & 2 deletions lockfile/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ impl Parse for Cargo {
}

fn is_path_lockfile(&self, path: &Path) -> bool {
path.file_name() == Some(OsStr::new("Cargo.lock"))
path.file_name() == Some(OsStr::new("Cargo.lock")) && path.is_file()
}

fn is_path_manifest(&self, path: &Path) -> bool {
path.file_name() == Some(OsStr::new("Cargo.toml"))
path.file_name() == Some(OsStr::new("Cargo.toml")) && path.is_file()
}

#[cfg(feature = "generator")]
Expand Down
2 changes: 1 addition & 1 deletion lockfile/src/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Parse for PackagesLock {
};

// Accept both `packages.lock.json` and `packages.<project_name>.lock.json`.
file_name.starts_with("packages.") && file_name.ends_with(".lock.json")
file_name.starts_with("packages.") && file_name.ends_with(".lock.json") && path.is_file()
}

fn is_path_manifest(&self, path: &Path) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the && path.is_file() check for manifest files left off here intentionally? If so, why is it treated differently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just missed it.

Expand Down
4 changes: 2 additions & 2 deletions lockfile/src/golang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Parse for GoSum {
}

fn is_path_lockfile(&self, path: &Path) -> bool {
path.file_name() == Some(OsStr::new("go.sum"))
path.file_name() == Some(OsStr::new("go.sum")) && path.is_file()
}

fn is_path_manifest(&self, path: &Path) -> bool {
path.file_name() == Some(OsStr::new("go.mod"))
path.file_name() == Some(OsStr::new("go.mod")) && path.is_file()
}

#[cfg(feature = "generator")]
Expand Down
4 changes: 2 additions & 2 deletions lockfile/src/java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ impl Parse for GradleLock {
}

fn is_path_lockfile(&self, path: &Path) -> bool {
path.file_name() == Some(OsStr::new("gradle.lockfile"))
path.file_name() == Some(OsStr::new("gradle.lockfile")) && path.is_file()
}

fn is_path_manifest(&self, path: &Path) -> bool {
path.file_name() == Some(OsStr::new("build.gradle"))
path.file_name() == Some(OsStr::new("build.gradle")) && path.is_file()
}

#[cfg(feature = "generator")]
Expand Down
7 changes: 4 additions & 3 deletions lockfile/src/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ impl Parse for PackageLock {

fn is_path_lockfile(&self, path: &Path) -> bool {
let file_name = path.file_name();
file_name == Some(OsStr::new("package-lock.json"))
|| file_name == Some(OsStr::new("npm-shrinkwrap.json"))
(file_name == Some(OsStr::new("package-lock.json"))
|| file_name == Some(OsStr::new("npm-shrinkwrap.json")))
&& path.is_file()
}

fn is_path_manifest(&self, path: &Path) -> bool {
path.file_name() == Some(OsStr::new("package.json"))
path.file_name() == Some(OsStr::new("package.json")) && path.is_file()
}

#[cfg(feature = "generator")]
Expand Down
8 changes: 7 additions & 1 deletion lockfile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,14 @@ mod tests {
(".spdx.yaml", LockfileFormat::Spdx),
];

let dir = tempfile::tempdir().unwrap();

for (file, expected_type) in test_cases {
let pkg_type = get_path_format(Path::new(file));
// Create file, so we can read its metadata.
let path = dir.path().join(file);
File::create(&path).unwrap();

let pkg_type = get_path_format(&path);
assert_eq!(pkg_type, Some(*expected_type), "{}", file);
}
}
Expand Down
7 changes: 4 additions & 3 deletions lockfile/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ impl Parse for PyRequirements {
}

fn is_path_lockfile(&self, path: &Path) -> bool {
is_requirements_file(path)
is_requirements_file(path) && path.is_file()
}

fn is_path_manifest(&self, path: &Path) -> bool {
path.file_name() == Some(OsStr::new("requirements.in"))
(path.file_name() == Some(OsStr::new("requirements.in"))
|| path.file_name() == Some(OsStr::new("pyproject.toml"))
|| path.file_name() == Some(OsStr::new("setup.py"))
|| is_requirements_file(path)
|| is_requirements_file(path))
&& path.is_file()
}

#[cfg(feature = "generator")]
Expand Down
4 changes: 2 additions & 2 deletions lockfile/src/ruby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ impl Parse for GemLock {
}

fn is_path_lockfile(&self, path: &Path) -> bool {
path.file_name() == Some(OsStr::new("Gemfile.lock"))
path.file_name() == Some(OsStr::new("Gemfile.lock")) && path.is_file()
}

fn is_path_manifest(&self, path: &Path) -> bool {
path.file_name() == Some(OsStr::new("Gemfile"))
path.file_name() == Some(OsStr::new("Gemfile")) && path.is_file()
}

#[cfg(feature = "generator")]
Expand Down
5 changes: 3 additions & 2 deletions lockfile/src/spdx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,11 @@ impl Parse for Spdx {
}

fn is_path_lockfile(&self, path: &Path) -> bool {
path.ends_with(".spdx.json")
(path.ends_with(".spdx.json")
|| path.ends_with(".spdx.yaml")
|| path.ends_with(".spdx.yml")
|| path.ends_with(".spdx")
|| path.ends_with(".spdx"))
&& path.is_file()
}

fn is_path_manifest(&self, _path: &Path) -> bool {
Expand Down