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

Extract $HOME usages into utils.GetHomeDir() (reopen #10358) #10602

Merged
merged 2 commits into from
Feb 6, 2015
Merged

Extract $HOME usages into utils.GetHomeDir() (reopen #10358) #10602

merged 2 commits into from
Feb 6, 2015

Conversation

ahmetb
Copy link
Contributor

@ahmetb ahmetb commented Feb 5, 2015

Refactored getHomeDir in docker/docker to GetHomeDir in utils Currently covers all use cases on the client-side.

@ahmetb ahmetb mentioned this pull request Feb 5, 2015
Refactored getHomeDir in docker/docker to GetHomeDir in utils
pkg. Currently covers all use cases on the client-side.

Signed-off-by: Ahmet Alp Balkan <ahmetb@microsoft.com>
@LK4D4
Copy link
Contributor

LK4D4 commented Feb 6, 2015

LGTM

@tiborvass
Copy link
Contributor

~~Can we create a new package for this? not sure how to call it... osutil? ~~

EDIT: +1 to mitchellh/go-homedir or pkg/home.

@ahmetb
Copy link
Contributor Author

ahmetb commented Feb 6, 2015

I'll see if I can vendor that package but it will just add one more trivial dependency. Are we sure we want to do that? It seems pretty harmless to have this in "util" since the pkg already exists.

@tianon
Copy link
Member

tianon commented Feb 6, 2015 via email

@tiborvass
Copy link
Contributor

My position is that it's not because we have a utils package that we want to continue adding to it :)

@phemmer
Copy link
Contributor

phemmer commented Feb 6, 2015

Also, $HOME can't be relied upon. There are many cases where the HOME environment variable is unset.
It's safest to use the os/user package.

package main
import (
    "fmt"
    "os"
    "os/user"
)

func main() {
    fmt.Printf("HOME: %#v\n", os.Getenv("HOME"))
    u, _ := user.Current()
    fmt.Printf("user.HomeDir: %#v\n", u.HomeDir)
}
# env -i go run test.go  
HOME: ""
user.HomeDir: "/home/phemmer"

@ahmetb
Copy link
Contributor Author

ahmetb commented Feb 6, 2015

@phemmer that's actually a cleaner solution. Is there a reason why this hasn't been used in the first place? e.g. mitchellh/go-homedir mentions:

Why not just use os/user? The built-in os/user package requires cgo on Darwin systems. This means that any Go code that uses that package cannot cross compile. But 99% of the time the use for os/user is just to retrieve the home directory, which we can do for the current user without cgo. This library does that, enabling cross-compilation.

@tianon
Copy link
Member

tianon commented Feb 6, 2015 via email

@ahmetb
Copy link
Contributor Author

ahmetb commented Feb 6, 2015

@tianon yeah makes sense stick with this change then.

@tiborvass
Copy link
Contributor

@ahmetalpbalkan @tianon I'm still voting for pkg/home or pkg/homedir. I don't want to add more stuff to utils, only remove.

@tianon
Copy link
Member

tianon commented Feb 6, 2015 via email

@ahmetb
Copy link
Contributor Author

ahmetb commented Feb 6, 2015

I'll work on creating pkg/homedir.

@ahmetb
Copy link
Contributor Author

ahmetb commented Feb 6, 2015

@tiborvass @tianon so there's a possibility that @phemmer brought up, where environment variables are not set. I'm making my changes by ignoring that fact because all the code currently depends on that.

@tiborvass
Copy link
Contributor

@ahmetalpbalkan fair enough!

@tianon
Copy link
Member

tianon commented Feb 6, 2015 via email

@duglin
Copy link
Contributor

duglin commented Feb 6, 2015

Is there a process or set of tests someplace in our build that we could modify to grep all of our code to make sure people don't use $HOME ? Just looking for a way to make sure something doesn't slip by our reviews.

@ahmetb
Copy link
Contributor Author

ahmetb commented Feb 6, 2015

I just added another commit to export this to pkg/homedir. I'll squash into one before submitting. PTAL.

@ahmetb
Copy link
Contributor Author

ahmetb commented Feb 6, 2015

@duglin I believe we don't have any test in place. Certain test cases and daemon-referenced packages are using os.Getenv("HOME") or $PATH. I guess a validation step can be added using grep by whitelisting this file in the makefiles.

Signed-off-by: Ahmet Alp Balkan <ahmetb@microsoft.com>
@tiborvass
Copy link
Contributor

LGTM

1 similar comment
@jessfraz
Copy link
Contributor

jessfraz commented Feb 6, 2015

LGTM

tiborvass added a commit that referenced this pull request Feb 6, 2015
Extract $HOME usages into utils.GetHomeDir() (reopen #10358)
@tiborvass tiborvass merged commit 9491cec into moby:master Feb 6, 2015
@ahmetb ahmetb deleted the dev/ahmetb-homedir-fix branch February 6, 2015 21:59
@ahmetb
Copy link
Contributor Author

ahmetb commented Feb 10, 2015

@mattmoor discussion about this is at #10602. #10602 (comment) it prevents us from cross-compiling binaries since it requires cgo to compile os/user on darwin.

@ahmetb
Copy link
Contributor Author

ahmetb commented Feb 10, 2015

You should also fixup the python client library to read this from the correct location:
https://github.com/docker/docker-py/blob/40770878ad5b6fccc1b5f5866fa1167bb990f3d3/docker/auth/auth.py#L128

Umm, feel free to change it. 😉

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

9 participants