diff options
author | Rishabh Bhatnagar <bhatnagarrishabh4@gmail.com> | 2020-11-17 20:45:14 +0530 |
---|---|---|
committer | Rishabh Bhatnagar <bhatnagarrishabh4@gmail.com> | 2020-11-18 09:27:08 +0530 |
commit | f71fa04c39232d41b1f9f30d5e981c96f943df7d (patch) | |
tree | b3acc0d6282ca1def503bf4f99dfaa3e2bcbc3e3 /rdfloader/parser2v2/parse_relationship.go | |
parent | 302f983e7b61d30e81294efb1637e82056e81732 (diff) | |
download | spdx-tools-f71fa04c39232d41b1f9f30d5e981c96f943df7d.tar.gz |
Enable Caching And Parse Cyclic Dependent Objects
- File, Package, Relationship can have cyclic dependent objects.
- Cyclic dependent License will raise an error.
- Double computation for File, Package, Relationship and License is enabled.
Signed-off-by: Rishabh Bhatnagar <bhatnagarrishabh4@gmail.com>
Diffstat (limited to 'rdfloader/parser2v2/parse_relationship.go')
-rw-r--r-- | rdfloader/parser2v2/parse_relationship.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/rdfloader/parser2v2/parse_relationship.go b/rdfloader/parser2v2/parse_relationship.go index beba838..c4e8540 100644 --- a/rdfloader/parser2v2/parse_relationship.go +++ b/rdfloader/parser2v2/parse_relationship.go @@ -22,6 +22,26 @@ func (parser *rdfParser2_2) parseRelationship(triple *gordfParser.Triple) (err e return err } + currState := parser.cache[triple.Object.ID] + if currState == nil { + // there is no entry about the state of current package node. + // this is the first time we're seeing this node. + parser.cache[triple.Object.ID] = &nodeState{ + object: reln, + Color: WHITE, + } + } else if currState.Color == GREY { + // we have already started parsing this relationship node and we needn't parse it again. + return nil + } + + // setting color of the state to grey to indicate that we've started to + // parse this node once. + parser.cache[triple.Object.ID].Color = GREY + + // setting state color to black to indicate when we're done parsing this node. + defer func(){parser.cache[triple.Object.ID].Color = BLACK}(); + for _, subTriple := range parser.nodeToTriples(triple.Object) { switch subTriple.Predicate.ID { case SPDX_RELATIONSHIP_TYPE: |