diff --git a/internal/cephfs/core/snapshot_metadata.go b/internal/cephfs/core/snapshot_metadata.go index f168fbf8cd41..273e212dae92 100644 --- a/internal/cephfs/core/snapshot_metadata.go +++ b/internal/cephfs/core/snapshot_metadata.go @@ -19,7 +19,7 @@ package core import ( "errors" "fmt" - "strings" + "syscall" fsAdmin "github.com/ceph/go-ceph/cephfs/admin" ) @@ -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