util: addresed few todo

this commit replaces string comparsion with error code
at few places

Signed-off-by: Riya Singhal <rsinghal@redhat.com>
This commit is contained in:
Riya Singhal 2023-11-20 17:01:39 +05:30 committed by mergify[bot]
parent 4ccb299fd5
commit 4b5cdd5316
3 changed files with 8 additions and 14 deletions

View File

@ -19,8 +19,8 @@ package core
import ( import (
"errors" "errors"
"fmt" "fmt"
"strings"
libcephfs "github.com/ceph/go-ceph/cephfs"
fsAdmin "github.com/ceph/go-ceph/cephfs/admin" fsAdmin "github.com/ceph/go-ceph/cephfs/admin"
) )
@ -133,8 +133,7 @@ func (s *subVolumeClient) UnsetAllMetadata(keys []string) error {
if errors.Is(err, ErrSubVolMetadataNotSupported) { if errors.Is(err, ErrSubVolMetadataNotSupported) {
return nil return nil
} }
// TODO: replace string comparison with errno. if err != nil && !errors.Is(err, libcephfs.ErrNotExist) {
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {
return fmt.Errorf("failed to unset metadata key %q on subvolume %v: %w", key, s, err) return fmt.Errorf("failed to unset metadata key %q on subvolume %v: %w", key, s, err)
} }
} }
@ -144,8 +143,7 @@ func (s *subVolumeClient) UnsetAllMetadata(keys []string) error {
if errors.Is(err, ErrSubVolMetadataNotSupported) { if errors.Is(err, ErrSubVolMetadataNotSupported) {
return nil return nil
} }
// TODO: replace string comparison with errno. if err != nil && !errors.Is(err, libcephfs.ErrNotExist) {
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {
return fmt.Errorf("failed to unset metadata key %q on subvolume %v: %w", clusterNameKey, s, err) return fmt.Errorf("failed to unset metadata key %q on subvolume %v: %w", clusterNameKey, s, err)
} }

View File

@ -19,8 +19,8 @@ package core
import ( import (
"errors" "errors"
"fmt" "fmt"
"strings"
libcephfs "github.com/ceph/go-ceph/cephfs"
fsAdmin "github.com/ceph/go-ceph/cephfs/admin" fsAdmin "github.com/ceph/go-ceph/cephfs/admin"
) )
@ -121,16 +121,14 @@ func (s *snapshotClient) UnsetAllSnapshotMetadata(keys []string) error {
for _, key := range keys { for _, key := range keys {
err := s.removeSnapshotMetadata(key) err := s.removeSnapshotMetadata(key)
// TODO: replace string comparison with errno. if err != nil && !errors.Is(err, libcephfs.ErrNotExist) {
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {
return fmt.Errorf("failed to unset metadata key %q on subvolume snapshot %s %s in fs %s: %w", return fmt.Errorf("failed to unset metadata key %q on subvolume snapshot %s %s in fs %s: %w",
key, s.SnapshotID, s.VolID, s.FsName, err) key, s.SnapshotID, s.VolID, s.FsName, err)
} }
} }
err := s.removeSnapshotMetadata(clusterNameKey) err := s.removeSnapshotMetadata(clusterNameKey)
// TODO: replace string comparison with errno. if err != nil && !errors.Is(err, libcephfs.ErrNotExist) {
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {
return fmt.Errorf("failed to unset metadata key %q on subvolume snapshot %s %s in fs %s: %w", return fmt.Errorf("failed to unset metadata key %q on subvolume snapshot %s %s in fs %s: %w",
clusterNameKey, s.SnapshotID, s.VolID, s.FsName, err) clusterNameKey, s.SnapshotID, s.VolID, s.FsName, err)
} }

View File

@ -2143,15 +2143,13 @@ func (rv *rbdVolume) setAllMetadata(parameters map[string]string) error {
func (rv *rbdVolume) unsetAllMetadata(keys []string) error { func (rv *rbdVolume) unsetAllMetadata(keys []string) error {
for _, key := range keys { for _, key := range keys {
err := rv.RemoveMetadata(key) err := rv.RemoveMetadata(key)
// TODO: replace string comparison with errno. if err != nil && !errors.Is(err, librbd.ErrNotExist) {
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {
return fmt.Errorf("failed to unset metadata key %q on %q: %w", key, rv, err) return fmt.Errorf("failed to unset metadata key %q on %q: %w", key, rv, err)
} }
} }
err := rv.RemoveMetadata(clusterNameKey) err := rv.RemoveMetadata(clusterNameKey)
// TODO: replace string comparison with errno. if err != nil && !errors.Is(err, librbd.ErrNotExist) {
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {
return fmt.Errorf("failed to unset metadata key %q on %q: %w", clusterNameKey, rv, err) return fmt.Errorf("failed to unset metadata key %q on %q: %w", clusterNameKey, rv, err)
} }