From 7e420ad8502089e66ce0ade92bf70574f894f287 Mon Sep 17 00:00:00 2001 From: Zhang Wei Date: Wed, 29 Jul 2015 00:13:12 +0800 Subject: [PATCH] fix golint warnings/errors on `pkg/system` and `pkg/stdcopy` Signed-off-by: Zhang Wei --- daemon/volumes_unix.go | 2 +- docker/daemon_unix.go | 2 +- hack/make/validate-lint | 4 ++- pkg/archive/changes.go | 2 +- pkg/archive/changes_unix.go | 4 +-- pkg/archive/changes_windows.go | 2 +- pkg/stdcopy/stdcopy.go | 57 +++++++++++++++++-------------- pkg/system/errors.go | 1 + pkg/system/events_windows.go | 16 ++++----- pkg/system/filesys.go | 2 ++ pkg/system/lstat.go | 4 +-- pkg/system/lstat_windows.go | 8 ++--- pkg/system/meminfo_linux.go | 5 --- pkg/system/meminfo_unsupported.go | 1 + pkg/system/mknod.go | 6 ++-- pkg/system/mknod_windows.go | 2 ++ pkg/system/stat.go | 27 +++++++++------ pkg/system/stat_freebsd.go | 6 ++-- pkg/system/stat_linux.go | 12 +++---- pkg/system/stat_test.go | 2 +- pkg/system/stat_unsupported.go | 6 ++-- pkg/system/stat_windows.go | 19 +++++++---- pkg/system/umask.go | 2 ++ pkg/system/umask_windows.go | 1 + pkg/system/utimes_darwin.go | 3 ++ pkg/system/utimes_freebsd.go | 4 +++ pkg/system/utimes_linux.go | 10 ++++-- pkg/system/utimes_unsupported.go | 2 ++ pkg/system/xattrs_linux.go | 6 +++- pkg/system/xattrs_unsupported.go | 2 ++ 30 files changed, 131 insertions(+), 89 deletions(-) diff --git a/daemon/volumes_unix.go b/daemon/volumes_unix.go index da9e62b9c1..6f6f4b48ba 100644 --- a/daemon/volumes_unix.go +++ b/daemon/volumes_unix.go @@ -28,7 +28,7 @@ func copyOwnership(source, destination string) error { return err } - if err := os.Chown(destination, int(stat.Uid()), int(stat.Gid())); err != nil { + if err := os.Chown(destination, int(stat.UID()), int(stat.Gid())); err != nil { return err } diff --git a/docker/daemon_unix.go b/docker/daemon_unix.go index 3ea96a7b08..7754130d34 100644 --- a/docker/daemon_unix.go +++ b/docker/daemon_unix.go @@ -26,7 +26,7 @@ func setPlatformServerConfig(serverConfig *apiserver.Config, daemonCfg *daemon.C // file. func currentUserIsOwner(f string) bool { if fileInfo, err := system.Stat(f); err == nil && fileInfo != nil { - if int(fileInfo.Uid()) == os.Getuid() { + if int(fileInfo.UID()) == os.Getuid() { return true } } diff --git a/hack/make/validate-lint b/hack/make/validate-lint index a8c27ef34b..e106871027 100644 --- a/hack/make/validate-lint +++ b/hack/make/validate-lint @@ -75,11 +75,13 @@ packages=( pkg/reexec pkg/signal pkg/sockets + pkg/stdcopy pkg/streamformatter pkg/stringid pkg/stringutils - pkg/sysinfo pkg/symlink + pkg/sysinfo + pkg/system pkg/tailfile pkg/tarsum pkg/term diff --git a/pkg/archive/changes.go b/pkg/archive/changes.go index 4619a4cfce..76c36b5215 100644 --- a/pkg/archive/changes.go +++ b/pkg/archive/changes.go @@ -173,7 +173,7 @@ func Changes(layers []string, rw string) ([]Change, error) { type FileInfo struct { parent *FileInfo name string - stat *system.Stat_t + stat *system.StatT children map[string]*FileInfo capability []byte added bool diff --git a/pkg/archive/changes_unix.go b/pkg/archive/changes_unix.go index d780f16398..a2ccbb2583 100644 --- a/pkg/archive/changes_unix.go +++ b/pkg/archive/changes_unix.go @@ -8,10 +8,10 @@ import ( "github.com/docker/docker/pkg/system" ) -func statDifferent(oldStat *system.Stat_t, newStat *system.Stat_t) bool { +func statDifferent(oldStat *system.StatT, newStat *system.StatT) bool { // Don't look at size for dirs, its not a good measure of change if oldStat.Mode() != newStat.Mode() || - oldStat.Uid() != newStat.Uid() || + oldStat.UID() != newStat.UID() || oldStat.Gid() != newStat.Gid() || oldStat.Rdev() != newStat.Rdev() || // Don't look at size for dirs, its not a good measure of change diff --git a/pkg/archive/changes_windows.go b/pkg/archive/changes_windows.go index 4809b7a59c..135db369e5 100644 --- a/pkg/archive/changes_windows.go +++ b/pkg/archive/changes_windows.go @@ -4,7 +4,7 @@ import ( "github.com/docker/docker/pkg/system" ) -func statDifferent(oldStat *system.Stat_t, newStat *system.Stat_t) bool { +func statDifferent(oldStat *system.StatT, newStat *system.StatT) bool { // Don't look at size for dirs, its not a good measure of change if oldStat.ModTime() != newStat.ModTime() || diff --git a/pkg/stdcopy/stdcopy.go b/pkg/stdcopy/stdcopy.go index 684b4d4cd1..89c64baec0 100644 --- a/pkg/stdcopy/stdcopy.go +++ b/pkg/stdcopy/stdcopy.go @@ -9,19 +9,24 @@ import ( ) const ( - StdWriterPrefixLen = 8 - StdWriterFdIndex = 0 - StdWriterSizeIndex = 4 + stdWriterPrefixLen = 8 + stdWriterFdIndex = 0 + stdWriterSizeIndex = 4 ) -type StdType [StdWriterPrefixLen]byte +// StdType prefixes type and length to standard stream. +type StdType [stdWriterPrefixLen]byte var ( - Stdin StdType = StdType{0: 0} - Stdout StdType = StdType{0: 1} - Stderr StdType = StdType{0: 2} + // Stdin represents standard input stream type. + Stdin = StdType{0: 0} + // Stdout represents standard output stream type. + Stdout = StdType{0: 1} + // Stderr represents standard error steam type. + Stderr = StdType{0: 2} ) +// StdWriter is wrapper of io.Writer with extra customized info. type StdWriter struct { io.Writer prefix StdType @@ -36,10 +41,10 @@ func (w *StdWriter) Write(buf []byte) (n int, err error) { binary.BigEndian.PutUint32(w.prefix[4:], uint32(len(buf))) n1, err = w.Writer.Write(w.prefix[:]) if err != nil { - n = n1 - StdWriterPrefixLen + n = n1 - stdWriterPrefixLen } else { n2, err = w.Writer.Write(buf) - n = n1 + n2 - StdWriterPrefixLen + n = n1 + n2 - stdWriterPrefixLen } if n < 0 { n = 0 @@ -61,7 +66,7 @@ func NewStdWriter(w io.Writer, t StdType) *StdWriter { } } -var ErrInvalidStdHeader = errors.New("Unrecognized input header") +var errInvalidStdHeader = errors.New("Unrecognized input header") // StdCopy is a modified version of io.Copy. // @@ -75,7 +80,7 @@ var ErrInvalidStdHeader = errors.New("Unrecognized input header") // `written` will hold the total number of bytes written to `dstout` and `dsterr`. func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) { var ( - buf = make([]byte, 32*1024+StdWriterPrefixLen+1) + buf = make([]byte, 32*1024+stdWriterPrefixLen+1) bufLen = len(buf) nr, nw int er, ew error @@ -85,12 +90,12 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) for { // Make sure we have at least a full header - for nr < StdWriterPrefixLen { + for nr < stdWriterPrefixLen { var nr2 int nr2, er = src.Read(buf[nr:]) nr += nr2 if er == io.EOF { - if nr < StdWriterPrefixLen { + if nr < stdWriterPrefixLen { logrus.Debugf("Corrupted prefix: %v", buf[:nr]) return written, nil } @@ -103,7 +108,7 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) } // Check the first byte to know where to write - switch buf[StdWriterFdIndex] { + switch buf[stdWriterFdIndex] { case 0: fallthrough case 1: @@ -113,30 +118,30 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) // Write on stderr out = dsterr default: - logrus.Debugf("Error selecting output fd: (%d)", buf[StdWriterFdIndex]) - return 0, ErrInvalidStdHeader + logrus.Debugf("Error selecting output fd: (%d)", buf[stdWriterFdIndex]) + return 0, errInvalidStdHeader } // Retrieve the size of the frame - frameSize = int(binary.BigEndian.Uint32(buf[StdWriterSizeIndex : StdWriterSizeIndex+4])) + frameSize = int(binary.BigEndian.Uint32(buf[stdWriterSizeIndex : stdWriterSizeIndex+4])) logrus.Debugf("framesize: %d", frameSize) // Check if the buffer is big enough to read the frame. // Extend it if necessary. - if frameSize+StdWriterPrefixLen > bufLen { - logrus.Debugf("Extending buffer cap by %d (was %d)", frameSize+StdWriterPrefixLen-bufLen+1, len(buf)) - buf = append(buf, make([]byte, frameSize+StdWriterPrefixLen-bufLen+1)...) + if frameSize+stdWriterPrefixLen > bufLen { + logrus.Debugf("Extending buffer cap by %d (was %d)", frameSize+stdWriterPrefixLen-bufLen+1, len(buf)) + buf = append(buf, make([]byte, frameSize+stdWriterPrefixLen-bufLen+1)...) bufLen = len(buf) } // While the amount of bytes read is less than the size of the frame + header, we keep reading - for nr < frameSize+StdWriterPrefixLen { + for nr < frameSize+stdWriterPrefixLen { var nr2 int nr2, er = src.Read(buf[nr:]) nr += nr2 if er == io.EOF { - if nr < frameSize+StdWriterPrefixLen { - logrus.Debugf("Corrupted frame: %v", buf[StdWriterPrefixLen:nr]) + if nr < frameSize+stdWriterPrefixLen { + logrus.Debugf("Corrupted frame: %v", buf[stdWriterPrefixLen:nr]) return written, nil } break @@ -148,7 +153,7 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) } // Write the retrieved frame (without header) - nw, ew = out.Write(buf[StdWriterPrefixLen : frameSize+StdWriterPrefixLen]) + nw, ew = out.Write(buf[stdWriterPrefixLen : frameSize+stdWriterPrefixLen]) if ew != nil { logrus.Debugf("Error writing frame: %s", ew) return 0, ew @@ -161,8 +166,8 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) written += int64(nw) // Move the rest of the buffer to the beginning - copy(buf, buf[frameSize+StdWriterPrefixLen:]) + copy(buf, buf[frameSize+stdWriterPrefixLen:]) // Move the index - nr -= frameSize + StdWriterPrefixLen + nr -= frameSize + stdWriterPrefixLen } } diff --git a/pkg/system/errors.go b/pkg/system/errors.go index 63045186fe..288318985e 100644 --- a/pkg/system/errors.go +++ b/pkg/system/errors.go @@ -5,5 +5,6 @@ import ( ) var ( + // ErrNotSupportedPlatform means the platform is not supported. ErrNotSupportedPlatform = errors.New("platform and architecture is not supported") ) diff --git a/pkg/system/events_windows.go b/pkg/system/events_windows.go index 23f7c618bc..04e2de7871 100644 --- a/pkg/system/events_windows.go +++ b/pkg/system/events_windows.go @@ -8,11 +8,6 @@ import ( "unsafe" ) -const ( - EVENT_ALL_ACCESS = 0x1F0003 - EVENT_MODIFY_STATUS = 0x0002 -) - var ( procCreateEvent = modkernel32.NewProc("CreateEventW") procOpenEvent = modkernel32.NewProc("OpenEventW") @@ -21,13 +16,14 @@ var ( procPulseEvent = modkernel32.NewProc("PulseEvent") ) +// CreateEvent implements win32 CreateEventW func in golang. It will create an event object. func CreateEvent(eventAttributes *syscall.SecurityAttributes, manualReset bool, initialState bool, name string) (handle syscall.Handle, err error) { namep, _ := syscall.UTF16PtrFromString(name) - var _p1 uint32 = 0 + var _p1 uint32 if manualReset { _p1 = 1 } - var _p2 uint32 = 0 + var _p2 uint32 if initialState { _p2 = 1 } @@ -40,9 +36,10 @@ func CreateEvent(eventAttributes *syscall.SecurityAttributes, manualReset bool, return } +// OpenEvent implements win32 OpenEventW func in golang. It opens an event object. func OpenEvent(desiredAccess uint32, inheritHandle bool, name string) (handle syscall.Handle, err error) { namep, _ := syscall.UTF16PtrFromString(name) - var _p1 uint32 = 0 + var _p1 uint32 if inheritHandle { _p1 = 1 } @@ -55,14 +52,17 @@ func OpenEvent(desiredAccess uint32, inheritHandle bool, name string) (handle sy return } +// SetEvent implements win32 SetEvent func in golang. func SetEvent(handle syscall.Handle) (err error) { return setResetPulse(handle, procSetEvent) } +// ResetEvent implements win32 ResetEvent func in golang. func ResetEvent(handle syscall.Handle) (err error) { return setResetPulse(handle, procResetEvent) } +// PulseEvent implements win32 PulseEvent func in golang. func PulseEvent(handle syscall.Handle) (err error) { return setResetPulse(handle, procPulseEvent) } diff --git a/pkg/system/filesys.go b/pkg/system/filesys.go index e1f70e8dac..3e26e358ec 100644 --- a/pkg/system/filesys.go +++ b/pkg/system/filesys.go @@ -6,6 +6,8 @@ import ( "os" ) +// MkdirAll creates a directory named path along with any necessary parents, +// with permission specified by attribute perm for all dir created. func MkdirAll(path string, perm os.FileMode) error { return os.MkdirAll(path, perm) } diff --git a/pkg/system/lstat.go b/pkg/system/lstat.go index d0e43b3709..bd23c4d50b 100644 --- a/pkg/system/lstat.go +++ b/pkg/system/lstat.go @@ -7,10 +7,10 @@ import ( ) // Lstat takes a path to a file and returns -// a system.Stat_t type pertaining to that file. +// a system.StatT type pertaining to that file. // // Throws an error if the file does not exist -func Lstat(path string) (*Stat_t, error) { +func Lstat(path string) (*StatT, error) { s := &syscall.Stat_t{} if err := syscall.Lstat(path, s); err != nil { return nil, err diff --git a/pkg/system/lstat_windows.go b/pkg/system/lstat_windows.go index eee1be26eb..49e87eb40b 100644 --- a/pkg/system/lstat_windows.go +++ b/pkg/system/lstat_windows.go @@ -6,21 +6,17 @@ import ( "os" ) -// Some explanation for my own sanity, and hopefully maintainers in the -// future. -// // Lstat calls os.Lstat to get a fileinfo interface back. // This is then copied into our own locally defined structure. // Note the Linux version uses fromStatT to do the copy back, // but that not strictly necessary when already in an OS specific module. - -func Lstat(path string) (*Stat_t, error) { +func Lstat(path string) (*StatT, error) { fi, err := os.Lstat(path) if err != nil { return nil, err } - return &Stat_t{ + return &StatT{ name: fi.Name(), size: fi.Size(), mode: fi.Mode(), diff --git a/pkg/system/meminfo_linux.go b/pkg/system/meminfo_linux.go index e2ca140092..a07bb17cbc 100644 --- a/pkg/system/meminfo_linux.go +++ b/pkg/system/meminfo_linux.go @@ -2,7 +2,6 @@ package system import ( "bufio" - "errors" "io" "os" "strconv" @@ -11,10 +10,6 @@ import ( "github.com/docker/docker/pkg/units" ) -var ( - ErrMalformed = errors.New("malformed file") -) - // ReadMemInfo retrieves memory statistics of the host system and returns a // MemInfo type. func ReadMemInfo() (*MemInfo, error) { diff --git a/pkg/system/meminfo_unsupported.go b/pkg/system/meminfo_unsupported.go index 604d338754..82ddd30c1b 100644 --- a/pkg/system/meminfo_unsupported.go +++ b/pkg/system/meminfo_unsupported.go @@ -2,6 +2,7 @@ package system +// ReadMemInfo is not supported on platforms other than linux and windows. func ReadMemInfo() (*MemInfo, error) { return nil, ErrNotSupportedPlatform } diff --git a/pkg/system/mknod.go b/pkg/system/mknod.go index 26617eb08f..73958182b4 100644 --- a/pkg/system/mknod.go +++ b/pkg/system/mknod.go @@ -7,14 +7,16 @@ import ( ) // Mknod creates a filesystem node (file, device special file or named pipe) named path -// with attributes specified by mode and dev +// with attributes specified by mode and dev. func Mknod(path string, mode uint32, dev int) error { return syscall.Mknod(path, mode, dev) } +// Mkdev is used to build the value of linux devices (in /dev/) which specifies major +// and minor number of the newly created device special file. // Linux device nodes are a bit weird due to backwards compat with 16 bit device nodes. // They are, from low to high: the lower 8 bits of the minor, then 12 bits of the major, -// then the top 12 bits of the minor +// then the top 12 bits of the minor. func Mkdev(major int64, minor int64) uint32 { return uint32(((minor & 0xfff00) << 12) | ((major & 0xfff) << 8) | (minor & 0xff)) } diff --git a/pkg/system/mknod_windows.go b/pkg/system/mknod_windows.go index 1811542ab3..2e863c0215 100644 --- a/pkg/system/mknod_windows.go +++ b/pkg/system/mknod_windows.go @@ -2,10 +2,12 @@ package system +// Mknod is not implemented on Windows. func Mknod(path string, mode uint32, dev int) error { return ErrNotSupportedPlatform } +// Mkdev is not implemented on Windows. func Mkdev(major int64, minor int64) uint32 { panic("Mkdev not implemented on Windows.") } diff --git a/pkg/system/stat.go b/pkg/system/stat.go index e2ecfe52fe..7392c82029 100644 --- a/pkg/system/stat.go +++ b/pkg/system/stat.go @@ -6,9 +6,9 @@ import ( "syscall" ) -// Stat_t type contains status of a file. It contains metadata -// like permission, owner, group, size, etc about a file -type Stat_t struct { +// StatT type contains status of a file. It contains metadata +// like permission, owner, group, size, etc about a file. +type StatT struct { mode uint32 uid uint32 gid uint32 @@ -17,30 +17,37 @@ type Stat_t struct { mtim syscall.Timespec } -func (s Stat_t) Mode() uint32 { +// Mode returns file's permission mode. +func (s StatT) Mode() uint32 { return s.mode } -func (s Stat_t) Uid() uint32 { +// UID returns file's user id of owner. +func (s StatT) UID() uint32 { return s.uid } -func (s Stat_t) Gid() uint32 { +// Gid returns file's group id of owner. +func (s StatT) Gid() uint32 { return s.gid } -func (s Stat_t) Rdev() uint64 { +// Rdev returns file's device ID (if it's special file). +func (s StatT) Rdev() uint64 { return s.rdev } -func (s Stat_t) Size() int64 { +// Size returns file's size. +func (s StatT) Size() int64 { return s.size } -func (s Stat_t) Mtim() syscall.Timespec { +// Mtim returns file's last modification time. +func (s StatT) Mtim() syscall.Timespec { return s.mtim } -func (s Stat_t) GetLastModification() syscall.Timespec { +// GetLastModification returns file's last modification time. +func (s StatT) GetLastModification() syscall.Timespec { return s.Mtim() } diff --git a/pkg/system/stat_freebsd.go b/pkg/system/stat_freebsd.go index 4b2198b3aa..d0fb6f1519 100644 --- a/pkg/system/stat_freebsd.go +++ b/pkg/system/stat_freebsd.go @@ -5,8 +5,8 @@ import ( ) // fromStatT converts a syscall.Stat_t type to a system.Stat_t type -func fromStatT(s *syscall.Stat_t) (*Stat_t, error) { - return &Stat_t{size: s.Size, +func fromStatT(s *syscall.Stat_t) (*StatT, error) { + return &StatT{size: s.Size, mode: uint32(s.Mode), uid: s.Uid, gid: s.Gid, @@ -18,7 +18,7 @@ func fromStatT(s *syscall.Stat_t) (*Stat_t, error) { // a system.Stat_t type pertaining to that file. // // Throws an error if the file does not exist -func Stat(path string) (*Stat_t, error) { +func Stat(path string) (*StatT, error) { s := &syscall.Stat_t{} if err := syscall.Stat(path, s); err != nil { return nil, err diff --git a/pkg/system/stat_linux.go b/pkg/system/stat_linux.go index 80262d9519..8b1eded138 100644 --- a/pkg/system/stat_linux.go +++ b/pkg/system/stat_linux.go @@ -5,8 +5,8 @@ import ( ) // fromStatT converts a syscall.Stat_t type to a system.Stat_t type -func fromStatT(s *syscall.Stat_t) (*Stat_t, error) { - return &Stat_t{size: s.Size, +func fromStatT(s *syscall.Stat_t) (*StatT, error) { + return &StatT{size: s.Size, mode: s.Mode, uid: s.Uid, gid: s.Gid, @@ -14,17 +14,17 @@ func fromStatT(s *syscall.Stat_t) (*Stat_t, error) { mtim: s.Mtim}, nil } -// FromStatT exists only on linux, and loads a system.Stat_t from a +// FromStatT exists only on linux, and loads a system.StatT from a // syscal.Stat_t. -func FromStatT(s *syscall.Stat_t) (*Stat_t, error) { +func FromStatT(s *syscall.Stat_t) (*StatT, error) { return fromStatT(s) } // Stat takes a path to a file and returns -// a system.Stat_t type pertaining to that file. +// a system.StatT type pertaining to that file. // // Throws an error if the file does not exist -func Stat(path string) (*Stat_t, error) { +func Stat(path string) (*StatT, error) { s := &syscall.Stat_t{} if err := syscall.Stat(path, s); err != nil { return nil, err diff --git a/pkg/system/stat_test.go b/pkg/system/stat_test.go index 4534129200..57121f1579 100644 --- a/pkg/system/stat_test.go +++ b/pkg/system/stat_test.go @@ -22,7 +22,7 @@ func TestFromStatT(t *testing.T) { if stat.Mode != s.Mode() { t.Fatal("got invalid mode") } - if stat.Uid != s.Uid() { + if stat.Uid != s.UID() { t.Fatal("got invalid uid") } if stat.Gid != s.Gid() { diff --git a/pkg/system/stat_unsupported.go b/pkg/system/stat_unsupported.go index 5251ae2129..381ea82116 100644 --- a/pkg/system/stat_unsupported.go +++ b/pkg/system/stat_unsupported.go @@ -6,9 +6,9 @@ import ( "syscall" ) -// fromStatT creates a system.Stat_t type from a syscall.Stat_t type -func fromStatT(s *syscall.Stat_t) (*Stat_t, error) { - return &Stat_t{size: s.Size, +// fromStatT creates a system.StatT type from a syscall.Stat_t type +func fromStatT(s *syscall.Stat_t) (*StatT, error) { + return &StatT{size: s.Size, mode: uint32(s.Mode), uid: s.Uid, gid: s.Gid, diff --git a/pkg/system/stat_windows.go b/pkg/system/stat_windows.go index b1fd39e83f..39490c625c 100644 --- a/pkg/system/stat_windows.go +++ b/pkg/system/stat_windows.go @@ -7,7 +7,9 @@ import ( "time" ) -type Stat_t struct { +// StatT type contains status of a file. It contains metadata +// like name, permission, size, etc about a file. +type StatT struct { name string size int64 mode os.FileMode @@ -15,22 +17,27 @@ type Stat_t struct { isDir bool } -func (s Stat_t) Name() string { +// Name returns file's name. +func (s StatT) Name() string { return s.name } -func (s Stat_t) Size() int64 { +// Size returns file's size. +func (s StatT) Size() int64 { return s.size } -func (s Stat_t) Mode() os.FileMode { +// Mode returns file's permission mode. +func (s StatT) Mode() os.FileMode { return s.mode } -func (s Stat_t) ModTime() time.Time { +// ModTime returns file's last modification time. +func (s StatT) ModTime() time.Time { return s.modTime } -func (s Stat_t) IsDir() bool { +// IsDir returns whether file is actually a directory. +func (s StatT) IsDir() bool { return s.isDir } diff --git a/pkg/system/umask.go b/pkg/system/umask.go index fddbecd390..c670fcd758 100644 --- a/pkg/system/umask.go +++ b/pkg/system/umask.go @@ -6,6 +6,8 @@ import ( "syscall" ) +// Umask sets current process's file mode creation mask to newmask +// and return oldmask. func Umask(newmask int) (oldmask int, err error) { return syscall.Umask(newmask), nil } diff --git a/pkg/system/umask_windows.go b/pkg/system/umask_windows.go index 3be563f89e..13f1de1769 100644 --- a/pkg/system/umask_windows.go +++ b/pkg/system/umask_windows.go @@ -2,6 +2,7 @@ package system +// Umask is not supported on the windows platform. func Umask(newmask int) (oldmask int, err error) { // should not be called on cli code path return 0, ErrNotSupportedPlatform diff --git a/pkg/system/utimes_darwin.go b/pkg/system/utimes_darwin.go index 4c6002fe8e..9e3dcddbc1 100644 --- a/pkg/system/utimes_darwin.go +++ b/pkg/system/utimes_darwin.go @@ -2,10 +2,13 @@ package system import "syscall" +// LUtimesNano is not supported by darwin platform. func LUtimesNano(path string, ts []syscall.Timespec) error { return ErrNotSupportedPlatform } +// UtimesNano is used to change access and modification time of path. +// it can't be used for symbol link file. func UtimesNano(path string, ts []syscall.Timespec) error { return syscall.UtimesNano(path, ts) } diff --git a/pkg/system/utimes_freebsd.go b/pkg/system/utimes_freebsd.go index ceaa044c1c..15ce26f063 100644 --- a/pkg/system/utimes_freebsd.go +++ b/pkg/system/utimes_freebsd.go @@ -5,6 +5,8 @@ import ( "unsafe" ) +// LUtimesNano is used to change access and modification time of the specified path. +// It's used for symbol link file because syscall.UtimesNano doesn't support a NOFOLLOW flag atm. func LUtimesNano(path string, ts []syscall.Timespec) error { var _path *byte _path, err := syscall.BytePtrFromString(path) @@ -19,6 +21,8 @@ func LUtimesNano(path string, ts []syscall.Timespec) error { return nil } +// UtimesNano is used to change access and modification time of the specified path. +// It can't be used for symbol link file. func UtimesNano(path string, ts []syscall.Timespec) error { return syscall.UtimesNano(path, ts) } diff --git a/pkg/system/utimes_linux.go b/pkg/system/utimes_linux.go index 8f90298271..7909801f9e 100644 --- a/pkg/system/utimes_linux.go +++ b/pkg/system/utimes_linux.go @@ -5,10 +5,12 @@ import ( "unsafe" ) +// LUtimesNano is used to change access and modification time of the speficied path. +// It's used for symbol link file because syscall.UtimesNano doesn't support a NOFOLLOW flag atm. func LUtimesNano(path string, ts []syscall.Timespec) error { // These are not currently available in syscall - AT_FDCWD := -100 - AT_SYMLINK_NOFOLLOW := 0x100 + atFdCwd := -100 + atSymLinkNoFollow := 0x100 var _path *byte _path, err := syscall.BytePtrFromString(path) @@ -16,13 +18,15 @@ func LUtimesNano(path string, ts []syscall.Timespec) error { return err } - 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 { + 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 { return err } return nil } +// UtimesNano is used to change access and modification time of the specified path. +// It can't be used for symbol link file. func UtimesNano(path string, ts []syscall.Timespec) error { return syscall.UtimesNano(path, ts) } diff --git a/pkg/system/utimes_unsupported.go b/pkg/system/utimes_unsupported.go index adf2734f27..cb614a12a3 100644 --- a/pkg/system/utimes_unsupported.go +++ b/pkg/system/utimes_unsupported.go @@ -4,10 +4,12 @@ package system import "syscall" +// LUtimesNano is not supported on platforms other than linux, freebsd and darwin. func LUtimesNano(path string, ts []syscall.Timespec) error { return ErrNotSupportedPlatform } +// UtimesNano is not supported on platforms other than linux, freebsd and darwin. func UtimesNano(path string, ts []syscall.Timespec) error { return ErrNotSupportedPlatform } diff --git a/pkg/system/xattrs_linux.go b/pkg/system/xattrs_linux.go index 00edb201b5..d2e2c05799 100644 --- a/pkg/system/xattrs_linux.go +++ b/pkg/system/xattrs_linux.go @@ -5,7 +5,9 @@ import ( "unsafe" ) -// Returns a nil slice and nil error if the xattr is not set +// Lgetxattr retrieves the value of the extended attribute identified by attr +// and associated with the given path in the file system. +// It will returns a nil slice and nil error if the xattr is not set. func Lgetxattr(path string, attr string) ([]byte, error) { pathBytes, err := syscall.BytePtrFromString(path) if err != nil { @@ -36,6 +38,8 @@ func Lgetxattr(path string, attr string) ([]byte, error) { var _zero uintptr +// Lsetxattr sets the value of the extended attribute identified by attr +// and associated with the given path in the file system. func Lsetxattr(path string, attr string, data []byte, flags int) error { pathBytes, err := syscall.BytePtrFromString(path) if err != nil { diff --git a/pkg/system/xattrs_unsupported.go b/pkg/system/xattrs_unsupported.go index 0060c167dc..0114f2227c 100644 --- a/pkg/system/xattrs_unsupported.go +++ b/pkg/system/xattrs_unsupported.go @@ -2,10 +2,12 @@ package system +// Lgetxattr is not supported on platforms other than linux. func Lgetxattr(path string, attr string) ([]byte, error) { return nil, ErrNotSupportedPlatform } +// Lsetxattr is not supported on platforms other than linux. func Lsetxattr(path string, attr string, data []byte, flags int) error { return ErrNotSupportedPlatform }