Rearange code

This commit is contained in:
DRON-666 2024-04-29 01:27:34 +03:00
parent 7ee889bb0d
commit 125dba23c5
2 changed files with 16 additions and 20 deletions

View file

@ -274,11 +274,7 @@ func TestParseProvider(t *testing.T) {
if err != nil { if err != nil {
result = err.Error() result = err.Error()
} }
matched, err := regexp.MatchString(test.result, result) if test.result != result || test.result == "" {
if err != nil {
panic(err)
}
if !matched || test.result == "" {
t.Fatalf("wrong result, want:\n %#v\ngot:\n %#v", test.result, result) t.Fatalf("wrong result, want:\n %#v\ngot:\n %#v", test.result, result)
} }
} else if !ole.IsEqualGUID(id, test.id) { } else if !ole.IsEqualGUID(id, test.id) {

View file

@ -537,13 +537,6 @@ func vssFreeSnapshotProperties(properties *VssSnapshotProperties) error {
return nil return nil
} }
func vssFreeProviderProperties(p *VssProviderProperties) {
ole.CoTaskMemFree(uintptr(unsafe.Pointer(p.providerName)))
p.providerName = nil
ole.CoTaskMemFree(uintptr(unsafe.Pointer(p.providerVersion)))
p.providerName = nil
}
// BackupComplete calls the equivalent VSS api. // BackupComplete calls the equivalent VSS api.
func (vss *IVssBackupComponents) BackupComplete() (*IVSSAsync, error) { func (vss *IVssBackupComponents) BackupComplete() (*IVSSAsync, error) {
var oleIUnknown *ole.IUnknown var oleIUnknown *ole.IUnknown
@ -583,6 +576,13 @@ type VssProviderProperties struct {
classID ole.GUID classID ole.GUID
} }
func vssFreeProviderProperties(p *VssProviderProperties) {
ole.CoTaskMemFree(uintptr(unsafe.Pointer(p.providerName)))
p.providerName = nil
ole.CoTaskMemFree(uintptr(unsafe.Pointer(p.providerVersion)))
p.providerVersion = nil
}
// GetSnapshotDeviceObject returns root path to access the snapshot files // GetSnapshotDeviceObject returns root path to access the snapshot files
// and folders. // and folders.
func (p *VssSnapshotProperties) GetSnapshotDeviceObject() string { func (p *VssSnapshotProperties) GetSnapshotDeviceObject() string {
@ -1084,14 +1084,6 @@ func (p *VssSnapshot) Delete() error {
} }
func getProviderID(provider string) (*ole.GUID, error) { func getProviderID(provider string) (*ole.GUID, error) {
comInterface, err := ole.CreateInstance(CLSID_VSS_COORDINATOR, UIID_IVSS_ADMIN)
if err != nil {
return nil, err
}
defer comInterface.Release()
vssAdmin := (*IVSSAdmin)(unsafe.Pointer(comInterface))
providerLower := strings.ToLower(provider) providerLower := strings.ToLower(provider)
switch providerLower { switch providerLower {
case "": case "":
@ -1100,6 +1092,14 @@ func getProviderID(provider string) (*ole.GUID, error) {
return ole.NewGUID("{b5946137-7b9f-4925-af80-51abd60b20d5}"), nil return ole.NewGUID("{b5946137-7b9f-4925-af80-51abd60b20d5}"), nil
} }
comInterface, err := ole.CreateInstance(CLSID_VSS_COORDINATOR, UIID_IVSS_ADMIN)
if err != nil {
return nil, err
}
defer comInterface.Release()
vssAdmin := (*IVSSAdmin)(unsafe.Pointer(comInterface))
enum, err := vssAdmin.QueryProviders() enum, err := vssAdmin.QueryProviders()
if err != nil { if err != nil {
return nil, err return nil, err