1package headless23import (4 "context"5 "path/filepath"6 "strings"78 "src.rest/cat/012/internal/paged"9 "src.rest/cat/012/internal/sheet"10)1112// ReadSources answers what the workbook's formulas and pivot tables ask13// of its linked sources, reading them to the end before it returns, as14// the screen does in the background. Only sources in the workbook's15// folder or below are read: a path out of it (absolute, or through ..)16// shows why it wasn't, as the screen asks first about such paths in a17// workbook from another computer.18func (f *File) ReadSources(ctx context.Context) {19 w := f.Book20 if len(w.Sources()) == 0 {21 return22 }23 dir := filepath.Dir(f.Path)24 h := paged.NewHost(sheet.MaxCells())25 defer h.Close()26 var inside []paged.Linked27 for _, l := range paged.Links(w, func(p string) string { return p }, "") {28 if p := l.Spec.Path; filepath.IsAbs(p) || p == ".." || strings.HasPrefix(p, ".."+string(filepath.Separator)) {29 w.SetSourceShape(l.Name, sheet.SourceShape{}, "Not read: outside the workbook's folder")30 continue31 }32 l.Spec.Path = filepath.Join(dir, l.Spec.Path)33 inside = append(inside, l)34 }35 h.Settle(ctx, w, inside)36}