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 LK4D4 commented Feb 6, 2015

LGTM

@tiborvass
Copy link
Collaborator

@tiborvass tiborvass commented Feb 6, 2015

~~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 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 tianon commented Feb 6, 2015

@tiborvass
Copy link
Collaborator

@tiborvass tiborvass commented Feb 6, 2015

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 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 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 tianon commented Feb 6, 2015

@ahmetb
Copy link
Contributor Author

@ahmetb ahmetb commented Feb 6, 2015

@tianon yeah makes sense stick with this change then.

@tiborvass
Copy link
Collaborator

@tiborvass tiborvass commented Feb 6, 2015

@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 tianon commented Feb 6, 2015

@ahmetb
Copy link
Contributor Author

@ahmetb ahmetb commented Feb 6, 2015

I'll work on creating pkg/homedir.

@ahmetb
Copy link
Contributor Author

@ahmetb 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
Collaborator

@tiborvass tiborvass commented Feb 6, 2015

@ahmetalpbalkan fair enough!

@tianon
Copy link
Member

@tianon tianon commented Feb 6, 2015

@duglin
Copy link
Contributor

@duglin 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 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 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
Collaborator

@tiborvass tiborvass commented Feb 6, 2015

LGTM

1 similar comment
@jessfraz
Copy link
Contributor

@jessfraz jessfraz commented Feb 6, 2015

LGTM

tiborvass added a commit that referenced this issue Feb 6, 2015
Extract $HOME usages into utils.GetHomeDir() (reopen #10358)
@tiborvass tiborvass merged commit 9491cec into moby:master Feb 6, 2015
1 check passed
@ahmetb ahmetb deleted the dev/ahmetb-homedir-fix branch Feb 6, 2015
mattmoor
Copy link
Contributor

mattmoor commented on f9ae2d4 Feb 10, 2015

@ahmetalpbalkan Why didn't you use the standard Go library for this?

http://stackoverflow.com/questions/7922270/obtain-users-home-directory

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

thanks.

jonjohnsonjr
Copy link
Contributor

jonjohnsonjr commented on f9ae2d4 Sep 6, 2019

@ahmetalpbalkan Why didn't you use the standard Go library for this?

http://stackoverflow.com/questions/7922270/obtain-users-home-directory

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

thanks.

@mattmoor see containerd/ttrpc#13

@ahmetb
Copy link
Contributor Author

@ahmetb 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 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. 😉

mattmoor
Copy link
Contributor

mattmoor commented on f9ae2d4 Feb 10, 2015

@ahmetalpbalkan Why didn't you use the standard Go library for this?

http://stackoverflow.com/questions/7922270/obtain-users-home-directory

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

thanks.

jonjohnsonjr
Copy link
Contributor

jonjohnsonjr commented on f9ae2d4 Sep 6, 2019

@ahmetalpbalkan Why didn't you use the standard Go library for this?

http://stackoverflow.com/questions/7922270/obtain-users-home-directory

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

thanks.

@mattmoor see containerd/ttrpc#13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

9 participants