mirror of
https://github.com/octoleo/restic.git
synced 2024-11-23 21:27:34 +00:00
vss: Fix issues reported by linters
This commit is contained in:
parent
88c509e3e9
commit
3bac1f0135
@ -165,7 +165,6 @@ func (fs *LocalVss) isMountPointExcluded(mountPoint string) bool {
|
|||||||
// If creation of a snapshot fails the file's original path is returned as
|
// If creation of a snapshot fails the file's original path is returned as
|
||||||
// a fallback.
|
// a fallback.
|
||||||
func (fs *LocalVss) snapshotPath(path string) string {
|
func (fs *LocalVss) snapshotPath(path string) string {
|
||||||
|
|
||||||
fixPath := fixpath(path)
|
fixPath := fixpath(path)
|
||||||
|
|
||||||
if strings.HasPrefix(fixPath, `\\?\UNC\`) {
|
if strings.HasPrefix(fixPath, `\\?\UNC\`) {
|
||||||
@ -268,9 +267,8 @@ func (fs *LocalVss) snapshotPath(path string) string {
|
|||||||
snapshotPath = fs.Join(snapshot.GetSnapshotDeviceObject(),
|
snapshotPath = fs.Join(snapshot.GetSnapshotDeviceObject(),
|
||||||
strings.TrimPrefix(fixPath, volumeName))
|
strings.TrimPrefix(fixPath, volumeName))
|
||||||
if snapshotPath == snapshot.GetSnapshotDeviceObject() {
|
if snapshotPath == snapshot.GetSnapshotDeviceObject() {
|
||||||
snapshotPath = snapshotPath + string(filepath.Separator)
|
snapshotPath += string(filepath.Separator)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// no snapshot is available for the requested path:
|
// no snapshot is available for the requested path:
|
||||||
// -> try to backup without a snapshot
|
// -> try to backup without a snapshot
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
type HRESULT uint
|
type HRESULT uint
|
||||||
|
|
||||||
// HRESULT constant values necessary for using VSS api.
|
// HRESULT constant values necessary for using VSS api.
|
||||||
|
//nolint:golint
|
||||||
const (
|
const (
|
||||||
S_OK HRESULT = 0x00000000
|
S_OK HRESULT = 0x00000000
|
||||||
E_ACCESSDENIED HRESULT = 0x80070005
|
E_ACCESSDENIED HRESULT = 0x80070005
|
||||||
@ -256,6 +257,7 @@ type IVssBackupComponents struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IVssBackupComponentsVTable is the vtable for IVssBackupComponents.
|
// IVssBackupComponentsVTable is the vtable for IVssBackupComponents.
|
||||||
|
// nolint:structcheck
|
||||||
type IVssBackupComponentsVTable struct {
|
type IVssBackupComponentsVTable struct {
|
||||||
ole.IUnknownVtbl
|
ole.IUnknownVtbl
|
||||||
getWriterComponentsCount uintptr
|
getWriterComponentsCount uintptr
|
||||||
@ -415,7 +417,7 @@ func (vss *IVssBackupComponents) AddToSnapshotSet(volumeName string, idSnapshot
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var result uintptr = 0
|
var result uintptr
|
||||||
|
|
||||||
if runtime.GOARCH == "386" {
|
if runtime.GOARCH == "386" {
|
||||||
id := (*[4]uintptr)(unsafe.Pointer(ole.IID_NULL))
|
id := (*[4]uintptr)(unsafe.Pointer(ole.IID_NULL))
|
||||||
@ -479,9 +481,9 @@ func (vss *IVssBackupComponents) DoSnapshotSet() (*IVSSAsync, error) {
|
|||||||
|
|
||||||
// DeleteSnapshots calls the equivalent VSS api.
|
// DeleteSnapshots calls the equivalent VSS api.
|
||||||
func (vss *IVssBackupComponents) DeleteSnapshots(snapshotID ole.GUID) (int32, ole.GUID, error) {
|
func (vss *IVssBackupComponents) DeleteSnapshots(snapshotID ole.GUID) (int32, ole.GUID, error) {
|
||||||
var deletedSnapshots int32 = 0
|
var deletedSnapshots int32
|
||||||
var nondeletedSnapshotID ole.GUID
|
var nondeletedSnapshotID ole.GUID
|
||||||
var result uintptr = 0
|
var result uintptr
|
||||||
|
|
||||||
if runtime.GOARCH == "386" {
|
if runtime.GOARCH == "386" {
|
||||||
id := (*[4]uintptr)(unsafe.Pointer(&snapshotID))
|
id := (*[4]uintptr)(unsafe.Pointer(&snapshotID))
|
||||||
@ -505,7 +507,7 @@ func (vss *IVssBackupComponents) DeleteSnapshots(snapshotID ole.GUID) (int32, ol
|
|||||||
// GetSnapshotProperties calls the equivalent VSS api.
|
// GetSnapshotProperties calls the equivalent VSS api.
|
||||||
func (vss *IVssBackupComponents) GetSnapshotProperties(snapshotID ole.GUID,
|
func (vss *IVssBackupComponents) GetSnapshotProperties(snapshotID ole.GUID,
|
||||||
properties *VssSnapshotProperties) error {
|
properties *VssSnapshotProperties) error {
|
||||||
var result uintptr = 0
|
var result uintptr
|
||||||
|
|
||||||
if runtime.GOARCH == "386" {
|
if runtime.GOARCH == "386" {
|
||||||
id := (*[4]uintptr)(unsafe.Pointer(&snapshotID))
|
id := (*[4]uintptr)(unsafe.Pointer(&snapshotID))
|
||||||
@ -528,8 +530,8 @@ func vssFreeSnapshotProperties(properties *VssSnapshotProperties) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// this function always succeeds and returns no value
|
||||||
proc.Call(uintptr(unsafe.Pointer(properties)))
|
_, _, _ = proc.Call(uintptr(unsafe.Pointer(properties)))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,6 +546,7 @@ func (vss *IVssBackupComponents) BackupComplete() (*IVSSAsync, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// VssSnapshotProperties defines the properties of a VSS snapshot as part of the VSS api.
|
// VssSnapshotProperties defines the properties of a VSS snapshot as part of the VSS api.
|
||||||
|
// nolint:structcheck
|
||||||
type VssSnapshotProperties struct {
|
type VssSnapshotProperties struct {
|
||||||
snapshotID ole.GUID
|
snapshotID ole.GUID
|
||||||
snapshotSetID ole.GUID
|
snapshotSetID ole.GUID
|
||||||
@ -700,7 +703,12 @@ func initializeVssCOMInterface() (*ole.IUnknown, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ensure COM is initialized before use
|
// ensure COM is initialized before use
|
||||||
ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
|
if err = ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED); err != nil {
|
||||||
|
// CoInitializeEx returns 1 if COM is already initialized
|
||||||
|
if oleErr, ok := err.(*ole.OleError); !ok || oleErr.Code() != 1 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var oleIUnknown *ole.IUnknown
|
var oleIUnknown *ole.IUnknown
|
||||||
result, _, _ := vssInstance.Call(uintptr(unsafe.Pointer(&oleIUnknown)))
|
result, _, _ := vssInstance.Call(uintptr(unsafe.Pointer(&oleIUnknown)))
|
||||||
@ -761,7 +769,6 @@ func GetVolumeNameForVolumeMountPoint(mountPoint string) (string, error) {
|
|||||||
func NewVssSnapshot(
|
func NewVssSnapshot(
|
||||||
volume string, timeout time.Duration, filter VolumeFilter, msgError ErrorHandler) (VssSnapshot, error) {
|
volume string, timeout time.Duration, filter VolumeFilter, msgError ErrorHandler) (VssSnapshot, error) {
|
||||||
is64Bit, err := isRunningOn64BitWindows()
|
is64Bit, err := isRunningOn64BitWindows()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return VssSnapshot{}, newVssTextError(fmt.Sprintf(
|
return VssSnapshot{}, newVssTextError(fmt.Sprintf(
|
||||||
"Failed to detect windows architecture: %s", err.Error()))
|
"Failed to detect windows architecture: %s", err.Error()))
|
||||||
@ -884,8 +891,10 @@ func NewVssSnapshot(
|
|||||||
return VssSnapshot{}, err
|
return VssSnapshot{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
mountPointInfo[mountPoint] = MountPoint{isSnapshotted: true,
|
mountPointInfo[mountPoint] = MountPoint{
|
||||||
snapshotSetID: mountPointSnapshotSetID}
|
isSnapshotted: true,
|
||||||
|
snapshotSetID: mountPointSnapshotSetID,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -903,7 +912,7 @@ func NewVssSnapshot(
|
|||||||
err = callAsyncFunctionAndWait(iVssBackupComponents.DoSnapshotSet, "DoSnapshotSet",
|
err = callAsyncFunctionAndWait(iVssBackupComponents.DoSnapshotSet, "DoSnapshotSet",
|
||||||
deadline)
|
deadline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
iVssBackupComponents.AbortBackup()
|
_ = iVssBackupComponents.AbortBackup()
|
||||||
iVssBackupComponents.Release()
|
iVssBackupComponents.Release()
|
||||||
return VssSnapshot{}, err
|
return VssSnapshot{}, err
|
||||||
}
|
}
|
||||||
@ -911,13 +920,12 @@ func NewVssSnapshot(
|
|||||||
var snapshotProperties VssSnapshotProperties
|
var snapshotProperties VssSnapshotProperties
|
||||||
err = iVssBackupComponents.GetSnapshotProperties(snapshotSetID, &snapshotProperties)
|
err = iVssBackupComponents.GetSnapshotProperties(snapshotSetID, &snapshotProperties)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
iVssBackupComponents.AbortBackup()
|
_ = iVssBackupComponents.AbortBackup()
|
||||||
iVssBackupComponents.Release()
|
iVssBackupComponents.Release()
|
||||||
return VssSnapshot{}, err
|
return VssSnapshot{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for mountPoint, info := range mountPointInfo {
|
for mountPoint, info := range mountPointInfo {
|
||||||
|
|
||||||
if !info.isSnapshotted {
|
if !info.isSnapshotted {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -936,8 +944,10 @@ func NewVssSnapshot(
|
|||||||
mountPointInfo[mountPoint] = info
|
mountPointInfo[mountPoint] = info
|
||||||
}
|
}
|
||||||
|
|
||||||
return VssSnapshot{iVssBackupComponents, snapshotSetID, snapshotProperties,
|
return VssSnapshot{
|
||||||
snapshotProperties.GetSnapshotDeviceObject(), mountPointInfo, time.Until(deadline)}, nil
|
iVssBackupComponents, snapshotSetID, snapshotProperties,
|
||||||
|
snapshotProperties.GetSnapshotDeviceObject(), mountPointInfo, time.Until(deadline),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete deletes the created snapshot.
|
// Delete deletes the created snapshot.
|
||||||
@ -968,7 +978,7 @@ func (p *VssSnapshot) Delete() error {
|
|||||||
|
|
||||||
if _, _, e := p.iVssBackupComponents.DeleteSnapshots(p.snapshotID); e != nil {
|
if _, _, e := p.iVssBackupComponents.DeleteSnapshots(p.snapshotID); e != nil {
|
||||||
err = newVssTextError(fmt.Sprintf("Failed to delete snapshot: %s", e.Error()))
|
err = newVssTextError(fmt.Sprintf("Failed to delete snapshot: %s", e.Error()))
|
||||||
p.iVssBackupComponents.AbortBackup()
|
_ = p.iVssBackupComponents.AbortBackup()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1079,6 +1089,7 @@ func enumerateMountedFolders(volume string) ([]string, error) {
|
|||||||
return mountedFolders, nil
|
return mountedFolders, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:errcheck
|
||||||
defer windows.FindVolumeMountPointClose(handle)
|
defer windows.FindVolumeMountPointClose(handle)
|
||||||
|
|
||||||
volumeMountPoint := syscall.UTF16ToString(volumeMountPointBuffer)
|
volumeMountPoint := syscall.UTF16ToString(volumeMountPointBuffer)
|
||||||
|
Loading…
Reference in New Issue
Block a user