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

fix-resolve-home-v1 #4519

Merged
merged 4 commits into from Oct 18, 2022
Merged

fix-resolve-home-v1 #4519

merged 4 commits into from Oct 18, 2022

Conversation

RanVaknin
Copy link
Contributor

For changes to files under the /model/ folder, and manual edits to autogenerated code (e.g. /service/s3/api.go) please create an Issue instead of a PR for those type of changes.

If there is an existing bug or feature this PR is answers please reference it here.
#4444

Added a fallback to resolve home using current user from "os/user".

)

func userHomeDir() string {
home, _ := os.UserHomeDir()
Copy link

Choose a reason for hiding this comment

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

This does not fix the problem with #4444, since os.UserHomeDir is also based on $HOME.
Test program to demonstrate:

// go build test.go
// env -i ./test
package main                                                                    
                                                                                
import (                                                                        
        "fmt"                                                                   
        "os"                                                                    
)                                                                               
                                                                                
func main() {                                                                   
        home, err := os.UserHomeDir()                                           
        fmt.Println(home,  err)                                            // prints "$HOME not defined" if variable is empty
}  

Better solution:

package main                                                                    
                                                                                
import (                                                                        
        "fmt"                                                                   
        "os/user"                                                               
)                                                                               
                                                                                
func main() {                                                                   
        user, err := user.Current()                                             
        fmt.Println(user.HomeDir, err)                  // Prints home directory even when running under env -i or $HOME unset.
}                                                                               

The user.Current() is based on getpwent and thus is independent of the $HOME variable.

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.

None yet

3 participants