Skip to content

Commit

Permalink
cephfs: replaced string comparison with errno
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 6, 2023
1 parent 348959a commit a36ff70
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions internal/cephfs/core/snapshot_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package core
import (
"errors"
"fmt"
"strings"
"syscall"

fsAdmin "github.com/ceph/go-ceph/cephfs/admin"
)
Expand Down Expand Up @@ -121,18 +121,22 @@ 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") {
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)
if err != nil {
if errno, ok := err.(syscall.Errno); ok && errno == syscall.ENOENT {
// Handle "No such file or directory" error
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") {
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)
if err != nil {
if errno, ok := err.(syscall.Errno); ok && errno == syscall.ENOENT {
// Handle "No such file or directory" error
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)
}
}

return nil
Expand Down

0 comments on commit a36ff70

Please sign in to comment.