diff --git a/graphdriver/aufs/migrate.go b/graphdriver/aufs/migrate.go index 58145aa989..3d1fa0c0f2 100644 --- a/graphdriver/aufs/migrate.go +++ b/graphdriver/aufs/migrate.go @@ -1,6 +1,7 @@ package aufs import ( + "fmt" "io/ioutil" "os" "path" @@ -20,7 +21,7 @@ func (a *AufsDriver) Migrate(pth string) error { } for _, fi := range fis { if fi.IsDir() && exists(path.Join(pth, fi.Name(), "layer")) && !a.Exists(fi.Name()) { - if err := os.Symlink(path.Join(pth, fi.Name(), "layer"), path.Join(a.rootPath(), "diff", fi.Name())); err != nil { + if err := tryRelocate(path.Join(pth, fi.Name(), "layer"), path.Join(a.rootPath(), "diff", fi.Name())); err != nil { return err } if err := a.Create(fi.Name(), ""); err != nil { @@ -30,3 +31,14 @@ func (a *AufsDriver) Migrate(pth string) error { } return nil } + +// tryRelocate will try to rename the old path to the new pack and if +// the operation fails, it will fallback to a symlink +func tryRelocate(oldPath, newPath string) error { + if err := os.Rename(oldPath, newPath); err != nil { + if sErr := os.Symlink(oldPath, newPath); sErr != nil { + return fmt.Errorf("Unable to relocate %s to %s: Rename err %s Symlink err %s", oldPath, newPath, err, sErr) + } + } + return nil +}