fix golint warnings/errors on pkg/system and pkg/stdcopy
| ... | ... |
@@ -28,7 +28,7 @@ func copyOwnership(source, destination string) error {
|
| 28 | 28 |
return err |
| 29 | 29 |
} |
| 30 | 30 |
|
| 31 |
- if err := os.Chown(destination, int(stat.Uid()), int(stat.Gid())); err != nil {
|
|
| 31 |
+ if err := os.Chown(destination, int(stat.UID()), int(stat.Gid())); err != nil {
|
|
| 32 | 32 |
return err |
| 33 | 33 |
} |
| 34 | 34 |
|
| ... | ... |
@@ -26,7 +26,7 @@ func setPlatformServerConfig(serverConfig *apiserver.Config, daemonCfg *daemon.C |
| 26 | 26 |
// file. |
| 27 | 27 |
func currentUserIsOwner(f string) bool {
|
| 28 | 28 |
if fileInfo, err := system.Stat(f); err == nil && fileInfo != nil {
|
| 29 |
- if int(fileInfo.Uid()) == os.Getuid() {
|
|
| 29 |
+ if int(fileInfo.UID()) == os.Getuid() {
|
|
| 30 | 30 |
return true |
| 31 | 31 |
} |
| 32 | 32 |
} |
| ... | ... |
@@ -8,10 +8,10 @@ import ( |
| 8 | 8 |
"github.com/docker/docker/pkg/system" |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 |
-func statDifferent(oldStat *system.Stat_t, newStat *system.Stat_t) bool {
|
|
| 11 |
+func statDifferent(oldStat *system.StatT, newStat *system.StatT) bool {
|
|
| 12 | 12 |
// Don't look at size for dirs, its not a good measure of change |
| 13 | 13 |
if oldStat.Mode() != newStat.Mode() || |
| 14 |
- oldStat.Uid() != newStat.Uid() || |
|
| 14 |
+ oldStat.UID() != newStat.UID() || |
|
| 15 | 15 |
oldStat.Gid() != newStat.Gid() || |
| 16 | 16 |
oldStat.Rdev() != newStat.Rdev() || |
| 17 | 17 |
// Don't look at size for dirs, its not a good measure of change |
| ... | ... |
@@ -4,7 +4,7 @@ import ( |
| 4 | 4 |
"github.com/docker/docker/pkg/system" |
| 5 | 5 |
) |
| 6 | 6 |
|
| 7 |
-func statDifferent(oldStat *system.Stat_t, newStat *system.Stat_t) bool {
|
|
| 7 |
+func statDifferent(oldStat *system.StatT, newStat *system.StatT) bool {
|
|
| 8 | 8 |
|
| 9 | 9 |
// Don't look at size for dirs, its not a good measure of change |
| 10 | 10 |
if oldStat.ModTime() != newStat.ModTime() || |
| ... | ... |
@@ -9,19 +9,24 @@ import ( |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 | 11 |
const ( |
| 12 |
- StdWriterPrefixLen = 8 |
|
| 13 |
- StdWriterFdIndex = 0 |
|
| 14 |
- StdWriterSizeIndex = 4 |
|
| 12 |
+ stdWriterPrefixLen = 8 |
|
| 13 |
+ stdWriterFdIndex = 0 |
|
| 14 |
+ stdWriterSizeIndex = 4 |
|
| 15 | 15 |
) |
| 16 | 16 |
|
| 17 |
-type StdType [StdWriterPrefixLen]byte |
|
| 17 |
+// StdType prefixes type and length to standard stream. |
|
| 18 |
+type StdType [stdWriterPrefixLen]byte |
|
| 18 | 19 |
|
| 19 | 20 |
var ( |
| 20 |
- Stdin StdType = StdType{0: 0}
|
|
| 21 |
- Stdout StdType = StdType{0: 1}
|
|
| 22 |
- Stderr StdType = StdType{0: 2}
|
|
| 21 |
+ // Stdin represents standard input stream type. |
|
| 22 |
+ Stdin = StdType{0: 0}
|
|
| 23 |
+ // Stdout represents standard output stream type. |
|
| 24 |
+ Stdout = StdType{0: 1}
|
|
| 25 |
+ // Stderr represents standard error steam type. |
|
| 26 |
+ Stderr = StdType{0: 2}
|
|
| 23 | 27 |
) |
| 24 | 28 |
|
| 29 |
+// StdWriter is wrapper of io.Writer with extra customized info. |
|
| 25 | 30 |
type StdWriter struct {
|
| 26 | 31 |
io.Writer |
| 27 | 32 |
prefix StdType |
| ... | ... |
@@ -36,10 +41,10 @@ func (w *StdWriter) Write(buf []byte) (n int, err error) {
|
| 36 | 36 |
binary.BigEndian.PutUint32(w.prefix[4:], uint32(len(buf))) |
| 37 | 37 |
n1, err = w.Writer.Write(w.prefix[:]) |
| 38 | 38 |
if err != nil {
|
| 39 |
- n = n1 - StdWriterPrefixLen |
|
| 39 |
+ n = n1 - stdWriterPrefixLen |
|
| 40 | 40 |
} else {
|
| 41 | 41 |
n2, err = w.Writer.Write(buf) |
| 42 |
- n = n1 + n2 - StdWriterPrefixLen |
|
| 42 |
+ n = n1 + n2 - stdWriterPrefixLen |
|
| 43 | 43 |
} |
| 44 | 44 |
if n < 0 {
|
| 45 | 45 |
n = 0 |
| ... | ... |
@@ -61,7 +66,7 @@ func NewStdWriter(w io.Writer, t StdType) *StdWriter {
|
| 61 | 61 |
} |
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 |
-var ErrInvalidStdHeader = errors.New("Unrecognized input header")
|
|
| 64 |
+var errInvalidStdHeader = errors.New("Unrecognized input header")
|
|
| 65 | 65 |
|
| 66 | 66 |
// StdCopy is a modified version of io.Copy. |
| 67 | 67 |
// |
| ... | ... |
@@ -75,7 +80,7 @@ var ErrInvalidStdHeader = errors.New("Unrecognized input header")
|
| 75 | 75 |
// `written` will hold the total number of bytes written to `dstout` and `dsterr`. |
| 76 | 76 |
func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) {
|
| 77 | 77 |
var ( |
| 78 |
- buf = make([]byte, 32*1024+StdWriterPrefixLen+1) |
|
| 78 |
+ buf = make([]byte, 32*1024+stdWriterPrefixLen+1) |
|
| 79 | 79 |
bufLen = len(buf) |
| 80 | 80 |
nr, nw int |
| 81 | 81 |
er, ew error |
| ... | ... |
@@ -85,12 +90,12 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) |
| 85 | 85 |
|
| 86 | 86 |
for {
|
| 87 | 87 |
// Make sure we have at least a full header |
| 88 |
- for nr < StdWriterPrefixLen {
|
|
| 88 |
+ for nr < stdWriterPrefixLen {
|
|
| 89 | 89 |
var nr2 int |
| 90 | 90 |
nr2, er = src.Read(buf[nr:]) |
| 91 | 91 |
nr += nr2 |
| 92 | 92 |
if er == io.EOF {
|
| 93 |
- if nr < StdWriterPrefixLen {
|
|
| 93 |
+ if nr < stdWriterPrefixLen {
|
|
| 94 | 94 |
logrus.Debugf("Corrupted prefix: %v", buf[:nr])
|
| 95 | 95 |
return written, nil |
| 96 | 96 |
} |
| ... | ... |
@@ -103,7 +108,7 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) |
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 | 105 |
// Check the first byte to know where to write |
| 106 |
- switch buf[StdWriterFdIndex] {
|
|
| 106 |
+ switch buf[stdWriterFdIndex] {
|
|
| 107 | 107 |
case 0: |
| 108 | 108 |
fallthrough |
| 109 | 109 |
case 1: |
| ... | ... |
@@ -113,30 +118,30 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) |
| 113 | 113 |
// Write on stderr |
| 114 | 114 |
out = dsterr |
| 115 | 115 |
default: |
| 116 |
- logrus.Debugf("Error selecting output fd: (%d)", buf[StdWriterFdIndex])
|
|
| 117 |
- return 0, ErrInvalidStdHeader |
|
| 116 |
+ logrus.Debugf("Error selecting output fd: (%d)", buf[stdWriterFdIndex])
|
|
| 117 |
+ return 0, errInvalidStdHeader |
|
| 118 | 118 |
} |
| 119 | 119 |
|
| 120 | 120 |
// Retrieve the size of the frame |
| 121 |
- frameSize = int(binary.BigEndian.Uint32(buf[StdWriterSizeIndex : StdWriterSizeIndex+4])) |
|
| 121 |
+ frameSize = int(binary.BigEndian.Uint32(buf[stdWriterSizeIndex : stdWriterSizeIndex+4])) |
|
| 122 | 122 |
logrus.Debugf("framesize: %d", frameSize)
|
| 123 | 123 |
|
| 124 | 124 |
// Check if the buffer is big enough to read the frame. |
| 125 | 125 |
// Extend it if necessary. |
| 126 |
- if frameSize+StdWriterPrefixLen > bufLen {
|
|
| 127 |
- logrus.Debugf("Extending buffer cap by %d (was %d)", frameSize+StdWriterPrefixLen-bufLen+1, len(buf))
|
|
| 128 |
- buf = append(buf, make([]byte, frameSize+StdWriterPrefixLen-bufLen+1)...) |
|
| 126 |
+ if frameSize+stdWriterPrefixLen > bufLen {
|
|
| 127 |
+ logrus.Debugf("Extending buffer cap by %d (was %d)", frameSize+stdWriterPrefixLen-bufLen+1, len(buf))
|
|
| 128 |
+ buf = append(buf, make([]byte, frameSize+stdWriterPrefixLen-bufLen+1)...) |
|
| 129 | 129 |
bufLen = len(buf) |
| 130 | 130 |
} |
| 131 | 131 |
|
| 132 | 132 |
// While the amount of bytes read is less than the size of the frame + header, we keep reading |
| 133 |
- for nr < frameSize+StdWriterPrefixLen {
|
|
| 133 |
+ for nr < frameSize+stdWriterPrefixLen {
|
|
| 134 | 134 |
var nr2 int |
| 135 | 135 |
nr2, er = src.Read(buf[nr:]) |
| 136 | 136 |
nr += nr2 |
| 137 | 137 |
if er == io.EOF {
|
| 138 |
- if nr < frameSize+StdWriterPrefixLen {
|
|
| 139 |
- logrus.Debugf("Corrupted frame: %v", buf[StdWriterPrefixLen:nr])
|
|
| 138 |
+ if nr < frameSize+stdWriterPrefixLen {
|
|
| 139 |
+ logrus.Debugf("Corrupted frame: %v", buf[stdWriterPrefixLen:nr])
|
|
| 140 | 140 |
return written, nil |
| 141 | 141 |
} |
| 142 | 142 |
break |
| ... | ... |
@@ -148,7 +153,7 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) |
| 148 | 148 |
} |
| 149 | 149 |
|
| 150 | 150 |
// Write the retrieved frame (without header) |
| 151 |
- nw, ew = out.Write(buf[StdWriterPrefixLen : frameSize+StdWriterPrefixLen]) |
|
| 151 |
+ nw, ew = out.Write(buf[stdWriterPrefixLen : frameSize+stdWriterPrefixLen]) |
|
| 152 | 152 |
if ew != nil {
|
| 153 | 153 |
logrus.Debugf("Error writing frame: %s", ew)
|
| 154 | 154 |
return 0, ew |
| ... | ... |
@@ -161,8 +166,8 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) |
| 161 | 161 |
written += int64(nw) |
| 162 | 162 |
|
| 163 | 163 |
// Move the rest of the buffer to the beginning |
| 164 |
- copy(buf, buf[frameSize+StdWriterPrefixLen:]) |
|
| 164 |
+ copy(buf, buf[frameSize+stdWriterPrefixLen:]) |
|
| 165 | 165 |
// Move the index |
| 166 |
- nr -= frameSize + StdWriterPrefixLen |
|
| 166 |
+ nr -= frameSize + stdWriterPrefixLen |
|
| 167 | 167 |
} |
| 168 | 168 |
} |
| ... | ... |
@@ -8,11 +8,6 @@ import ( |
| 8 | 8 |
"unsafe" |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 |
-const ( |
|
| 12 |
- EVENT_ALL_ACCESS = 0x1F0003 |
|
| 13 |
- EVENT_MODIFY_STATUS = 0x0002 |
|
| 14 |
-) |
|
| 15 |
- |
|
| 16 | 11 |
var ( |
| 17 | 12 |
procCreateEvent = modkernel32.NewProc("CreateEventW")
|
| 18 | 13 |
procOpenEvent = modkernel32.NewProc("OpenEventW")
|
| ... | ... |
@@ -21,13 +16,14 @@ var ( |
| 21 | 21 |
procPulseEvent = modkernel32.NewProc("PulseEvent")
|
| 22 | 22 |
) |
| 23 | 23 |
|
| 24 |
+// CreateEvent implements win32 CreateEventW func in golang. It will create an event object. |
|
| 24 | 25 |
func CreateEvent(eventAttributes *syscall.SecurityAttributes, manualReset bool, initialState bool, name string) (handle syscall.Handle, err error) {
|
| 25 | 26 |
namep, _ := syscall.UTF16PtrFromString(name) |
| 26 |
- var _p1 uint32 = 0 |
|
| 27 |
+ var _p1 uint32 |
|
| 27 | 28 |
if manualReset {
|
| 28 | 29 |
_p1 = 1 |
| 29 | 30 |
} |
| 30 |
- var _p2 uint32 = 0 |
|
| 31 |
+ var _p2 uint32 |
|
| 31 | 32 |
if initialState {
|
| 32 | 33 |
_p2 = 1 |
| 33 | 34 |
} |
| ... | ... |
@@ -40,9 +36,10 @@ func CreateEvent(eventAttributes *syscall.SecurityAttributes, manualReset bool, |
| 40 | 40 |
return |
| 41 | 41 |
} |
| 42 | 42 |
|
| 43 |
+// OpenEvent implements win32 OpenEventW func in golang. It opens an event object. |
|
| 43 | 44 |
func OpenEvent(desiredAccess uint32, inheritHandle bool, name string) (handle syscall.Handle, err error) {
|
| 44 | 45 |
namep, _ := syscall.UTF16PtrFromString(name) |
| 45 |
- var _p1 uint32 = 0 |
|
| 46 |
+ var _p1 uint32 |
|
| 46 | 47 |
if inheritHandle {
|
| 47 | 48 |
_p1 = 1 |
| 48 | 49 |
} |
| ... | ... |
@@ -55,14 +52,17 @@ func OpenEvent(desiredAccess uint32, inheritHandle bool, name string) (handle sy |
| 55 | 55 |
return |
| 56 | 56 |
} |
| 57 | 57 |
|
| 58 |
+// SetEvent implements win32 SetEvent func in golang. |
|
| 58 | 59 |
func SetEvent(handle syscall.Handle) (err error) {
|
| 59 | 60 |
return setResetPulse(handle, procSetEvent) |
| 60 | 61 |
} |
| 61 | 62 |
|
| 63 |
+// ResetEvent implements win32 ResetEvent func in golang. |
|
| 62 | 64 |
func ResetEvent(handle syscall.Handle) (err error) {
|
| 63 | 65 |
return setResetPulse(handle, procResetEvent) |
| 64 | 66 |
} |
| 65 | 67 |
|
| 68 |
+// PulseEvent implements win32 PulseEvent func in golang. |
|
| 66 | 69 |
func PulseEvent(handle syscall.Handle) (err error) {
|
| 67 | 70 |
return setResetPulse(handle, procPulseEvent) |
| 68 | 71 |
} |
| ... | ... |
@@ -6,6 +6,8 @@ import ( |
| 6 | 6 |
"os" |
| 7 | 7 |
) |
| 8 | 8 |
|
| 9 |
+// MkdirAll creates a directory named path along with any necessary parents, |
|
| 10 |
+// with permission specified by attribute perm for all dir created. |
|
| 9 | 11 |
func MkdirAll(path string, perm os.FileMode) error {
|
| 10 | 12 |
return os.MkdirAll(path, perm) |
| 11 | 13 |
} |
| ... | ... |
@@ -7,10 +7,10 @@ import ( |
| 7 | 7 |
) |
| 8 | 8 |
|
| 9 | 9 |
// Lstat takes a path to a file and returns |
| 10 |
-// a system.Stat_t type pertaining to that file. |
|
| 10 |
+// a system.StatT type pertaining to that file. |
|
| 11 | 11 |
// |
| 12 | 12 |
// Throws an error if the file does not exist |
| 13 |
-func Lstat(path string) (*Stat_t, error) {
|
|
| 13 |
+func Lstat(path string) (*StatT, error) {
|
|
| 14 | 14 |
s := &syscall.Stat_t{}
|
| 15 | 15 |
if err := syscall.Lstat(path, s); err != nil {
|
| 16 | 16 |
return nil, err |
| ... | ... |
@@ -6,21 +6,17 @@ import ( |
| 6 | 6 |
"os" |
| 7 | 7 |
) |
| 8 | 8 |
|
| 9 |
-// Some explanation for my own sanity, and hopefully maintainers in the |
|
| 10 |
-// future. |
|
| 11 |
-// |
|
| 12 | 9 |
// Lstat calls os.Lstat to get a fileinfo interface back. |
| 13 | 10 |
// This is then copied into our own locally defined structure. |
| 14 | 11 |
// Note the Linux version uses fromStatT to do the copy back, |
| 15 | 12 |
// but that not strictly necessary when already in an OS specific module. |
| 16 |
- |
|
| 17 |
-func Lstat(path string) (*Stat_t, error) {
|
|
| 13 |
+func Lstat(path string) (*StatT, error) {
|
|
| 18 | 14 |
fi, err := os.Lstat(path) |
| 19 | 15 |
if err != nil {
|
| 20 | 16 |
return nil, err |
| 21 | 17 |
} |
| 22 | 18 |
|
| 23 |
- return &Stat_t{
|
|
| 19 |
+ return &StatT{
|
|
| 24 | 20 |
name: fi.Name(), |
| 25 | 21 |
size: fi.Size(), |
| 26 | 22 |
mode: fi.Mode(), |
| ... | ... |
@@ -2,7 +2,6 @@ package system |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"bufio" |
| 5 |
- "errors" |
|
| 6 | 5 |
"io" |
| 7 | 6 |
"os" |
| 8 | 7 |
"strconv" |
| ... | ... |
@@ -11,10 +10,6 @@ import ( |
| 11 | 11 |
"github.com/docker/docker/pkg/units" |
| 12 | 12 |
) |
| 13 | 13 |
|
| 14 |
-var ( |
|
| 15 |
- ErrMalformed = errors.New("malformed file")
|
|
| 16 |
-) |
|
| 17 |
- |
|
| 18 | 14 |
// ReadMemInfo retrieves memory statistics of the host system and returns a |
| 19 | 15 |
// MemInfo type. |
| 20 | 16 |
func ReadMemInfo() (*MemInfo, error) {
|
| ... | ... |
@@ -7,14 +7,16 @@ import ( |
| 7 | 7 |
) |
| 8 | 8 |
|
| 9 | 9 |
// Mknod creates a filesystem node (file, device special file or named pipe) named path |
| 10 |
-// with attributes specified by mode and dev |
|
| 10 |
+// with attributes specified by mode and dev. |
|
| 11 | 11 |
func Mknod(path string, mode uint32, dev int) error {
|
| 12 | 12 |
return syscall.Mknod(path, mode, dev) |
| 13 | 13 |
} |
| 14 | 14 |
|
| 15 |
+// Mkdev is used to build the value of linux devices (in /dev/) which specifies major |
|
| 16 |
+// and minor number of the newly created device special file. |
|
| 15 | 17 |
// Linux device nodes are a bit weird due to backwards compat with 16 bit device nodes. |
| 16 | 18 |
// They are, from low to high: the lower 8 bits of the minor, then 12 bits of the major, |
| 17 |
-// then the top 12 bits of the minor |
|
| 19 |
+// then the top 12 bits of the minor. |
|
| 18 | 20 |
func Mkdev(major int64, minor int64) uint32 {
|
| 19 | 21 |
return uint32(((minor & 0xfff00) << 12) | ((major & 0xfff) << 8) | (minor & 0xff)) |
| 20 | 22 |
} |
| ... | ... |
@@ -2,10 +2,12 @@ |
| 2 | 2 |
|
| 3 | 3 |
package system |
| 4 | 4 |
|
| 5 |
+// Mknod is not implemented on Windows. |
|
| 5 | 6 |
func Mknod(path string, mode uint32, dev int) error {
|
| 6 | 7 |
return ErrNotSupportedPlatform |
| 7 | 8 |
} |
| 8 | 9 |
|
| 10 |
+// Mkdev is not implemented on Windows. |
|
| 9 | 11 |
func Mkdev(major int64, minor int64) uint32 {
|
| 10 | 12 |
panic("Mkdev not implemented on Windows.")
|
| 11 | 13 |
} |
| ... | ... |
@@ -6,9 +6,9 @@ import ( |
| 6 | 6 |
"syscall" |
| 7 | 7 |
) |
| 8 | 8 |
|
| 9 |
-// Stat_t type contains status of a file. It contains metadata |
|
| 10 |
-// like permission, owner, group, size, etc about a file |
|
| 11 |
-type Stat_t struct {
|
|
| 9 |
+// StatT type contains status of a file. It contains metadata |
|
| 10 |
+// like permission, owner, group, size, etc about a file. |
|
| 11 |
+type StatT struct {
|
|
| 12 | 12 |
mode uint32 |
| 13 | 13 |
uid uint32 |
| 14 | 14 |
gid uint32 |
| ... | ... |
@@ -17,30 +17,37 @@ type Stat_t struct {
|
| 17 | 17 |
mtim syscall.Timespec |
| 18 | 18 |
} |
| 19 | 19 |
|
| 20 |
-func (s Stat_t) Mode() uint32 {
|
|
| 20 |
+// Mode returns file's permission mode. |
|
| 21 |
+func (s StatT) Mode() uint32 {
|
|
| 21 | 22 |
return s.mode |
| 22 | 23 |
} |
| 23 | 24 |
|
| 24 |
-func (s Stat_t) Uid() uint32 {
|
|
| 25 |
+// UID returns file's user id of owner. |
|
| 26 |
+func (s StatT) UID() uint32 {
|
|
| 25 | 27 |
return s.uid |
| 26 | 28 |
} |
| 27 | 29 |
|
| 28 |
-func (s Stat_t) Gid() uint32 {
|
|
| 30 |
+// Gid returns file's group id of owner. |
|
| 31 |
+func (s StatT) Gid() uint32 {
|
|
| 29 | 32 |
return s.gid |
| 30 | 33 |
} |
| 31 | 34 |
|
| 32 |
-func (s Stat_t) Rdev() uint64 {
|
|
| 35 |
+// Rdev returns file's device ID (if it's special file). |
|
| 36 |
+func (s StatT) Rdev() uint64 {
|
|
| 33 | 37 |
return s.rdev |
| 34 | 38 |
} |
| 35 | 39 |
|
| 36 |
-func (s Stat_t) Size() int64 {
|
|
| 40 |
+// Size returns file's size. |
|
| 41 |
+func (s StatT) Size() int64 {
|
|
| 37 | 42 |
return s.size |
| 38 | 43 |
} |
| 39 | 44 |
|
| 40 |
-func (s Stat_t) Mtim() syscall.Timespec {
|
|
| 45 |
+// Mtim returns file's last modification time. |
|
| 46 |
+func (s StatT) Mtim() syscall.Timespec {
|
|
| 41 | 47 |
return s.mtim |
| 42 | 48 |
} |
| 43 | 49 |
|
| 44 |
-func (s Stat_t) GetLastModification() syscall.Timespec {
|
|
| 50 |
+// GetLastModification returns file's last modification time. |
|
| 51 |
+func (s StatT) GetLastModification() syscall.Timespec {
|
|
| 45 | 52 |
return s.Mtim() |
| 46 | 53 |
} |
| ... | ... |
@@ -5,8 +5,8 @@ import ( |
| 5 | 5 |
) |
| 6 | 6 |
|
| 7 | 7 |
// fromStatT converts a syscall.Stat_t type to a system.Stat_t type |
| 8 |
-func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
|
|
| 9 |
- return &Stat_t{size: s.Size,
|
|
| 8 |
+func fromStatT(s *syscall.Stat_t) (*StatT, error) {
|
|
| 9 |
+ return &StatT{size: s.Size,
|
|
| 10 | 10 |
mode: uint32(s.Mode), |
| 11 | 11 |
uid: s.Uid, |
| 12 | 12 |
gid: s.Gid, |
| ... | ... |
@@ -18,7 +18,7 @@ func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
|
| 18 | 18 |
// a system.Stat_t type pertaining to that file. |
| 19 | 19 |
// |
| 20 | 20 |
// Throws an error if the file does not exist |
| 21 |
-func Stat(path string) (*Stat_t, error) {
|
|
| 21 |
+func Stat(path string) (*StatT, error) {
|
|
| 22 | 22 |
s := &syscall.Stat_t{}
|
| 23 | 23 |
if err := syscall.Stat(path, s); err != nil {
|
| 24 | 24 |
return nil, err |
| ... | ... |
@@ -5,8 +5,8 @@ import ( |
| 5 | 5 |
) |
| 6 | 6 |
|
| 7 | 7 |
// fromStatT converts a syscall.Stat_t type to a system.Stat_t type |
| 8 |
-func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
|
|
| 9 |
- return &Stat_t{size: s.Size,
|
|
| 8 |
+func fromStatT(s *syscall.Stat_t) (*StatT, error) {
|
|
| 9 |
+ return &StatT{size: s.Size,
|
|
| 10 | 10 |
mode: s.Mode, |
| 11 | 11 |
uid: s.Uid, |
| 12 | 12 |
gid: s.Gid, |
| ... | ... |
@@ -14,17 +14,17 @@ func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
|
| 14 | 14 |
mtim: s.Mtim}, nil |
| 15 | 15 |
} |
| 16 | 16 |
|
| 17 |
-// FromStatT exists only on linux, and loads a system.Stat_t from a |
|
| 17 |
+// FromStatT exists only on linux, and loads a system.StatT from a |
|
| 18 | 18 |
// syscal.Stat_t. |
| 19 |
-func FromStatT(s *syscall.Stat_t) (*Stat_t, error) {
|
|
| 19 |
+func FromStatT(s *syscall.Stat_t) (*StatT, error) {
|
|
| 20 | 20 |
return fromStatT(s) |
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
// Stat takes a path to a file and returns |
| 24 |
-// a system.Stat_t type pertaining to that file. |
|
| 24 |
+// a system.StatT type pertaining to that file. |
|
| 25 | 25 |
// |
| 26 | 26 |
// Throws an error if the file does not exist |
| 27 |
-func Stat(path string) (*Stat_t, error) {
|
|
| 27 |
+func Stat(path string) (*StatT, error) {
|
|
| 28 | 28 |
s := &syscall.Stat_t{}
|
| 29 | 29 |
if err := syscall.Stat(path, s); err != nil {
|
| 30 | 30 |
return nil, err |
| ... | ... |
@@ -6,9 +6,9 @@ import ( |
| 6 | 6 |
"syscall" |
| 7 | 7 |
) |
| 8 | 8 |
|
| 9 |
-// fromStatT creates a system.Stat_t type from a syscall.Stat_t type |
|
| 10 |
-func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
|
|
| 11 |
- return &Stat_t{size: s.Size,
|
|
| 9 |
+// fromStatT creates a system.StatT type from a syscall.Stat_t type |
|
| 10 |
+func fromStatT(s *syscall.Stat_t) (*StatT, error) {
|
|
| 11 |
+ return &StatT{size: s.Size,
|
|
| 12 | 12 |
mode: uint32(s.Mode), |
| 13 | 13 |
uid: s.Uid, |
| 14 | 14 |
gid: s.Gid, |
| ... | ... |
@@ -7,7 +7,9 @@ import ( |
| 7 | 7 |
"time" |
| 8 | 8 |
) |
| 9 | 9 |
|
| 10 |
-type Stat_t struct {
|
|
| 10 |
+// StatT type contains status of a file. It contains metadata |
|
| 11 |
+// like name, permission, size, etc about a file. |
|
| 12 |
+type StatT struct {
|
|
| 11 | 13 |
name string |
| 12 | 14 |
size int64 |
| 13 | 15 |
mode os.FileMode |
| ... | ... |
@@ -15,22 +17,27 @@ type Stat_t struct {
|
| 15 | 15 |
isDir bool |
| 16 | 16 |
} |
| 17 | 17 |
|
| 18 |
-func (s Stat_t) Name() string {
|
|
| 18 |
+// Name returns file's name. |
|
| 19 |
+func (s StatT) Name() string {
|
|
| 19 | 20 |
return s.name |
| 20 | 21 |
} |
| 21 | 22 |
|
| 22 |
-func (s Stat_t) Size() int64 {
|
|
| 23 |
+// Size returns file's size. |
|
| 24 |
+func (s StatT) Size() int64 {
|
|
| 23 | 25 |
return s.size |
| 24 | 26 |
} |
| 25 | 27 |
|
| 26 |
-func (s Stat_t) Mode() os.FileMode {
|
|
| 28 |
+// Mode returns file's permission mode. |
|
| 29 |
+func (s StatT) Mode() os.FileMode {
|
|
| 27 | 30 |
return s.mode |
| 28 | 31 |
} |
| 29 | 32 |
|
| 30 |
-func (s Stat_t) ModTime() time.Time {
|
|
| 33 |
+// ModTime returns file's last modification time. |
|
| 34 |
+func (s StatT) ModTime() time.Time {
|
|
| 31 | 35 |
return s.modTime |
| 32 | 36 |
} |
| 33 | 37 |
|
| 34 |
-func (s Stat_t) IsDir() bool {
|
|
| 38 |
+// IsDir returns whether file is actually a directory. |
|
| 39 |
+func (s StatT) IsDir() bool {
|
|
| 35 | 40 |
return s.isDir |
| 36 | 41 |
} |
| ... | ... |
@@ -2,10 +2,13 @@ package system |
| 2 | 2 |
|
| 3 | 3 |
import "syscall" |
| 4 | 4 |
|
| 5 |
+// LUtimesNano is not supported by darwin platform. |
|
| 5 | 6 |
func LUtimesNano(path string, ts []syscall.Timespec) error {
|
| 6 | 7 |
return ErrNotSupportedPlatform |
| 7 | 8 |
} |
| 8 | 9 |
|
| 10 |
+// UtimesNano is used to change access and modification time of path. |
|
| 11 |
+// it can't be used for symbol link file. |
|
| 9 | 12 |
func UtimesNano(path string, ts []syscall.Timespec) error {
|
| 10 | 13 |
return syscall.UtimesNano(path, ts) |
| 11 | 14 |
} |
| ... | ... |
@@ -5,6 +5,8 @@ import ( |
| 5 | 5 |
"unsafe" |
| 6 | 6 |
) |
| 7 | 7 |
|
| 8 |
+// LUtimesNano is used to change access and modification time of the specified path. |
|
| 9 |
+// It's used for symbol link file because syscall.UtimesNano doesn't support a NOFOLLOW flag atm. |
|
| 8 | 10 |
func LUtimesNano(path string, ts []syscall.Timespec) error {
|
| 9 | 11 |
var _path *byte |
| 10 | 12 |
_path, err := syscall.BytePtrFromString(path) |
| ... | ... |
@@ -19,6 +21,8 @@ func LUtimesNano(path string, ts []syscall.Timespec) error {
|
| 19 | 19 |
return nil |
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 |
+// UtimesNano is used to change access and modification time of the specified path. |
|
| 23 |
+// It can't be used for symbol link file. |
|
| 22 | 24 |
func UtimesNano(path string, ts []syscall.Timespec) error {
|
| 23 | 25 |
return syscall.UtimesNano(path, ts) |
| 24 | 26 |
} |
| ... | ... |
@@ -5,10 +5,12 @@ import ( |
| 5 | 5 |
"unsafe" |
| 6 | 6 |
) |
| 7 | 7 |
|
| 8 |
+// LUtimesNano is used to change access and modification time of the speficied path. |
|
| 9 |
+// It's used for symbol link file because syscall.UtimesNano doesn't support a NOFOLLOW flag atm. |
|
| 8 | 10 |
func LUtimesNano(path string, ts []syscall.Timespec) error {
|
| 9 | 11 |
// These are not currently available in syscall |
| 10 |
- AT_FDCWD := -100 |
|
| 11 |
- AT_SYMLINK_NOFOLLOW := 0x100 |
|
| 12 |
+ atFdCwd := -100 |
|
| 13 |
+ atSymLinkNoFollow := 0x100 |
|
| 12 | 14 |
|
| 13 | 15 |
var _path *byte |
| 14 | 16 |
_path, err := syscall.BytePtrFromString(path) |
| ... | ... |
@@ -16,13 +18,15 @@ func LUtimesNano(path string, ts []syscall.Timespec) error {
|
| 16 | 16 |
return err |
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 |
- if _, _, err := syscall.Syscall6(syscall.SYS_UTIMENSAT, uintptr(AT_FDCWD), uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), uintptr(AT_SYMLINK_NOFOLLOW), 0, 0); err != 0 && err != syscall.ENOSYS {
|
|
| 19 |
+ if _, _, err := syscall.Syscall6(syscall.SYS_UTIMENSAT, uintptr(atFdCwd), uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), uintptr(atSymLinkNoFollow), 0, 0); err != 0 && err != syscall.ENOSYS {
|
|
| 20 | 20 |
return err |
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
return nil |
| 24 | 24 |
} |
| 25 | 25 |
|
| 26 |
+// UtimesNano is used to change access and modification time of the specified path. |
|
| 27 |
+// It can't be used for symbol link file. |
|
| 26 | 28 |
func UtimesNano(path string, ts []syscall.Timespec) error {
|
| 27 | 29 |
return syscall.UtimesNano(path, ts) |
| 28 | 30 |
} |
| ... | ... |
@@ -4,10 +4,12 @@ package system |
| 4 | 4 |
|
| 5 | 5 |
import "syscall" |
| 6 | 6 |
|
| 7 |
+// LUtimesNano is not supported on platforms other than linux, freebsd and darwin. |
|
| 7 | 8 |
func LUtimesNano(path string, ts []syscall.Timespec) error {
|
| 8 | 9 |
return ErrNotSupportedPlatform |
| 9 | 10 |
} |
| 10 | 11 |
|
| 12 |
+// UtimesNano is not supported on platforms other than linux, freebsd and darwin. |
|
| 11 | 13 |
func UtimesNano(path string, ts []syscall.Timespec) error {
|
| 12 | 14 |
return ErrNotSupportedPlatform |
| 13 | 15 |
} |
| ... | ... |
@@ -5,7 +5,9 @@ import ( |
| 5 | 5 |
"unsafe" |
| 6 | 6 |
) |
| 7 | 7 |
|
| 8 |
-// Returns a nil slice and nil error if the xattr is not set |
|
| 8 |
+// Lgetxattr retrieves the value of the extended attribute identified by attr |
|
| 9 |
+// and associated with the given path in the file system. |
|
| 10 |
+// It will returns a nil slice and nil error if the xattr is not set. |
|
| 9 | 11 |
func Lgetxattr(path string, attr string) ([]byte, error) {
|
| 10 | 12 |
pathBytes, err := syscall.BytePtrFromString(path) |
| 11 | 13 |
if err != nil {
|
| ... | ... |
@@ -36,6 +38,8 @@ func Lgetxattr(path string, attr string) ([]byte, error) {
|
| 36 | 36 |
|
| 37 | 37 |
var _zero uintptr |
| 38 | 38 |
|
| 39 |
+// Lsetxattr sets the value of the extended attribute identified by attr |
|
| 40 |
+// and associated with the given path in the file system. |
|
| 39 | 41 |
func Lsetxattr(path string, attr string, data []byte, flags int) error {
|
| 40 | 42 |
pathBytes, err := syscall.BytePtrFromString(path) |
| 41 | 43 |
if err != nil {
|
| ... | ... |
@@ -2,10 +2,12 @@ |
| 2 | 2 |
|
| 3 | 3 |
package system |
| 4 | 4 |
|
| 5 |
+// Lgetxattr is not supported on platforms other than linux. |
|
| 5 | 6 |
func Lgetxattr(path string, attr string) ([]byte, error) {
|
| 6 | 7 |
return nil, ErrNotSupportedPlatform |
| 7 | 8 |
} |
| 8 | 9 |
|
| 10 |
+// Lsetxattr is not supported on platforms other than linux. |
|
| 9 | 11 |
func Lsetxattr(path string, attr string, data []byte, flags int) error {
|
| 10 | 12 |
return ErrNotSupportedPlatform |
| 11 | 13 |
} |