Skip to content

Commit 173681f

Browse files
committed
api: fix bug to use same path for cache/un-cached result
1 parent a4b27f5 commit 173681f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

api.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,18 @@ type compilation struct {
8585
// addSource will read in a path and assign it a source index. If
8686
// it's already been loaded, the cached source is returned.
8787
func (c *compilation) addSource(path string) (int, error) {
88-
c.sourcesMu.RLock()
89-
if _, ok := c.sources[path]; ok {
90-
defer c.sourcesMu.RUnlock()
91-
return c.sources[path], nil
92-
}
93-
c.sourcesMu.RUnlock()
94-
9588
abs, err := filepath.Abs(path)
9689
if err != nil {
9790
return 0, oops.Wrapf(err, "failed to make path absolute: %s", path)
9891
}
9992

93+
c.sourcesMu.RLock()
94+
if _, ok := c.sources[abs]; ok {
95+
defer c.sourcesMu.RUnlock()
96+
return c.sources[abs], nil
97+
}
98+
c.sourcesMu.RUnlock()
99+
100100
in, err := ioutil.ReadFile(abs)
101101
if err != nil {
102102
return 0, oops.Wrapf(err, "failed to read file: %s", path)

0 commit comments

Comments
 (0)