Merge pull request #10261 from cpuguy83/fix_volume_err_on_symlink_eval

Do not return err on symlink eval
This commit is contained in:
Michael Crosby 2015-01-26 15:12:46 -08:00
commit 3466baafc1
2 changed files with 78 additions and 3 deletions

View File

@ -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")
}

View File

@ -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{