Skip to content

Commit

Permalink
util: addresed few todo
Browse files Browse the repository at this point in the history
this commit replaces string comparsion with error code
at few places

Signed-off-by: Riya Singhal <[email protected]>
  • Loading branch information
riya-singhal31 committed Nov 20, 2023
1 parent 9955def commit 20ac121
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
8 changes: 3 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 @@ -133,8 +133,7 @@ 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 @@ -144,8 +143,7 @@ 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 20ac121

Please sign in to comment.