mirror of https://github.com/docker/docs.git
Use tryRelocate to fall back to symlink if rename fails
This commit is contained in:
parent
a518b84751
commit
94e854823f
|
@ -1,6 +1,7 @@
|
||||||
package aufs
|
package aufs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -20,7 +21,7 @@ func (a *AufsDriver) Migrate(pth string) error {
|
||||||
}
|
}
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
if fi.IsDir() && exists(path.Join(pth, fi.Name(), "layer")) && !a.Exists(fi.Name()) {
|
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
|
return err
|
||||||
}
|
}
|
||||||
if err := a.Create(fi.Name(), ""); err != nil {
|
if err := a.Create(fi.Name(), ""); err != nil {
|
||||||
|
@ -30,3 +31,14 @@ func (a *AufsDriver) Migrate(pth string) error {
|
||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue