mirror of
https://github.com/rwinkhart/go-winio.git
synced 2026-09-05 16:47:31 -04:00
Replace github.com/pkg/errors with stdlib errors
Since Go version 1.13, the standard library has built-in support for wrapping and unwrapping of error values. This commit bumps the minimum version required by the module from 1.12 to 1.13, replaces all calls to errors.Wrap/f with fmt.Errorf and removes the now unneeded dependency on github.com/pkg/errors. Signed-off-by: Michael Hofmann <michael.hofmann@bitgestalt.com>
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
module github.com/Microsoft/go-winio
|
module github.com/Microsoft/go-winio
|
||||||
|
|
||||||
go 1.12
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/pkg/errors v0.9.1
|
|
||||||
github.com/sirupsen/logrus v1.7.0
|
github.com/sirupsen/logrus v1.7.0
|
||||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c
|
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
|
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
|
||||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
|
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
|
||||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
|||||||
@@ -3,11 +3,10 @@
|
|||||||
package security
|
package security
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -72,7 +71,7 @@ func GrantVmGroupAccess(name string) error {
|
|||||||
// Stat (to determine if `name` is a directory).
|
// Stat (to determine if `name` is a directory).
|
||||||
s, err := os.Stat(name)
|
s, err := os.Stat(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "%s os.Stat %s", gvmga, name)
|
return fmt.Errorf("%s os.Stat %s: %w", gvmga, name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a handle to the file/directory. Must defer Close on success.
|
// Get a handle to the file/directory. Must defer Close on success.
|
||||||
@@ -88,7 +87,7 @@ func GrantVmGroupAccess(name string) error {
|
|||||||
sd := uintptr(0)
|
sd := uintptr(0)
|
||||||
origDACL := uintptr(0)
|
origDACL := uintptr(0)
|
||||||
if err := getSecurityInfo(fd, uint32(ot), uint32(si), nil, nil, &origDACL, nil, &sd); err != nil {
|
if err := getSecurityInfo(fd, uint32(ot), uint32(si), nil, nil, &origDACL, nil, &sd); err != nil {
|
||||||
return errors.Wrapf(err, "%s GetSecurityInfo %s", gvmga, name)
|
return fmt.Errorf("%s GetSecurityInfo %s: %w", gvmga, name, err)
|
||||||
}
|
}
|
||||||
defer syscall.LocalFree((syscall.Handle)(unsafe.Pointer(sd)))
|
defer syscall.LocalFree((syscall.Handle)(unsafe.Pointer(sd)))
|
||||||
|
|
||||||
@@ -102,7 +101,7 @@ func GrantVmGroupAccess(name string) error {
|
|||||||
|
|
||||||
// And finally use SetSecurityInfo to apply the updated DACL.
|
// And finally use SetSecurityInfo to apply the updated DACL.
|
||||||
if err := setSecurityInfo(fd, uint32(ot), uint32(si), uintptr(0), uintptr(0), newDACL, uintptr(0)); err != nil {
|
if err := setSecurityInfo(fd, uint32(ot), uint32(si), uintptr(0), uintptr(0), newDACL, uintptr(0)); err != nil {
|
||||||
return errors.Wrapf(err, "%s SetSecurityInfo %s", gvmga, name)
|
return fmt.Errorf("%s SetSecurityInfo %s: %w", gvmga, name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -120,7 +119,7 @@ func createFile(name string, isDir bool) (syscall.Handle, error) {
|
|||||||
}
|
}
|
||||||
fd, err := syscall.CreateFile(&namep[0], da, sm, nil, syscall.OPEN_EXISTING, fa, 0)
|
fd, err := syscall.CreateFile(&namep[0], da, sm, nil, syscall.OPEN_EXISTING, fa, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.Wrapf(err, "%s syscall.CreateFile %s", gvmga, name)
|
return 0, fmt.Errorf("%s syscall.CreateFile %s: %w", gvmga, name, err)
|
||||||
}
|
}
|
||||||
return fd, nil
|
return fd, nil
|
||||||
}
|
}
|
||||||
@@ -131,7 +130,7 @@ func generateDACLWithAcesAdded(name string, isDir bool, origDACL uintptr) (uintp
|
|||||||
// Generate pointers to the SIDs based on the string SIDs
|
// Generate pointers to the SIDs based on the string SIDs
|
||||||
sid, err := syscall.StringToSid(sidVmGroup)
|
sid, err := syscall.StringToSid(sidVmGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.Wrapf(err, "%s syscall.StringToSid %s %s", gvmga, name, sidVmGroup)
|
return 0, fmt.Errorf("%s syscall.StringToSid %s %s: %w", gvmga, name, sidVmGroup, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
inheritance := inheritModeNoInheritance
|
inheritance := inheritModeNoInheritance
|
||||||
@@ -154,7 +153,7 @@ func generateDACLWithAcesAdded(name string, isDir bool, origDACL uintptr) (uintp
|
|||||||
|
|
||||||
modifiedDACL := uintptr(0)
|
modifiedDACL := uintptr(0)
|
||||||
if err := setEntriesInAcl(uintptr(uint32(1)), uintptr(unsafe.Pointer(&eaArray[0])), origDACL, &modifiedDACL); err != nil {
|
if err := setEntriesInAcl(uintptr(uint32(1)), uintptr(unsafe.Pointer(&eaArray[0])), origDACL, &modifiedDACL); err != nil {
|
||||||
return 0, errors.Wrapf(err, "%s SetEntriesInAcl %s", gvmga, name)
|
return 0, fmt.Errorf("%s SetEntriesInAcl %s: %w", gvmga, name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return modifiedDACL, nil
|
return modifiedDACL, nil
|
||||||
|
|||||||
+8
-9
@@ -7,7 +7,6 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/Microsoft/go-winio/pkg/guid"
|
"github.com/Microsoft/go-winio/pkg/guid"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -155,7 +154,7 @@ func CreateVhdx(path string, maxSizeInGb, blockSizeInMb uint32) error {
|
|||||||
// DetachVirtualDisk detaches a virtual hard disk by handle.
|
// DetachVirtualDisk detaches a virtual hard disk by handle.
|
||||||
func DetachVirtualDisk(handle syscall.Handle) (err error) {
|
func DetachVirtualDisk(handle syscall.Handle) (err error) {
|
||||||
if err := detachVirtualDisk(handle, 0, 0); err != nil {
|
if err := detachVirtualDisk(handle, 0, 0); err != nil {
|
||||||
return errors.Wrap(err, "failed to detach virtual disk")
|
return fmt.Errorf("failed to detach virtual disk: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -185,7 +184,7 @@ func AttachVirtualDisk(handle syscall.Handle, attachVirtualDiskFlag AttachVirtua
|
|||||||
parameters,
|
parameters,
|
||||||
nil,
|
nil,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return errors.Wrap(err, "failed to attach virtual disk")
|
return fmt.Errorf("failed to attach virtual disk: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -209,7 +208,7 @@ func AttachVhd(path string) (err error) {
|
|||||||
AttachVirtualDiskFlagNone,
|
AttachVirtualDiskFlagNone,
|
||||||
¶ms,
|
¶ms,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return errors.Wrap(err, "failed to attach virtual disk")
|
return fmt.Errorf("failed to attach virtual disk: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -246,7 +245,7 @@ func OpenVirtualDiskWithParameters(vhdPath string, virtualDiskAccessMask Virtual
|
|||||||
parameters,
|
parameters,
|
||||||
&handle,
|
&handle,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return 0, errors.Wrap(err, "failed to open virtual disk")
|
return 0, fmt.Errorf("failed to open virtual disk: %w", err)
|
||||||
}
|
}
|
||||||
return handle, nil
|
return handle, nil
|
||||||
}
|
}
|
||||||
@@ -272,7 +271,7 @@ func CreateVirtualDisk(path string, virtualDiskAccessMask VirtualDiskAccessMask,
|
|||||||
nil,
|
nil,
|
||||||
&handle,
|
&handle,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return handle, errors.Wrap(err, "failed to create virtual disk")
|
return handle, fmt.Errorf("failed to create virtual disk: %w", err)
|
||||||
}
|
}
|
||||||
return handle, nil
|
return handle, nil
|
||||||
}
|
}
|
||||||
@@ -290,7 +289,7 @@ func GetVirtualDiskPhysicalPath(handle syscall.Handle) (_ string, err error) {
|
|||||||
&diskPathSizeInBytes,
|
&diskPathSizeInBytes,
|
||||||
&diskPhysicalPathBuf[0],
|
&diskPhysicalPathBuf[0],
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return "", errors.Wrap(err, "failed to get disk physical path")
|
return "", fmt.Errorf("failed to get disk physical path: %w", err)
|
||||||
}
|
}
|
||||||
return windows.UTF16ToString(diskPhysicalPathBuf[:]), nil
|
return windows.UTF16ToString(diskPhysicalPathBuf[:]), nil
|
||||||
}
|
}
|
||||||
@@ -314,10 +313,10 @@ func CreateDiffVhd(diffVhdPath, baseVhdPath string, blockSizeInMB uint32) error
|
|||||||
createParams,
|
createParams,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create differencing vhd: %s", err)
|
return fmt.Errorf("failed to create differencing vhd: %w", err)
|
||||||
}
|
}
|
||||||
if err := syscall.CloseHandle(vhdHandle); err != nil {
|
if err := syscall.CloseHandle(vhdHandle); err != nil {
|
||||||
return fmt.Errorf("failed to close differencing vhd handle: %s", err)
|
return fmt.Errorf("failed to close differencing vhd handle: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user