Skip to content

Commit db5e976

Browse files
committed
chore: add missing Cache.GetFile method
1 parent 65e3726 commit db5e976

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

internal/cache/cache.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,26 @@ func (c *Cache) get(id ActionID) (Entry, error) {
198198
return Entry{buf, size, time.Unix(0, tm)}, nil
199199
}
200200

201+
// GetFile looks up the action ID in the cache and returns
202+
// the name of the corresponding data file.
203+
func (c *Cache) GetFile(id ActionID) (file string, entry Entry, err error) {
204+
entry, err = c.Get(id)
205+
if err != nil {
206+
return "", Entry{}, err
207+
}
208+
209+
file, err = c.OutputFile(entry.OutputID)
210+
if err != nil {
211+
return "", Entry{}, err
212+
}
213+
214+
info, err := os.Stat(file)
215+
if err != nil || info.Size() != entry.Size {
216+
return "", Entry{}, errMissing
217+
}
218+
return file, entry, nil
219+
}
220+
201221
// GetBytes looks up the action ID in the cache and returns
202222
// the corresponding output bytes.
203223
// GetBytes should only be used for data that can be expected to fit in memory.

0 commit comments

Comments
 (0)