a geicko-2 based round robin ranking system designed to test c++ battleship submissions
battleship.dunkirk.sh
1package sftp
2
3import (
4 "os"
5
6 sshfx "github.com/pkg/sftp/internal/encoding/ssh/filexfer"
7)
8
9// isRegular returns true if the mode describes a regular file.
10func isRegular(mode uint32) bool {
11 return sshfx.FileMode(mode)&sshfx.ModeType == sshfx.ModeRegular
12}
13
14// toFileMode converts sftp filemode bits to the os.FileMode specification
15func toFileMode(mode uint32) os.FileMode {
16 var fm = os.FileMode(mode & 0777)
17
18 switch sshfx.FileMode(mode) & sshfx.ModeType {
19 case sshfx.ModeDevice:
20 fm |= os.ModeDevice
21 case sshfx.ModeCharDevice:
22 fm |= os.ModeDevice | os.ModeCharDevice
23 case sshfx.ModeDir:
24 fm |= os.ModeDir
25 case sshfx.ModeNamedPipe:
26 fm |= os.ModeNamedPipe
27 case sshfx.ModeSymlink:
28 fm |= os.ModeSymlink
29 case sshfx.ModeRegular:
30 // nothing to do
31 case sshfx.ModeSocket:
32 fm |= os.ModeSocket
33 }
34
35 if sshfx.FileMode(mode)&sshfx.ModeSetUID != 0 {
36 fm |= os.ModeSetuid
37 }
38 if sshfx.FileMode(mode)&sshfx.ModeSetGID != 0 {
39 fm |= os.ModeSetgid
40 }
41 if sshfx.FileMode(mode)&sshfx.ModeSticky != 0 {
42 fm |= os.ModeSticky
43 }
44
45 return fm
46}
47
48// fromFileMode converts from the os.FileMode specification to sftp filemode bits
49func fromFileMode(mode os.FileMode) uint32 {
50 ret := sshfx.FileMode(mode & os.ModePerm)
51
52 switch mode & os.ModeType {
53 case os.ModeDevice | os.ModeCharDevice:
54 ret |= sshfx.ModeCharDevice
55 case os.ModeDevice:
56 ret |= sshfx.ModeDevice
57 case os.ModeDir:
58 ret |= sshfx.ModeDir
59 case os.ModeNamedPipe:
60 ret |= sshfx.ModeNamedPipe
61 case os.ModeSymlink:
62 ret |= sshfx.ModeSymlink
63 case 0:
64 ret |= sshfx.ModeRegular
65 case os.ModeSocket:
66 ret |= sshfx.ModeSocket
67 }
68
69 if mode&os.ModeSetuid != 0 {
70 ret |= sshfx.ModeSetUID
71 }
72 if mode&os.ModeSetgid != 0 {
73 ret |= sshfx.ModeSetGID
74 }
75 if mode&os.ModeSticky != 0 {
76 ret |= sshfx.ModeSticky
77 }
78
79 return uint32(ret)
80}
81
82const (
83 s_ISUID = uint32(sshfx.ModeSetUID)
84 s_ISGID = uint32(sshfx.ModeSetGID)
85 s_ISVTX = uint32(sshfx.ModeSticky)
86)
87
88// S_IFMT is a legacy export, and was brought in to support GOOS environments whose sysconfig.S_IFMT may be different from the value used internally by SFTP standards.
89// There should be no reason why you need to import it, or use it, but unexporting it could cause code to break in a way that cannot be readily fixed.
90// As such, we continue to export this value as the value used in the SFTP standard.
91//
92// Deprecated: Remove use of this value, and avoid any future use as well.
93// There is no alternative provided, you should never need to access this value.
94const S_IFMT = uint32(sshfx.ModeType)