Skip to content

Commit

Permalink
Allow several paths for one file
Browse files Browse the repository at this point in the history
  • Loading branch information
adyatlov committed Jun 18, 2018
1 parent 16870c0 commit e1e4464
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
16 changes: 14 additions & 2 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type FileType struct {
ContentType ContentType
// If HostTypes is not empty, then Path is relative to the host's directory,
// otherwise, it's relative to the bundle's root directory.
Path string
Paths []string
Description string
HostTypes map[HostType]struct{}
}
Expand Down Expand Up @@ -59,7 +59,19 @@ func OpenFile(basePath string, typeName string) (file File, err error) {
if err != nil {
return
}
filePath := path.Join(basePath, fileType.Path)
for _, p := range fileType.Paths {
filePath := path.Join(basePath, p)
file, err = open(filePath)
if err == nil {
break
}
}
return
}

// Open tries to open a file. If the file is not found, it tries to open it from a
// correspondent .gzip archive.
func open(filePath string) (file File, err error) {
file, err = os.Open(filePath)
if os.IsNotExist(err) {
var gzfile File
Expand Down
2 changes: 1 addition & 1 deletion file/dcos_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func init() {
f := bun.FileType{
Name: "dcos-version",
ContentType: bun.JSON,
Path: "opt/mesosphere/etc/dcos-version.json",
Paths: []string{"opt/mesosphere/etc/dcos-version.json"},
Description: "contains DC/OS version, DC/OS image commit and bootstrap ID.",
HostTypes: map[bun.HostType]struct{}{
bun.Master: {}, bun.Agent: {}, bun.PublicAgent: {},
Expand Down
2 changes: 1 addition & 1 deletion file/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func init() {
f := bun.FileType{
Name: "health",
ContentType: bun.JSON,
Path: "dcos-diagnostics-health.json",
Paths: []string{"dcos-diagnostics-health.json", "3dt-health.json"},
Description: "contains health of systemd services corresponding to DC/OS components.",
HostTypes: map[bun.HostType]struct{}{
bun.Master: {}, bun.Agent: {}, bun.PublicAgent: {},
Expand Down
4 changes: 1 addition & 3 deletions file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ type FileSystem interface {
Getwd() (string, error)
}

type File interface {
io.ReadCloser
}
type File io.ReadCloser

// osFS implements FileSystem
type OSFS struct {
Expand Down

0 comments on commit e1e4464

Please sign in to comment.