Remove unfinished VFS layer if its creation fails.
Current implementation of VFS driver performs the copy of the parent layer during the creation of new (child) layer, but does not clean the destination if the copy process fails. From the consuming application perspective, this make storage leaks possible, e.g. an attempt to create new container with podman, if failed in the middle of the copy due to disk overflow, leaves unfinished container layer stray. To avoid obliging the application (or the end user) to take care of such possible leaks, cleanup is added. Signed-off-by: Danila Kiver <danila.kiver@mail.ru>
This commit is contained in:
parent
8eed0c36d1
commit
fe0e9e0b58
|
|
@ -118,7 +118,7 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
|
|||
return d.create(id, parent, opts, true)
|
||||
}
|
||||
|
||||
func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts, ro bool) error {
|
||||
func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts, ro bool) (retErr error) {
|
||||
if opts != nil && len(opts.StorageOpt) != 0 {
|
||||
return fmt.Errorf("--storage-opt is not supported for vfs")
|
||||
}
|
||||
|
|
@ -133,6 +133,13 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts, ro bool
|
|||
if err := idtools.MkdirAllAndChown(filepath.Dir(dir), 0700, rootIDs); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
os.RemoveAll(dir)
|
||||
}
|
||||
}()
|
||||
|
||||
if parent != "" {
|
||||
st, err := system.Stat(d.dir(parent))
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue