Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure host platform are files and have contents #1584

Merged
merged 1 commit into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions host/host_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,47 +229,47 @@ func PlatformInformationWithContext(ctx context.Context) (platform string, famil
version = contents[0]
}
}
} else if common.PathExists(common.HostEtcWithContext(ctx, "neokylin-release")) {
} else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "neokylin-release")) {
contents, err := common.ReadLines(common.HostEtcWithContext(ctx, "neokylin-release"))
if err == nil {
version = getRedhatishVersion(contents)
platform = getRedhatishPlatform(contents)
}
} else if common.PathExists(common.HostEtcWithContext(ctx, "redhat-release")) {
} else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "redhat-release")) {
contents, err := common.ReadLines(common.HostEtcWithContext(ctx, "redhat-release"))
if err == nil {
version = getRedhatishVersion(contents)
platform = getRedhatishPlatform(contents)
}
} else if common.PathExists(common.HostEtcWithContext(ctx, "system-release")) {
} else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "system-release")) {
contents, err := common.ReadLines(common.HostEtcWithContext(ctx, "system-release"))
if err == nil {
version = getRedhatishVersion(contents)
platform = getRedhatishPlatform(contents)
}
} else if common.PathExists(common.HostEtcWithContext(ctx, "gentoo-release")) {
} else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "gentoo-release")) {
platform = "gentoo"
contents, err := common.ReadLines(common.HostEtcWithContext(ctx, "gentoo-release"))
if err == nil {
version = getRedhatishVersion(contents)
}
} else if common.PathExists(common.HostEtcWithContext(ctx, "SuSE-release")) {
} else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "SuSE-release")) {
contents, err := common.ReadLines(common.HostEtcWithContext(ctx, "SuSE-release"))
if err == nil {
version = getSuseVersion(contents)
platform = getSusePlatform(contents)
}
// TODO: slackware detecion
} else if common.PathExists(common.HostEtcWithContext(ctx, "arch-release")) {
} else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "arch-release")) {
platform = "arch"
version = lsb.Release
} else if common.PathExists(common.HostEtcWithContext(ctx, "alpine-release")) {
} else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "alpine-release")) {
platform = "alpine"
contents, err := common.ReadLines(common.HostEtcWithContext(ctx, "alpine-release"))
if err == nil && len(contents) > 0 && contents[0] != "" {
version = contents[0]
}
} else if common.PathExists(common.HostEtcWithContext(ctx, "os-release")) {
} else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "os-release")) {
p, v, err := common.GetOSReleaseWithContext(ctx)
if err == nil {
platform = p
Expand Down
2 changes: 1 addition & 1 deletion internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func PathExistsWithContents(filename string) bool {
if err != nil {
return false
}
return info.Size() > 4 // at least 4 bytes
return info.Size() > 4 && !info.IsDir() // at least 4 bytes
}

// GetEnvWithContext retrieves the environment variable key. If it does not exist it returns the default.
Expand Down
Loading