@@ -3,17 +3,16 @@ package sftp
3
3
// Methods on the Request object to make working with the Flags bitmasks and
4
4
// Attr(ibutes) byte blob easier. Use Pflags() when working with an Open/Write
5
5
// request and AttrFlags() and Attributes() when working with SetStat requests.
6
-
7
6
import "os"
8
7
9
- // Open packet pflags
10
- type pflags struct {
8
+ // File Open and Write Flags. Correlate directly with with os.OpenFile flags
9
+ // (https://golang.org/pkg/os/#pkg-constants).
10
+ type FileOpenFlags struct {
11
11
Read , Write , Append , Creat , Trunc , Excl bool
12
12
}
13
13
14
- // testable constructor
15
- func newPflags (flags uint32 ) pflags {
16
- return pflags {
14
+ func newFileOpenFlags (flags uint32 ) FileOpenFlags {
15
+ return FileOpenFlags {
17
16
Read : flags & ssh_FXF_READ != 0 ,
18
17
Write : flags & ssh_FXF_WRITE != 0 ,
19
18
Append : flags & ssh_FXF_APPEND != 0 ,
@@ -23,41 +22,42 @@ func newPflags(flags uint32) pflags {
23
22
}
24
23
}
25
24
26
- // Check bitmap/uint32 for Open packet pflag values
27
- func (r * Request ) Pflags () pflags {
28
- return newPflags (r .Flags )
25
+ // Pflags converts the bitmap/uint32 from SFTP Open packet pflag values,
26
+ // into a FileOpenFlags struct with booleans set for flags set in bitmap.
27
+ func (r * Request ) Pflags () FileOpenFlags {
28
+ return newFileOpenFlags (r .Flags )
29
29
}
30
30
31
- // File attribute flags
32
- type aflags struct {
31
+ // Flags that indicate whether SFTP file attributes were passed. When a flag is
32
+ // true the corresponding attribute should be available from the FileStat
33
+ // object returned by Attributes method. Used with SetStat.
34
+ type FileAttrFlags struct {
33
35
Size , UidGid , Permissions , Acmodtime bool
34
36
}
35
37
36
- // testable constructor
37
- func newAflags (flags uint32 ) aflags {
38
- return aflags {
38
+ func newFileAttrFlags (flags uint32 ) FileAttrFlags {
39
+ return FileAttrFlags {
39
40
Size : (flags & ssh_FILEXFER_ATTR_SIZE ) != 0 ,
40
41
UidGid : (flags & ssh_FILEXFER_ATTR_UIDGID ) != 0 ,
41
42
Permissions : (flags & ssh_FILEXFER_ATTR_PERMISSIONS ) != 0 ,
42
43
Acmodtime : (flags & ssh_FILEXFER_ATTR_ACMODTIME ) != 0 ,
43
44
}
44
45
}
45
46
46
- // Check bitmap/uint32 for file attribute flags
47
- func (r * Request ) AttrFlags (flags uint32 ) aflags {
48
- return newAflags (r .Flags )
47
+ // FileAttrFlags returns a FileAttrFlags boolean struct based on the
48
+ // bitmap/uint32 file attribute flags from the SFTP packaet.
49
+ func (r * Request ) AttrFlags () FileAttrFlags {
50
+ return newFileAttrFlags (r .Flags )
49
51
}
50
52
51
- // File attributes
52
- type fileattrs FileStat
53
-
54
- // Return Mode wrapped in os.FileMode
55
- func (a fileattrs ) FileMode () os.FileMode {
53
+ // FileMode returns the Mode SFTP file attributes wrapped as os.FileMode
54
+ func (a FileStat ) FileMode () os.FileMode {
56
55
return os .FileMode (a .Mode )
57
56
}
58
57
59
- // Parse file attributes byte blob and return them in object
60
- func (r * Request ) Attributes () fileattrs {
61
- fa , _ := getFileStat (r .Flags , r .Attrs )
62
- return fileattrs (* fa )
58
+ // Attributres parses file attributes byte blob and return them in a
59
+ // FileStat object.
60
+ func (r * Request ) Attributes () * FileStat {
61
+ fs , _ := getFileStat (r .Flags , r .Attrs )
62
+ return fs
63
63
}
0 commit comments