Browse code

Merge pull request #792 from dotcloud/780-diff-fix

- Runtime: fix Path corruption in 'docker diff'

Guillaume J. Charmes authored on 2013/06/04 02:06:25
Showing 2 changed files
... ...
@@ -65,7 +65,7 @@ func Changes(layers []string, rw string) ([]Change, error) {
65 65
 		file := filepath.Base(path)
66 66
 		// If there is a whiteout, then the file was removed
67 67
 		if strings.HasPrefix(file, ".wh.") {
68
-			originalFile := strings.TrimLeft(file, ".wh.")
68
+			originalFile := strings.TrimPrefix(file, ".wh.")
69 69
 			change.Path = filepath.Join(filepath.Dir(path), originalFile)
70 70
 			change.Kind = ChangeDelete
71 71
 		} else {
... ...
@@ -217,6 +217,37 @@ func TestDiff(t *testing.T) {
217 217
 			t.Fatalf("/etc/passwd should not be present in the diff after commit.")
218 218
 		}
219 219
 	}
220
+
221
+	// Create a new containere
222
+	container3, err := builder.Create(
223
+		&Config{
224
+			Image: GetTestImage(runtime).Id,
225
+			Cmd:   []string{"rm", "/bin/httpd"},
226
+		},
227
+	)
228
+	if err != nil {
229
+		t.Fatal(err)
230
+	}
231
+	defer runtime.Destroy(container3)
232
+
233
+	if err := container3.Run(); err != nil {
234
+		t.Fatal(err)
235
+	}
236
+
237
+	// Check the changelog
238
+	c, err = container3.Changes()
239
+	if err != nil {
240
+		t.Fatal(err)
241
+	}
242
+	success = false
243
+	for _, elem := range c {
244
+		if elem.Path == "/bin/httpd" && elem.Kind == 2 {
245
+			success = true
246
+		}
247
+	}
248
+	if !success {
249
+		t.Fatalf("/bin/httpd should be present in the diff after commit.")
250
+	}
220 251
 }
221 252
 
222 253
 func TestCommitAutoRun(t *testing.T) {