-
Notifications
You must be signed in to change notification settings - Fork 111
/
file_store.go
41 lines (34 loc) · 929 Bytes
/
file_store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package file
import (
"context"
"fmt"
"github.com/bmatcuk/doublestar/v4"
"github.com/rilldata/rill/runtime/pkg/fileutil"
)
// FilePaths implements drivers.FileStore
func (c *connection) FilePaths(ctx context.Context, src map[string]any) ([]string, error) {
conf, err := parseSourceProperties(src)
if err != nil {
return nil, err
}
path, err := c.resolveLocalPath(conf.Path)
if err != nil {
return nil, err
}
// get all files in case glob passed
localPaths, err := doublestar.FilepathGlob(path)
if err != nil {
return nil, err
}
if len(localPaths) == 0 {
return nil, fmt.Errorf("file does not exist at %s", conf.Path)
}
return localPaths, nil
}
func (c *connection) resolveLocalPath(path string) (string, error) {
allowHostAccess := false
if val, ok := c.driverConfig["allow_host_access"].(bool); ok {
allowHostAccess = val
}
return fileutil.ResolveLocalPath(path, c.root, allowHostAccess)
}