github.com/cs3org/reva/v2@v2.27.7/pkg/storage/fs/cephfs/errors.go (about)

     1  // Copyright 2018-2021 CERN
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  // In applying this license, CERN does not waive the privileges and immunities
    16  // granted to it by virtue of its status as an Intergovernmental Organization
    17  // or submit itself to any jurisdiction.
    18  
    19  //go:build ceph
    20  // +build ceph
    21  
    22  package cephfs
    23  
    24  /*
    25   #include <string.h>
    26   #include <errno.h>
    27   #include <stdlib.h>
    28  */
    29  import "C"
    30  import (
    31  	"fmt"
    32  
    33  	"github.com/cs3org/reva/v2/pkg/errtypes"
    34  )
    35  
    36  func wrapErrorMsg(code C.int) string {
    37  	return fmt.Sprintf("cephfs: ret=-%d, %s", code, C.GoString(C.strerror(code)))
    38  }
    39  
    40  var (
    41  	errNotFound         = wrapErrorMsg(C.ENOENT)
    42  	errFileExists       = wrapErrorMsg(C.EEXIST)
    43  	errNoSpaceLeft      = wrapErrorMsg(C.ENOSPC)
    44  	errIsADirectory     = wrapErrorMsg(C.EISDIR)
    45  	errPermissionDenied = wrapErrorMsg(C.EACCES)
    46  )
    47  
    48  func getRevaError(err error) error {
    49  	if err == nil {
    50  		return nil
    51  	}
    52  	switch err.Error() {
    53  	case errNotFound:
    54  		return errtypes.NotFound("cephfs: dir entry not found")
    55  	case errPermissionDenied:
    56  		return errtypes.PermissionDenied("cephfs: permission denied")
    57  	case errFileExists:
    58  		return errtypes.AlreadyExists("cephfs: file already exists")
    59  	case errNoSpaceLeft:
    60  		return errtypes.InsufficientStorage("cephfs: no space left on device")
    61  	default:
    62  		return errtypes.InternalError(err.Error())
    63  	}
    64  }