Browse code

Make sure the destination directory exists when using docker insert

Guillaume J. Charmes authored on 2013/04/25 05:51:28
Showing 3 changed files
... ...
@@ -110,7 +110,7 @@ func (builder *Builder) Build(dockerfile io.Reader, stdout io.Writer) error {
110 110
 			}
111 111
 
112 112
 			// Commit the container
113
-			base, err := builder.Commit(c, "", "", "", "")
113
+			base, err = builder.Commit(c, "", "", "", "")
114 114
 			if err != nil {
115 115
 				return err
116 116
 			}
... ...
@@ -104,7 +104,7 @@ func (srv *Server) CmdInsert(stdin io.ReadCloser, stdout rcli.DockerConn, args .
104 104
 	if err != nil {
105 105
 		return err
106 106
 	}
107
-	fmt.Fprintf(stdout, "%s\n", img)
107
+	fmt.Fprintf(stdout, "%s\n", img.Id)
108 108
 	return nil
109 109
 }
110 110
 
... ...
@@ -170,7 +170,12 @@ func (settings *NetworkSettings) PortMappingHuman() string {
170 170
 
171 171
 // Inject the io.Reader at the given path. Note: do not close the reader
172 172
 func (container *Container) Inject(file io.Reader, pth string) error {
173
-	dest, err := os.Open(path.Join(container.rwPath(), pth))
173
+	// Make sure the directory exists
174
+	if err := os.MkdirAll(path.Join(container.rwPath(), path.Dir(pth)), 0755); err != nil {
175
+		return err
176
+	}
177
+	// FIXME: Handle permissions/already existing dest
178
+	dest, err := os.Create(path.Join(container.rwPath(), pth))
174 179
 	if err != nil {
175 180
 		return err
176 181
 	}