From b54305ae2330bcadd2ef657a17f4a87896031d1f Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Wed, 21 Jan 2015 21:40:19 -0500 Subject: [PATCH] Do not return err on symlink eval Signed-off-by: Brian Goff --- integration-cli/docker_cli_daemon_test.go | 74 +++++++++++++++++++++++ volumes/repository.go | 7 ++- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index 95188296d8..d17e8093ad 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -403,3 +403,77 @@ func TestDaemonKeyMigration(t *testing.T) { logDone("daemon - key migration") } + +// Simulate an older daemon (pre 1.3) coming up with volumes specified in containers +// without corrosponding volume json +func TestDaemonUpgradeWithVolumes(t *testing.T) { + d := NewDaemon(t) + + graphDir := filepath.Join(os.TempDir(), "docker-test") + defer os.RemoveAll(graphDir) + if err := d.StartWithBusybox("-g", graphDir); err != nil { + t.Fatal(err) + } + + tmpDir := filepath.Join(os.TempDir(), "test") + defer os.RemoveAll(tmpDir) + + if out, err := d.Cmd("create", "-v", tmpDir+":/foo", "--name=test", "busybox"); err != nil { + t.Fatal(err, out) + } + + if err := d.Stop(); err != nil { + t.Fatal(err) + } + + // Remove this since we're expecting the daemon to re-create it too + if err := os.RemoveAll(tmpDir); err != nil { + t.Fatal(err) + } + + configDir := filepath.Join(graphDir, "volumes") + + if err := os.RemoveAll(configDir); err != nil { + t.Fatal(err) + } + + if err := d.Start("-g", graphDir); err != nil { + t.Fatal(err) + } + + if _, err := os.Stat(tmpDir); os.IsNotExist(err) { + t.Fatalf("expected volume path %s to exist but it does not", tmpDir) + } + + dir, err := ioutil.ReadDir(configDir) + if err != nil { + t.Fatal(err) + } + if len(dir) == 0 { + t.Fatalf("expected volumes config dir to contain data for new volume") + } + + // Now with just removing the volume config and not the volume data + if err := d.Stop(); err != nil { + t.Fatal(err) + } + + if err := os.RemoveAll(configDir); err != nil { + t.Fatal(err) + } + + if err := d.Start("-g", graphDir); err != nil { + t.Fatal(err) + } + + dir, err = ioutil.ReadDir(configDir) + if err != nil { + t.Fatal(err) + } + + if len(dir) == 0 { + t.Fatalf("expected volumes config dir to contain data for new volume") + } + + logDone("daemon - volumes from old(pre 1.3) daemon work") +} diff --git a/volumes/repository.go b/volumes/repository.go index 91f98fc060..e125677680 100644 --- a/volumes/repository.go +++ b/volumes/repository.go @@ -57,9 +57,10 @@ func (r *Repository) newVolume(path string, writable bool) (*Volume, error) { } path = filepath.Clean(path) - path, err = filepath.EvalSymlinks(path) - if err != nil { - return nil, err + // Ignore the error here since the path may not exist + // Really just want to make sure the path we are using is real(or non-existant) + if cleanPath, err := filepath.EvalSymlinks(path); err == nil { + path = cleanPath } v := &Volume{