mirror of
https://github.com/anchore/syft.git
synced 2026-11-03 07:56:36 +01:00
chore: drop the locking and JSON support from internal/index
the index was ported from a prototype with per-node `RWMutex` lock upgrading and JSON marshalling. Its only consumer (`archive.Resolver`) builds it sequentially during extraction and then only reads it, so neither was used. `lock.go` also compared method-value pointers to tell the read lock from the write lock, which can't distinguish lock instances. removed the locks, the upgrade and retry paths that existed only for concurrent writers, and the JSON methods and their test. The radix logic is unchanged, and the README now points at `archive.Resolver` rather than a nonexistent `archive.Index`. Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
# internal/index
|
||||
|
||||
A key-split (radix) index over strings, and a forward/reverse pair of them that answers prefix and
|
||||
suffix lookups. Ported from a prototype directory-scan package and kept close to the original so the
|
||||
two can be diffed.
|
||||
suffix lookups. Ported from a prototype directory-scan package, minus its locking and JSON support: the
|
||||
only consumer builds an index once and then only reads it, so it is not safe for concurrent writes.
|
||||
|
||||
## Types
|
||||
|
||||
- `KeySplitIndex[T]` / `Node[T]`: a radix tree. Each node holds at most one value and splits its
|
||||
children on the longest common prefix of their keys, so `pom.xml` and `pom.properties` share a
|
||||
`pom.` node. Reads take a read lock per node; writes upgrade to a write lock only where the tree
|
||||
changes. `KeySplitIndex` also marshals to and from a flat JSON object of key → value.
|
||||
`pom.` node.
|
||||
- `PrefixSuffix[T]`: two `KeySplitIndex` values, one keyed by the string and one by its reverse, so
|
||||
`ByPrefix("pom")` and `BySuffix(".jar")` are both a single descent followed by a collect.
|
||||
|
||||
@@ -27,13 +26,11 @@ name repeats across directories.
|
||||
|
||||
## Where it is used
|
||||
|
||||
`internal/archive.Index` keeps one `PrefixSuffix[[]*node]` of files by base name. A cataloger glob
|
||||
`internal/archive.Resolver` keeps one `PrefixSuffix[[]*node]` of files by base name, and one of directories. A cataloger glob
|
||||
whose last segment is a literal, `*suffix` or `prefix*` (nearly all of them: `**/*.jar`,
|
||||
`**/pom.properties`) is answered from it instead of by walking every path.
|
||||
|
||||
## Notes
|
||||
|
||||
- Lookups are byte-wise; `reverse` works on runes so a multi-byte name reverses correctly.
|
||||
- `lock.go` returns unlock functions rather than exposing `Unlock`, which is how a node tells a read
|
||||
lock from a write lock when deciding whether to upgrade.
|
||||
- `_find`, `_collect` and `_makeNodeP` are the prototype's internals and are left with its naming.
|
||||
|
||||
Reference in New Issue
Block a user