Skip to content

Commit 94f66b1

Browse files
committed
Split out alternate directory addition
We're going to want to support additional ways of handling alternate directories, so split the addition of an alternate directory out into a function so we can reuse it.
1 parent f17ed8d commit 94f66b1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

backend.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root strin
4545

4646
scanner := bufio.NewScanner(f)
4747
for scanner.Scan() {
48-
storage = append(storage, newFileStorer(scanner.Text(), ""))
49-
pack, err := pack.NewStorage(scanner.Text())
48+
storage, err = addAlternateDirectory(storage, scanner.Text())
5049
if err != nil {
5150
return nil, err
5251
}
53-
storage = append(storage, pack)
5452
}
5553

5654
if err := scanner.Err(); err != nil {
@@ -60,6 +58,16 @@ func findAllBackends(mainLoose *fileStorer, mainPacked *pack.Storage, root strin
6058
return storage, nil
6159
}
6260

61+
func addAlternateDirectory(s []storage.Storage, dir string) ([]storage.Storage, error) {
62+
s = append(s, newFileStorer(dir, ""))
63+
pack, err := pack.NewStorage(dir)
64+
if err != nil {
65+
return s, err
66+
}
67+
s = append(s, pack)
68+
return s, nil
69+
}
70+
6371
// NewMemoryBackend initializes a new memory-based backend.
6472
//
6573
// A value of "nil" is acceptable and indicates that no entries should be added

0 commit comments

Comments
 (0)