diff --git a/lockfile/src/cargo.rs b/lockfile/src/cargo.rs index 8c7d89ce9..c071bf79a 100644 --- a/lockfile/src/cargo.rs +++ b/lockfile/src/cargo.rs @@ -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")] diff --git a/lockfile/src/csharp.rs b/lockfile/src/csharp.rs index 7866e369d..861494358 100644 --- a/lockfile/src/csharp.rs +++ b/lockfile/src/csharp.rs @@ -47,7 +47,7 @@ impl Parse for PackagesLock { }; // Accept both `packages.lock.json` and `packages..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 { diff --git a/lockfile/src/golang.rs b/lockfile/src/golang.rs index 0da984e6d..db3a913cc 100644 --- a/lockfile/src/golang.rs +++ b/lockfile/src/golang.rs @@ -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")] diff --git a/lockfile/src/java.rs b/lockfile/src/java.rs index 9d049e8ae..bb9569ea0 100644 --- a/lockfile/src/java.rs +++ b/lockfile/src/java.rs @@ -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")] diff --git a/lockfile/src/javascript.rs b/lockfile/src/javascript.rs index c9d79f58f..e792d62df 100644 --- a/lockfile/src/javascript.rs +++ b/lockfile/src/javascript.rs @@ -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")] diff --git a/lockfile/src/lib.rs b/lockfile/src/lib.rs index 39ba2b80f..433b45e28 100644 --- a/lockfile/src/lib.rs +++ b/lockfile/src/lib.rs @@ -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); } } diff --git a/lockfile/src/python.rs b/lockfile/src/python.rs index 7cee3eda4..1a6181d57 100644 --- a/lockfile/src/python.rs +++ b/lockfile/src/python.rs @@ -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")] diff --git a/lockfile/src/ruby.rs b/lockfile/src/ruby.rs index f27bb0aa8..b6d0f1a9a 100644 --- a/lockfile/src/ruby.rs +++ b/lockfile/src/ruby.rs @@ -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")] diff --git a/lockfile/src/spdx.rs b/lockfile/src/spdx.rs index c6dca6bcc..c6641c3d3 100644 --- a/lockfile/src/spdx.rs +++ b/lockfile/src/spdx.rs @@ -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 {