Remove and create workdir if state dir does not exist
This is the case where the work dir could still exist if a machine reboots, reseting the state dir. On container creation, we should just clear out the work dir. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
37a6a91bdf
commit
ac78a5b615
@ -58,16 +58,7 @@ func NewBundle(ctx context.Context, root, state, id string, spec []byte) (b *Bun
|
|||||||
Path: filepath.Join(state, ns, id),
|
Path: filepath.Join(state, ns, id),
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
}
|
}
|
||||||
paths := []string{b.Path, work}
|
var paths []string
|
||||||
// create base directories
|
|
||||||
for _, d := range paths {
|
|
||||||
if err := os.MkdirAll(filepath.Dir(d), 0711); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := os.Mkdir(d, 0711); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, d := range paths {
|
for _, d := range paths {
|
||||||
@ -75,6 +66,28 @@ func NewBundle(ctx context.Context, root, state, id string, spec []byte) (b *Bun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
// create state directory for the bundle
|
||||||
|
if err := os.MkdirAll(filepath.Dir(b.Path), 0711); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := os.Mkdir(b.Path, 0711); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
paths = append(paths, b.Path)
|
||||||
|
// create working directory for the bundle
|
||||||
|
if err := os.MkdirAll(filepath.Dir(work), 0711); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := os.Mkdir(work, 0711); err != nil {
|
||||||
|
if !os.IsExist(err) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
os.RemoveAll(work)
|
||||||
|
if err := os.Mkdir(work, 0711); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
paths = append(paths, work)
|
||||||
// create rootfs dir
|
// create rootfs dir
|
||||||
if err := os.Mkdir(filepath.Join(b.Path, "rootfs"), 0711); err != nil {
|
if err := os.Mkdir(filepath.Join(b.Path, "rootfs"), 0711); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user