github.com/pkg/sftp@v1.13.6/internal/encoding/ssh/filexfer/fx.go (about)

     1  package sshfx
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // Status defines the SFTP error codes used in SSH_FXP_STATUS response packets.
     8  type Status uint32
     9  
    10  // Defines the various SSH_FX_* values.
    11  const (
    12  	// see draft-ietf-secsh-filexfer-02
    13  	// https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-02.txt#section-7
    14  	StatusOK = Status(iota)
    15  	StatusEOF
    16  	StatusNoSuchFile
    17  	StatusPermissionDenied
    18  	StatusFailure
    19  	StatusBadMessage
    20  	StatusNoConnection
    21  	StatusConnectionLost
    22  	StatusOPUnsupported
    23  
    24  	// https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-03.txt#section-7
    25  	StatusV4InvalidHandle
    26  	StatusV4NoSuchPath
    27  	StatusV4FileAlreadyExists
    28  	StatusV4WriteProtect
    29  
    30  	// https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-04.txt#section-7
    31  	StatusV4NoMedia
    32  
    33  	// https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-05.txt#section-7
    34  	StatusV5NoSpaceOnFilesystem
    35  	StatusV5QuotaExceeded
    36  	StatusV5UnknownPrincipal
    37  	StatusV5LockConflict
    38  
    39  	// https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-06.txt#section-8
    40  	StatusV6DirNotEmpty
    41  	StatusV6NotADirectory
    42  	StatusV6InvalidFilename
    43  	StatusV6LinkLoop
    44  
    45  	// https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-07.txt#section-8
    46  	StatusV6CannotDelete
    47  	StatusV6InvalidParameter
    48  	StatusV6FileIsADirectory
    49  	StatusV6ByteRangeLockConflict
    50  	StatusV6ByteRangeLockRefused
    51  	StatusV6DeletePending
    52  
    53  	// https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-08.txt#section-8.1
    54  	StatusV6FileCorrupt
    55  
    56  	// https://filezilla-project.org/specs/draft-ietf-secsh-filexfer-10.txt#section-9.1
    57  	StatusV6OwnerInvalid
    58  	StatusV6GroupInvalid
    59  
    60  	// https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-9.1
    61  	StatusV6NoMatchingByteRangeLock
    62  )
    63  
    64  func (s Status) Error() string {
    65  	return s.String()
    66  }
    67  
    68  // Is returns true if the target is the same Status code,
    69  // or target is a StatusPacket with the same Status code.
    70  func (s Status) Is(target error) bool {
    71  	if target, ok := target.(*StatusPacket); ok {
    72  		return target.StatusCode == s
    73  	}
    74  
    75  	return s == target
    76  }
    77  
    78  func (s Status) String() string {
    79  	switch s {
    80  	case StatusOK:
    81  		return "SSH_FX_OK"
    82  	case StatusEOF:
    83  		return "SSH_FX_EOF"
    84  	case StatusNoSuchFile:
    85  		return "SSH_FX_NO_SUCH_FILE"
    86  	case StatusPermissionDenied:
    87  		return "SSH_FX_PERMISSION_DENIED"
    88  	case StatusFailure:
    89  		return "SSH_FX_FAILURE"
    90  	case StatusBadMessage:
    91  		return "SSH_FX_BAD_MESSAGE"
    92  	case StatusNoConnection:
    93  		return "SSH_FX_NO_CONNECTION"
    94  	case StatusConnectionLost:
    95  		return "SSH_FX_CONNECTION_LOST"
    96  	case StatusOPUnsupported:
    97  		return "SSH_FX_OP_UNSUPPORTED"
    98  	case StatusV4InvalidHandle:
    99  		return "SSH_FX_INVALID_HANDLE"
   100  	case StatusV4NoSuchPath:
   101  		return "SSH_FX_NO_SUCH_PATH"
   102  	case StatusV4FileAlreadyExists:
   103  		return "SSH_FX_FILE_ALREADY_EXISTS"
   104  	case StatusV4WriteProtect:
   105  		return "SSH_FX_WRITE_PROTECT"
   106  	case StatusV4NoMedia:
   107  		return "SSH_FX_NO_MEDIA"
   108  	case StatusV5NoSpaceOnFilesystem:
   109  		return "SSH_FX_NO_SPACE_ON_FILESYSTEM"
   110  	case StatusV5QuotaExceeded:
   111  		return "SSH_FX_QUOTA_EXCEEDED"
   112  	case StatusV5UnknownPrincipal:
   113  		return "SSH_FX_UNKNOWN_PRINCIPAL"
   114  	case StatusV5LockConflict:
   115  		return "SSH_FX_LOCK_CONFLICT"
   116  	case StatusV6DirNotEmpty:
   117  		return "SSH_FX_DIR_NOT_EMPTY"
   118  	case StatusV6NotADirectory:
   119  		return "SSH_FX_NOT_A_DIRECTORY"
   120  	case StatusV6InvalidFilename:
   121  		return "SSH_FX_INVALID_FILENAME"
   122  	case StatusV6LinkLoop:
   123  		return "SSH_FX_LINK_LOOP"
   124  	case StatusV6CannotDelete:
   125  		return "SSH_FX_CANNOT_DELETE"
   126  	case StatusV6InvalidParameter:
   127  		return "SSH_FX_INVALID_PARAMETER"
   128  	case StatusV6FileIsADirectory:
   129  		return "SSH_FX_FILE_IS_A_DIRECTORY"
   130  	case StatusV6ByteRangeLockConflict:
   131  		return "SSH_FX_BYTE_RANGE_LOCK_CONFLICT"
   132  	case StatusV6ByteRangeLockRefused:
   133  		return "SSH_FX_BYTE_RANGE_LOCK_REFUSED"
   134  	case StatusV6DeletePending:
   135  		return "SSH_FX_DELETE_PENDING"
   136  	case StatusV6FileCorrupt:
   137  		return "SSH_FX_FILE_CORRUPT"
   138  	case StatusV6OwnerInvalid:
   139  		return "SSH_FX_OWNER_INVALID"
   140  	case StatusV6GroupInvalid:
   141  		return "SSH_FX_GROUP_INVALID"
   142  	case StatusV6NoMatchingByteRangeLock:
   143  		return "SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK"
   144  	default:
   145  		return fmt.Sprintf("SSH_FX_UNKNOWN(%d)", s)
   146  	}
   147  }