diff --git a/daemon/graphdriver/windows/windows.go b/daemon/graphdriver/windows/windows.go index 1cdd8591f7642..fc36b71859252 100644 --- a/daemon/graphdriver/windows/windows.go +++ b/daemon/graphdriver/windows/windows.go @@ -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 := make(map[string]string) @@ -123,7 +123,7 @@ func InitFilter(home string, options []string, _ idtools.IdentityMapping) (graph storageOpts, 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{ @@ -224,7 +224,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 @@ -233,7 +233,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 } } @@ -243,12 +243,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 } @@ -333,7 +333,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 } @@ -350,7 +350,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) } @@ -382,11 +382,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) @@ -465,7 +465,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()) @@ -491,7 +491,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() { @@ -525,7 +525,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() { @@ -819,7 +819,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 { @@ -854,13 +854,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 @@ -870,13 +870,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