Browse code

Do not return err on symlink eval

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2015/01/22 11:40:19
Showing 2 changed files
... ...
@@ -403,3 +403,77 @@ func TestDaemonKeyMigration(t *testing.T) {
403 403
 
404 404
 	logDone("daemon - key migration")
405 405
 }
406
+
407
+// Simulate an older daemon (pre 1.3) coming up with volumes specified in containers
408
+//	without corrosponding volume json
409
+func TestDaemonUpgradeWithVolumes(t *testing.T) {
410
+	d := NewDaemon(t)
411
+
412
+	graphDir := filepath.Join(os.TempDir(), "docker-test")
413
+	defer os.RemoveAll(graphDir)
414
+	if err := d.StartWithBusybox("-g", graphDir); err != nil {
415
+		t.Fatal(err)
416
+	}
417
+
418
+	tmpDir := filepath.Join(os.TempDir(), "test")
419
+	defer os.RemoveAll(tmpDir)
420
+
421
+	if out, err := d.Cmd("create", "-v", tmpDir+":/foo", "--name=test", "busybox"); err != nil {
422
+		t.Fatal(err, out)
423
+	}
424
+
425
+	if err := d.Stop(); err != nil {
426
+		t.Fatal(err)
427
+	}
428
+
429
+	// Remove this since we're expecting the daemon to re-create it too
430
+	if err := os.RemoveAll(tmpDir); err != nil {
431
+		t.Fatal(err)
432
+	}
433
+
434
+	configDir := filepath.Join(graphDir, "volumes")
435
+
436
+	if err := os.RemoveAll(configDir); err != nil {
437
+		t.Fatal(err)
438
+	}
439
+
440
+	if err := d.Start("-g", graphDir); err != nil {
441
+		t.Fatal(err)
442
+	}
443
+
444
+	if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
445
+		t.Fatalf("expected volume path %s to exist but it does not", tmpDir)
446
+	}
447
+
448
+	dir, err := ioutil.ReadDir(configDir)
449
+	if err != nil {
450
+		t.Fatal(err)
451
+	}
452
+	if len(dir) == 0 {
453
+		t.Fatalf("expected volumes config dir to contain data for new volume")
454
+	}
455
+
456
+	// Now with just removing the volume config and not the volume data
457
+	if err := d.Stop(); err != nil {
458
+		t.Fatal(err)
459
+	}
460
+
461
+	if err := os.RemoveAll(configDir); err != nil {
462
+		t.Fatal(err)
463
+	}
464
+
465
+	if err := d.Start("-g", graphDir); err != nil {
466
+		t.Fatal(err)
467
+	}
468
+
469
+	dir, err = ioutil.ReadDir(configDir)
470
+	if err != nil {
471
+		t.Fatal(err)
472
+	}
473
+
474
+	if len(dir) == 0 {
475
+		t.Fatalf("expected volumes config dir to contain data for new volume")
476
+	}
477
+
478
+	logDone("daemon - volumes from old(pre 1.3) daemon work")
479
+}
... ...
@@ -57,9 +57,10 @@ func (r *Repository) newVolume(path string, writable bool) (*Volume, error) {
57 57
 	}
58 58
 	path = filepath.Clean(path)
59 59
 
60
-	path, err = filepath.EvalSymlinks(path)
61
-	if err != nil {
62
-		return nil, err
60
+	// Ignore the error here since the path may not exist
61
+	// Really just want to make sure the path we are using is real(or non-existant)
62
+	if cleanPath, err := filepath.EvalSymlinks(path); err == nil {
63
+		path = cleanPath
63 64
 	}
64 65
 
65 66
 	v := &Volume{