Ver código fonte

Add some documentation to pkg/system

Partially addresses #11581

Signed-off-by: Ankush Agarwal <ankushagarwal11@gmail.com>
Ankush Agarwal 10 anos atrás
pai
commit
e94a48ffc8

+ 4 - 0
pkg/system/lstat.go

@@ -6,6 +6,10 @@ import (
 	"syscall"
 	"syscall"
 )
 )
 
 
+// Lstat takes a path to a file and returns
+// a system.Stat_t 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) (*Stat_t, error) {
 	s := &syscall.Stat_t{}
 	s := &syscall.Stat_t{}
 	err := syscall.Lstat(path, s)
 	err := syscall.Lstat(path, s)

+ 1 - 0
pkg/system/lstat_test.go

@@ -5,6 +5,7 @@ import (
 	"testing"
 	"testing"
 )
 )
 
 
+// TestLstat tests Lstat for existing and non existing files
 func TestLstat(t *testing.T) {
 func TestLstat(t *testing.T) {
 	file, invalid, _, dir := prepareFiles(t)
 	file, invalid, _, dir := prepareFiles(t)
 	defer os.RemoveAll(dir)
 	defer os.RemoveAll(dir)

+ 6 - 2
pkg/system/meminfo_linux.go

@@ -15,8 +15,8 @@ var (
 	ErrMalformed = errors.New("malformed file")
 	ErrMalformed = errors.New("malformed file")
 )
 )
 
 
-// Retrieve memory statistics of the host system and parse them into a MemInfo
-// type.
+// ReadMemInfo retrieves memory statistics of the host system and returns a
+//  MemInfo type.
 func ReadMemInfo() (*MemInfo, error) {
 func ReadMemInfo() (*MemInfo, error) {
 	file, err := os.Open("/proc/meminfo")
 	file, err := os.Open("/proc/meminfo")
 	if err != nil {
 	if err != nil {
@@ -26,6 +26,10 @@ func ReadMemInfo() (*MemInfo, error) {
 	return parseMemInfo(file)
 	return parseMemInfo(file)
 }
 }
 
 
+// parseMemInfo parses the /proc/meminfo file into
+// a MemInfo object given a io.Reader to the file.
+//
+// Throws error if there are problems reading from the file
 func parseMemInfo(reader io.Reader) (*MemInfo, error) {
 func parseMemInfo(reader io.Reader) (*MemInfo, error) {
 	meminfo := &MemInfo{}
 	meminfo := &MemInfo{}
 	scanner := bufio.NewScanner(reader)
 	scanner := bufio.NewScanner(reader)

+ 1 - 0
pkg/system/meminfo_linux_test.go

@@ -7,6 +7,7 @@ import (
 	"github.com/docker/docker/pkg/units"
 	"github.com/docker/docker/pkg/units"
 )
 )
 
 
+// TestMemInfo tests parseMemInfo with a static meminfo string
 func TestMemInfo(t *testing.T) {
 func TestMemInfo(t *testing.T) {
 	const input = `
 	const input = `
 	MemTotal:      1 kB
 	MemTotal:      1 kB

+ 2 - 0
pkg/system/mknod.go

@@ -6,6 +6,8 @@ import (
 	"syscall"
 	"syscall"
 )
 )
 
 
+// Mknod creates a filesystem node (file, device special file or named pipe) named path
+// with attributes specified by mode and dev
 func Mknod(path string, mode uint32, dev int) error {
 func Mknod(path string, mode uint32, dev int) error {
 	return syscall.Mknod(path, mode, dev)
 	return syscall.Mknod(path, mode, dev)
 }
 }

+ 2 - 0
pkg/system/stat.go

@@ -4,6 +4,8 @@ import (
 	"syscall"
 	"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 {
 type Stat_t struct {
 	mode uint32
 	mode uint32
 	uid  uint32
 	uid  uint32

+ 5 - 0
pkg/system/stat_linux.go

@@ -4,6 +4,7 @@ import (
 	"syscall"
 	"syscall"
 )
 )
 
 
+// fromStatT converts a syscall.Stat_t type to a system.Stat_t type
 func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
 func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
 	return &Stat_t{size: s.Size,
 	return &Stat_t{size: s.Size,
 		mode: s.Mode,
 		mode: s.Mode,
@@ -13,6 +14,10 @@ func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
 		mtim: s.Mtim}, nil
 		mtim: s.Mtim}, nil
 }
 }
 
 
+// Stat takes a path to a file and returns
+// 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) (*Stat_t, error) {
 	s := &syscall.Stat_t{}
 	s := &syscall.Stat_t{}
 	err := syscall.Stat(path, s)
 	err := syscall.Stat(path, s)

+ 1 - 0
pkg/system/stat_test.go

@@ -6,6 +6,7 @@ import (
 	"testing"
 	"testing"
 )
 )
 
 
+// TestFromStatT tests fromStatT for a tempfile
 func TestFromStatT(t *testing.T) {
 func TestFromStatT(t *testing.T) {
 	file, _, _, dir := prepareFiles(t)
 	file, _, _, dir := prepareFiles(t)
 	defer os.RemoveAll(dir)
 	defer os.RemoveAll(dir)

+ 1 - 0
pkg/system/stat_unsupported.go

@@ -6,6 +6,7 @@ import (
 	"syscall"
 	"syscall"
 )
 )
 
 
+// fromStatT creates a system.Stat_t type from a syscall.Stat_t type
 func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
 func fromStatT(s *syscall.Stat_t) (*Stat_t, error) {
 	return &Stat_t{size: s.Size,
 	return &Stat_t{size: s.Size,
 		mode: uint32(s.Mode),
 		mode: uint32(s.Mode),

+ 1 - 0
pkg/system/utimes_test.go

@@ -8,6 +8,7 @@ import (
 	"testing"
 	"testing"
 )
 )
 
 
+// prepareFiles creates files for testing in the temp directory
 func prepareFiles(t *testing.T) (string, string, string, string) {
 func prepareFiles(t *testing.T) (string, string, string, string) {
 	dir, err := ioutil.TempDir("", "docker-system-test")
 	dir, err := ioutil.TempDir("", "docker-system-test")
 	if err != nil {
 	if err != nil {