diff --git a/file.go b/file.go index de2c0ec..21b0988 100644 --- a/file.go +++ b/file.go @@ -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{} } @@ -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 diff --git a/file/dcos_version.go b/file/dcos_version.go index 594d997..a7cfb54 100644 --- a/file/dcos_version.go +++ b/file/dcos_version.go @@ -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: {}, diff --git a/file/health.go b/file/health.go index 921f328..cde5351 100644 --- a/file/health.go +++ b/file/health.go @@ -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: {}, diff --git a/file_system.go b/file_system.go index 415fb12..231281e 100644 --- a/file_system.go +++ b/file_system.go @@ -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 {