|
1 | 1 | package lockfile |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | | - "os" |
6 | | - |
7 | | - "github.com/BurntSushi/toml" |
| 4 | + "github.com/google/osv-scalibr/extractor/filesystem/language/rust/cargolock" |
8 | 5 | ) |
9 | 6 |
|
10 | | -type CargoLockPackage struct { |
11 | | - Name string `toml:"name"` |
12 | | - Version string `toml:"version"` |
13 | | -} |
14 | | - |
15 | | -type CargoLockFile struct { |
16 | | - Version int `toml:"version"` |
17 | | - Packages []CargoLockPackage `toml:"package"` |
18 | | -} |
19 | | - |
20 | 7 | const CargoEcosystem Ecosystem = "crates.io" |
21 | 8 |
|
22 | 9 | func ParseCargoLock(pathToLockfile string) ([]PackageDetails, error) { |
23 | | - var parsedLockfile *CargoLockFile |
24 | | - |
25 | | - lockfileContents, err := os.ReadFile(pathToLockfile) |
26 | | - |
27 | | - if err != nil { |
28 | | - return []PackageDetails{}, fmt.Errorf("could not read %s: %w", pathToLockfile, err) |
29 | | - } |
30 | | - |
31 | | - err = toml.Unmarshal(lockfileContents, &parsedLockfile) |
32 | | - |
33 | | - if err != nil { |
34 | | - return []PackageDetails{}, fmt.Errorf("could not parse %s: %w", pathToLockfile, err) |
35 | | - } |
36 | | - |
37 | | - packages := make([]PackageDetails, 0, len(parsedLockfile.Packages)) |
38 | | - |
39 | | - for _, lockPackage := range parsedLockfile.Packages { |
40 | | - packages = append(packages, PackageDetails{ |
41 | | - Name: lockPackage.Name, |
42 | | - Version: lockPackage.Version, |
43 | | - Ecosystem: CargoEcosystem, |
44 | | - CompareAs: CargoEcosystem, |
45 | | - }) |
46 | | - } |
47 | | - |
48 | | - return packages, nil |
| 10 | + return extract(pathToLockfile, cargolock.New(), CargoEcosystem) |
49 | 11 | } |
0 commit comments