Skip to content

Commit 86a8e2a

Browse files
committed
fix a bug where changing meta files has no effect when --boost is on
1 parent 68f7899 commit 86a8e2a

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

cli/archivist/cmd/generate.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545

4646
"github.com/edwingeng/deque"
4747
"github.com/kingsgroupos/archivist/cli/archivist/guesser"
48+
"github.com/kingsgroupos/archivist/cli/archivist/meta"
4849
"github.com/kingsgroupos/misc"
4950
"github.com/kingsgroupos/misc/chksum"
5051
"github.com/kingsgroupos/misc/variable"
@@ -398,6 +399,17 @@ func (this *generateCmdT) genStructRelatedCode(allFiles []string, sha1Map map[st
398399
panic("impossible")
399400
}
400401

402+
appendMetaFiles := func(jsonFile string, data []byte) []byte {
403+
d1, d2 := meta.ReadMetaFiles(jsonFile)
404+
var buf bytes.Buffer
405+
buf.Write(data)
406+
buf.WriteByte('\n')
407+
buf.Write(d1)
408+
buf.WriteByte('\n')
409+
buf.Write(d2)
410+
return buf.Bytes()
411+
}
412+
401413
revRefGraph := make(map[string][]string)
402414
var guessers []*guesser.Guesser
403415
for i, file := range allFiles {
@@ -410,7 +422,7 @@ func (this *generateCmdT) genStructRelatedCode(allFiles []string, sha1Map map[st
410422
panic(err)
411423
} else {
412424
if this.boost {
413-
fileSha1 = sha1.Sum(data)
425+
fileSha1 = sha1.Sum(appendMetaFiles(file, data))
414426
}
415427
g = this.buildGuesserWithBytes(
416428
data, file, primaryStructNameMap, this.structNameSuffix)
@@ -419,11 +431,11 @@ func (this *generateCmdT) genStructRelatedCode(allFiles []string, sha1Map map[st
419431
if data, err := guesser.ReadDataFile(file); err != nil {
420432
panic(err)
421433
} else {
434+
jsonFile := strings.TrimSuffix(file, ".js") + ".json"
422435
if this.boost {
423-
fileSha1 = sha1.Sum(data)
436+
fileSha1 = sha1.Sum(appendMetaFiles(jsonFile, data))
424437
}
425438
data = evalJavascript(data, file)
426-
jsonFile := strings.TrimSuffix(file, ".js") + ".json"
427439
g = this.buildGuesserWithBytes(
428440
data, jsonFile, primaryStructNameMap, this.structNameSuffix)
429441
}

cli/archivist/meta/multiMatcher.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
package meta
3232

3333
import (
34+
"io/ioutil"
3435
"path/filepath"
3536
"strings"
3637

@@ -47,7 +48,7 @@ func NewMultiMatcher() *MultiMatcher {
4748
return &MultiMatcher{}
4849
}
4950

50-
func (this *MultiMatcher) ParseMetaFiles(jsonFile string) error {
51+
func metaFiles(jsonFile string) (string, string) {
5152
dir1 := filepath.Dir(jsonFile)
5253
dir2 := filepath.Dir(dir1)
5354
dir3 := filepath.Dir(dir2)
@@ -60,7 +61,18 @@ func (this *MultiMatcher) ParseMetaFiles(jsonFile string) error {
6061
f0 := strings.TrimSuffix(jsonFile, ".json")
6162
f1 := f0 + ".meta"
6263
f2 := f0 + ".suggested.meta"
64+
return f1, f2
65+
}
6366

67+
func ReadMetaFiles(jsonFile string) ([]byte, []byte) {
68+
f1, f2 := metaFiles(jsonFile)
69+
data1, _ := ioutil.ReadFile(f1)
70+
data2, _ := ioutil.ReadFile(f2)
71+
return data1, data2
72+
}
73+
74+
func (this *MultiMatcher) ParseMetaFiles(jsonFile string) error {
75+
f1, f2 := metaFiles(jsonFile)
6476
if err := misc.FindFile(f1); err == nil {
6577
this.p1 = NewParser()
6678
if err := this.p1.ParseFile(f1); err != nil {

0 commit comments

Comments
 (0)