Skip to content

Commit 43aa788

Browse files
committed
cleanup <ID>-init dir and the symlink in <rootdir>/l on failure
Signed-off-by: zzzzzzzzzy9 <zhang.yu58@zte.com.cn>
1 parent 294f0c3 commit 43aa788

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

layer/layer_store.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,17 @@ func (ls *layerStore) CreateRWLayer(name string, parent ChainID, opts *CreateRWL
531531
if err := ls.driver.CreateReadWrite(m.mountID, parentID, createOpts); err != nil {
532532
return nil, err
533533
}
534+
defer func() {
535+
if retErr != nil {
536+
// cleanup on failure
537+
if err := ls.driver.Remove(m.mountID); err != nil {
538+
log.G(context.TODO()).WithFields(log.Fields{
539+
"mountID": m.mountID,
540+
"error": err,
541+
}).Warnf("Removing RWlayer after failure: %v", retErr)
542+
}
543+
}
544+
}()
534545
if err := ls.saveMount(m); err != nil {
535546
return nil, err
536547
}
@@ -642,7 +653,7 @@ func (ls *layerStore) saveMount(mount *mountedLayer) error {
642653
return nil
643654
}
644655

645-
func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc MountInit, storageOpt map[string]string) (string, error) {
656+
func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc MountInit, storageOpt map[string]string) (ID string, retErr error) {
646657
// Use "<graph-id>-init" to maintain compatibility with graph drivers
647658
// which are expecting this layer with this special name. If all
648659
// graph drivers can be updated to not rely on knowing about this layer
@@ -657,6 +668,17 @@ func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc Mou
657668
if err := ls.driver.CreateReadWrite(initID, parent, createOpts); err != nil {
658669
return "", err
659670
}
671+
defer func() {
672+
if retErr != nil {
673+
// cleanup on failure
674+
if err := ls.driver.Remove(initID); err != nil {
675+
log.G(context.TODO()).WithFields(log.Fields{
676+
"initID": initID,
677+
"error": err,
678+
}).Warnf("Removing RWlayer after failure: %v", retErr)
679+
}
680+
}
681+
}()
660682
p, err := ls.driver.Get(initID, "")
661683
if err != nil {
662684
return "", err

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy