Skip to content

Commit 3d64468

Browse files
committed
fix(fsi): fsi.ReadDir sets the '/fsi' path prefix
allows outside systems to distinguish datasets read from an FSI dir
1 parent 938060a commit 3d64468

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

cmd/search_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ type SearchTestRunner struct {
110110
}
111111

112112
// NewSearchTestRunner sets up state needed for the search test
113+
// TODO (b5) - add an explicit RepoPath to the SearchTestRunner. Tests are
114+
// relying on the "RootPath" property, which should be configurable per-test
113115
func NewSearchTestRunner(t *testing.T) *SearchTestRunner {
114116
run := SearchTestRunner{}
115117

fsi/fsi.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,29 @@ var (
3535
ErrNoLink = fmt.Errorf("dataset is not linked to the filesystem")
3636
)
3737

38+
// PathPrefix indicates paths that are using file system integration
39+
const PathPrefix = "/fsi"
40+
3841
// FilesystemPathToLocal converts a qfs.Filesystem path that has an /fsi prefix
3942
// to a local path
4043
func FilesystemPathToLocal(qfsPath string) string {
41-
return strings.TrimPrefix(qfsPath, "/fsi")
44+
return strings.TrimPrefix(qfsPath, PathPrefix)
45+
}
46+
47+
func localPathToFSIPath(absLocalPath string) string {
48+
if absLocalPath == "" {
49+
return ""
50+
}
51+
if strings.HasPrefix(absLocalPath, PathPrefix) {
52+
return absLocalPath
53+
}
54+
return fmt.Sprintf("%s%s", PathPrefix, absLocalPath)
55+
}
56+
57+
// IsFSIPath is a utility function that returns whether the given path is a
58+
// local filesystem path
59+
func IsFSIPath(path string) bool {
60+
return strings.HasPrefix(path, PathPrefix)
4261
}
4362

4463
// GetLinkedFilesysRef returns whether a directory is linked to a dataset in your repo, and
@@ -99,18 +118,12 @@ func (fsi *FSI) ResolvedPath(ref *dsref.Ref) error {
99118
}
100119

101120
if vi.FSIPath != "" {
102-
ref.Path = fmt.Sprintf("/fsi%s", vi.FSIPath)
121+
ref.Path = fmt.Sprintf("%s%s", PathPrefix, vi.FSIPath)
103122
return nil
104123
}
105124
return ErrNoLink
106125
}
107126

108-
// IsFSIPath is a utility function that returns whether the given path is a
109-
// local filesystem path
110-
func IsFSIPath(path string) bool {
111-
return strings.HasPrefix(path, "/fsi")
112-
}
113-
114127
// ListLinks returns a list of linked datasets and their connected
115128
// directories
116129
func (fsi *FSI) ListLinks(offset, limit int) ([]dsref.VersionInfo, error) {

fsi/mapping.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func ReadDir(dir string) (*dataset.Dataset, error) {
2828
if err != nil {
2929
return nil, err
3030
}
31+
ds.Path = localPathToFSIPath(ds.Path)
3132
return ds, nil
3233
}
3334

stats/cache.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"io/ioutil"
10+
"math"
1011
"os"
1112
"path/filepath"
1213
"sync"
@@ -169,8 +170,6 @@ func (c *localCache) cacheKey(key string) string {
169170
return b32Enc.EncodeToString([]byte(key))
170171
}
171172

172-
const uintSize = 32 << (^uint(0) >> 32 & 1)
173-
174173
func (c *localCache) addAndPurgeExpired(cacheKey string, statProps, targetProps didmod.Props) {
175174
c.infoLk.Lock()
176175
defer c.infoLk.Unlock()
@@ -180,15 +179,15 @@ func (c *localCache) addAndPurgeExpired(cacheKey string, statProps, targetProps
180179

181180
var (
182181
lowestKey string
183-
lowestModTime int
182+
lowestModTime int64
184183
)
185184

186185
for c.info.Size() > c.maxSize {
187186
lowestKey = ""
188-
lowestModTime = 1<<(uintSize-1) - 1
187+
lowestModTime = math.MaxInt64
189188

190189
for key, fileProps := range c.info.StatFileProps {
191-
if int(fileProps.Mtime.Unix()) < lowestModTime && key != cacheKey {
190+
if fileProps.Mtime.Unix() < lowestModTime && key != cacheKey {
192191
lowestKey = key
193192
}
194193
}

stats/stats.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ import (
2121

2222
var log = logger.Logger("stats")
2323

24-
func init() {
25-
logger.SetLogLevel("stats", "debug")
26-
}
27-
2824
// Service can generate an array of statistical info for a dataset
2925
type Service struct {
3026
cache Cache
@@ -117,7 +113,7 @@ func (s *Service) cacheKey(ds *dataset.Dataset) (string, error) {
117113
if fsi.IsFSIPath(ds.Path) {
118114
// if the passed-in dataset is FSI-linked, use the body file
119115
// as a basis for the cache key
120-
// TODO(b5) - the design of this system means changing the structure
116+
// TODO(b5) - using only one file as a target means changing the structure
121117
// component can't invalidate the cache. We should be able to specify
122118
// an arbitrary number of target files for cache invalidation along with
123119
// a single canonical path

0 commit comments

Comments
 (0)