Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jaypipes
Copy link
Owner

In calculating the default cache path, we were using the os.UserHomeDir() function to get the user's home directory. This function differs from the behaviour of mitchellh/go-homedir in that it errors out on Linux if $HOME is not set.

This caused issues in certain environments and so this PR simply returns an empty string when $HOME is unset and now returns an error only during pci.ids DB file discovery if search paths yields an empty slice AND cache path is empty AND network fetch is enabled.

Issue #38

@jaypipes
Copy link
Owner Author

@candlerb @stgraber please let me know your thoughts on this PR.

types/default.go Outdated
// https://github.com/jaypipes/pcidb/issues/38
if _, ok := os.LookupEnv("HOME"); !ok {
return ""
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this defeats the whole object of using os.UserHomeDir(), since the point of it is that it's platform independent - different platforms use different env vars for home.

Since the only error which UserHomeDir can return is if the required env variable is not set, I think a better solution would be simply:

	hdir, err := os.UserHomeDir()
	if err != nil {
        return ""
    }

(that is, just remove the printing of the error)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@candlerb great point. updated.

@jaypipes jaypipes force-pushed the jaypipes/home-unset branch from 4187bbe to 01517ae Compare August 31, 2025 13:33
In calculating the default cache path, we were using the
`os.UserHomeDir()` function to get the user's home directory. This
function differs from the behaviour of mitchellh/go-homedir in that it
errors out on Linux if `$HOME` is not set.

This caused issues in certain environments and so this PR simply returns
an empty string when `$HOME` is unset and now returns an error only
during pci.ids DB file discovery if search paths yields an empty slice
AND cache path is empty AND network fetch is enabled.

Issue #38

Signed-off-by: Jay Pipes <[email protected]>
@jaypipes jaypipes force-pushed the jaypipes/home-unset branch from 01517ae to 0aa295c Compare August 31, 2025 13:37
@jaypipes jaypipes merged commit 96cb73b into main Aug 31, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants