Skip to content

Commit

Permalink
daemon/graphdriver/windows: cleanup errors
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Dec 27, 2022
1 parent 82d6e16 commit 1f4c039
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions daemon/graphdriver/windows/windows.go
Expand Up @@ -110,7 +110,7 @@ func InitFilter(home string, options []string, _ idtools.IdentityMapping) (graph
// Setting file-mode is a no-op on Windows, so passing "0" to make it more
// transparent that the filemode passed has no effect.
if err = system.MkdirAll(home, 0); err != nil {
return nil, fmt.Errorf("windowsfilter failed to create '%s': %v", home, err)
return nil, errors.Wrapf(err, "windowsfilter failed to create '%s'", home)
}

storageOpt := map[string]string{
Expand All @@ -124,7 +124,7 @@ func InitFilter(home string, options []string, _ idtools.IdentityMapping) (graph

opts, err := parseStorageOpt(storageOpt)
if err != nil {
return nil, fmt.Errorf("windowsfilter failed to parse default storage options - %s", err)
return nil, errors.Wrap(err, "windowsfilter failed to parse default storage options")
}

d := &Driver{
Expand Down Expand Up @@ -225,7 +225,7 @@ func (d *Driver) create(id, parent, mountLabel string, readOnly bool, storageOpt

storageOpts, err := parseStorageOpt(storageOpt)
if err != nil {
return fmt.Errorf("Failed to parse storage options - %s", err)
return errors.Wrap(err, "failed to parse storage options")
}

sandboxSize := d.defaultStorageOpts.size
Expand All @@ -234,7 +234,7 @@ func (d *Driver) create(id, parent, mountLabel string, readOnly bool, storageOpt
}

if sandboxSize != 0 {
if err := hcsshim.ExpandSandboxSize(d.info, id, sandboxSize); err != nil {
if err = hcsshim.ExpandSandboxSize(d.info, id, sandboxSize); err != nil {
return err
}
}
Expand All @@ -244,12 +244,12 @@ func (d *Driver) create(id, parent, mountLabel string, readOnly bool, storageOpt
if err2 := hcsshim.DestroyLayer(d.info, id); err2 != nil {
logrus.Warnf("Failed to DestroyLayer %s: %s", id, err2)
}
return fmt.Errorf("Cannot create layer with missing parent %s: %s", parent, err)
return errors.Wrapf(err, "cannot create layer with missing parent %s", parent)
}

if err := d.setLayerChain(id, layerChain); err != nil {
if err2 := hcsshim.DestroyLayer(d.info, id); err2 != nil {
logrus.Warnf("Failed to DestroyLayer %s: %s", id, err2)
logrus.Warnf("failed to DestroyLayer %s: %s", id, err2)
}
return err
}
Expand Down Expand Up @@ -334,7 +334,7 @@ func (d *Driver) Remove(id string) error {
layerPath := filepath.Join(d.info.HomeDir, rID)
tmpID := fmt.Sprintf("%s-removing", rID)
tmpLayerPath := filepath.Join(d.info.HomeDir, tmpID)
if err := os.Rename(layerPath, tmpLayerPath); err != nil && !os.IsNotExist(err) {
if err = os.Rename(layerPath, tmpLayerPath); err != nil && !os.IsNotExist(err) {
if !os.IsPermission(err) {
return err
}
Expand All @@ -351,7 +351,7 @@ func (d *Driver) Remove(id string) error {
}
}
}
if err := hcsshim.DestroyLayer(d.info, tmpID); err != nil {
if err = hcsshim.DestroyLayer(d.info, tmpID); err != nil {
logrus.Errorf("Failed to DestroyLayer %s: %s", id, err)
}

Expand Down Expand Up @@ -383,11 +383,11 @@ func (d *Driver) Get(id, mountLabel string) (string, error) {
return "", err
}

if err := hcsshim.ActivateLayer(d.info, rID); err != nil {
if err = hcsshim.ActivateLayer(d.info, rID); err != nil {
d.ctr.Decrement(rID)
return "", err
}
if err := hcsshim.PrepareLayer(d.info, rID, layerChain); err != nil {
if err = hcsshim.PrepareLayer(d.info, rID, layerChain); err != nil {
d.ctr.Decrement(rID)
if err2 := hcsshim.DeactivateLayer(d.info, rID); err2 != nil {
logrus.Warnf("Failed to Deactivate %s: %s", id, err)
Expand Down Expand Up @@ -466,7 +466,7 @@ func (d *Driver) Cleanup() error {
// warnings if there are errors.
for _, item := range items {
if item.IsDir() && strings.HasSuffix(item.Name(), "-removing") {
if err := hcsshim.DestroyLayer(d.info, item.Name()); err != nil {
if err = hcsshim.DestroyLayer(d.info, item.Name()); err != nil {
logrus.Warnf("Failed to cleanup %s: %s", item.Name(), err)
} else {
logrus.Infof("Cleaned up %s", item.Name())
Expand All @@ -492,7 +492,7 @@ func (d *Driver) Diff(id, _ string) (_ io.ReadCloser, err error) {
}

// this is assuming that the layer is unmounted
if err := hcsshim.UnprepareLayer(d.info, rID); err != nil {
if err = hcsshim.UnprepareLayer(d.info, rID); err != nil {
return nil, err
}
prepare := func() {
Expand Down Expand Up @@ -526,7 +526,7 @@ func (d *Driver) Changes(id, _ string) ([]archive.Change, error) {
return nil, err
}

if err := hcsshim.ActivateLayer(d.info, rID); err != nil {
if err = hcsshim.ActivateLayer(d.info, rID); err != nil {
return nil, err
}
defer func() {
Expand Down Expand Up @@ -820,7 +820,7 @@ func writeLayer(layerData io.Reader, home string, id string, parentLayerPaths ..
}

defer func() {
if err := w.Close(); err != nil {
if err = w.Close(); err != nil {
// This error should not be discarded as a failure here
// could result in an invalid layer on disk
if retErr == nil {
Expand Down Expand Up @@ -855,13 +855,13 @@ func (d *Driver) getLayerChain(id string) ([]string, error) {
if os.IsNotExist(err) {
return nil, nil
} else if err != nil {
return nil, fmt.Errorf("Unable to read layerchain file - %s", err)
return nil, errors.Wrapf(err, "read layerchain file")
}

var layerChain []string
err = json.Unmarshal(content, &layerChain)
if err != nil {
return nil, fmt.Errorf("Failed to unmarshall layerchain json - %s", err)
return nil, errors.Wrapf(err, "failed to unmarshal layerchain JSON")
}

return layerChain, nil
Expand All @@ -871,13 +871,13 @@ func (d *Driver) getLayerChain(id string) ([]string, error) {
func (d *Driver) setLayerChain(id string, chain []string) error {
content, err := json.Marshal(&chain)
if err != nil {
return fmt.Errorf("Failed to marshall layerchain json - %s", err)
return errors.Wrapf(err, "failed to marshal layerchain JSON")
}

jPath := filepath.Join(d.dir(id), "layerchain.json")
err = os.WriteFile(jPath, content, 0600)
err = os.WriteFile(jPath, content, 0o600)
if err != nil {
return fmt.Errorf("Unable to write layerchain file - %s", err)
return errors.Wrap(err, "write layerchain file")
}

return nil
Expand Down

0 comments on commit 1f4c039

Please sign in to comment.