Skip to content

Commit

Permalink
util: replaced string comparison with suitable error code
Browse files Browse the repository at this point in the history
Signed-off-by: Riya Singhal <[email protected]>
  • Loading branch information
riya-singhal31 committed Nov 14, 2023
1 parent 1688f5c commit f94b53a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
10 changes: 5 additions & 5 deletions internal/cephfs/core/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package core
import (
"errors"
"fmt"
"strings"

libceph "github.com/ceph/go-ceph/cephfs"
fsAdmin "github.com/ceph/go-ceph/cephfs/admin"
)

Expand Down Expand Up @@ -159,8 +159,8 @@ func (s *subVolumeClient) UnsetAllMetadata(keys []string) error {
if errors.Is(err, ErrSubVolMetadataNotSupported) {
return nil
}
// TODO: replace string comparison with errno.
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {

if err != nil && !errors.Is(err, libceph.ErrNotExist) {
return fmt.Errorf("failed to unset metadata key %q on subvolume %v: %w", key, s, err)
}
}
Expand All @@ -170,8 +170,8 @@ func (s *subVolumeClient) UnsetAllMetadata(keys []string) error {
if errors.Is(err, ErrSubVolMetadataNotSupported) {
return nil
}
// TODO: replace string comparison with errno.
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {

if err != nil && !errors.Is(err, libceph.ErrNotExist) {
return fmt.Errorf("failed to unset metadata key %q on subvolume %v: %w", clusterNameKey, s, err)
}

Expand Down
8 changes: 3 additions & 5 deletions internal/cephfs/core/snapshot_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package core
import (
"errors"
"fmt"
"strings"

libceph "github.com/ceph/go-ceph/cephfs"
fsAdmin "github.com/ceph/go-ceph/cephfs/admin"
)

Expand Down Expand Up @@ -121,16 +121,14 @@ func (s *snapshotClient) UnsetAllSnapshotMetadata(keys []string) error {

for _, key := range keys {
err := s.removeSnapshotMetadata(key)
// TODO: replace string comparison with errno.
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {
if err != nil && !errors.Is(err, libceph.ErrNotExist) {
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)
}
}

err := s.removeSnapshotMetadata(clusterNameKey)
// TODO: replace string comparison with errno.
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {
if err != nil && !errors.Is(err, libceph.ErrNotExist) {
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)
}
Expand Down
6 changes: 2 additions & 4 deletions internal/rbd/rbd_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2143,15 +2143,13 @@ func (rv *rbdVolume) setAllMetadata(parameters map[string]string) error {
func (rv *rbdVolume) unsetAllMetadata(keys []string) error {
for _, key := range keys {
err := rv.RemoveMetadata(key)
// TODO: replace string comparison with errno.
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {
if err != nil && !errors.Is(err, librbd.ErrNotExist) {
return fmt.Errorf("failed to unset metadata key %q on %q: %w", key, rv, err)
}
}

err := rv.RemoveMetadata(clusterNameKey)
// TODO: replace string comparison with errno.
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {
if err != nil && !errors.Is(err, librbd.ErrNotExist) {
return fmt.Errorf("failed to unset metadata key %q on %q: %w", clusterNameKey, rv, err)
}

Expand Down

0 comments on commit f94b53a

Please sign in to comment.