When doing WriteEnviron we would create ~/.juju/environments.yaml
but we weren't creating the containing dir. (Which meant actually
running 'juju init -w' wouldn't work for new users.)
This adds an unconditional MkdirAll() before writing environments.yaml,
but that should be ok, as it is a no-op if the dir already exists.
Reviewers: mp+153283_ code.launchpad. net,
Message:
Please take a look.
Description:
environs/config: ensure ~/.juju exists
When doing WriteEnviron we would create ~/.juju/ environments. yaml
but we weren't creating the containing dir. (Which meant actually
running 'juju init -w' wouldn't work for new users.)
This adds an unconditional MkdirAll() before writing environments.yaml,
but that should be ok, as it is a no-op if the dir already exists.
https:/ /code.launchpad .net/~jameinel/ juju-core/ init-1147771/ +merge/ 153283
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/7759044/
Affected files: init_test. go config_ test.go
A [revision details]
M cmd/juju/
M environs/config.go
M environs/
M testing/environ.go
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>
Index: environs/config.go config. go' filepath. Dir(environsFil epath), 0755); err != nil { WriteFile( environsFilepat h, []byte( fileContents) , 0666);
=== modified file 'environs/
--- environs/config.go 2013-02-04 01:20:55 +0000
+++ environs/config.go 2013-03-14 04:51:54 +0000
@@ -153,6 +153,9 @@
if err != nil {
return "", err
}
+ if err := os.MkdirAll(
+ return "", err
+ }
if err := ioutil.
err != nil {
return "", err
}
Index: environs/ config_ test.go config_ test.go' config_ test.go 2013-03-12 23:02:49 +0000 config_ test.go 2013-03-14 04:51:54 +0000
=== modified file 'environs/
--- environs/
+++ environs/
@@ -141,7 +141,7 @@
}
func (suite) TestDefaultConf igFile( c *C) { MakeFakeHomeNoE nvironments( c, "only").Restore() MakeEmptyFakeHo me(c).Restore( )
- defer testing.
+ defer testing.
env := `
environments:
Index: testing/environ.go environ. go' nvironments( c *C, certNames ...string) FakeHome { me(c)
=== modified file 'testing/
--- testing/environ.go 2013-03-12 23:02:49 +0000
+++ testing/environ.go 2013-03-14 04:51:54 +0000
@@ -50,8 +50,7 @@
// 'certNames' specified, and the id_rsa.pub file is written to to the .ssh
// dir.
func MakeFakeHomeNoE
- oldHome := os.Getenv("HOME")
- os.Setenv("HOME", c.MkDir())
+ fake := MakeEmptyFakeHo
err := os.Mkdir( HomePath( ".juju" ), 0755) WriteFile( HomePath( ".ssh", "id_rsa.pub"), []byte("auth
c.Assert(err, IsNil)
@@ -68,7 +67,7 @@
err = ioutil.
key\n"), 0666)
c.Assert(err, IsNil)
- return FakeHome(oldHome)
+ return fake
}
// MakeFakeHome creates a new temporary directory through the test checker,
@@ -88,6 +87,13 @@
return fake
}
+func MakeEmptyFakeHome(c *C) FakeHome { []string{ os.Getenv( "HOME") }, names...) Join(all. ..)
+ oldHome := os.Getenv("HOME")
+ os.Setenv("HOME", c.MkDir())
+
+ return FakeHome(oldHome)
+}
+
func HomePath(names ...string) string {
all := append(
return filepath.
Index: cmd/juju/ init_test. go init_test. go' init_test. go 2013-03-12 23:34:53 +0000 init_test. go 2013-03-14 04:51:54 +0000
=== modified file 'cmd/juju/
--- cmd/juju/
+++ cmd/juju/
@@ -15,7 +15,7 @@
var _ = Suite(&InitSuite{})
func (*InitSuite) TestBoilerPlate Environment( c *C) { MakeFakeHomeNoE nvironments( c, "empty").Restore() MakeEmptyFakeHo me(c).Restore( ) &InitCommand{ }, ctx, []string{"-w"})
- defer testing.
+ defer testing.
// run without an environments.yaml
ctx := testing.Context(c)
code := cmd.Main(