Merge pull request #149 from vmarmol/path

Move from filepath -> path for Join.
This commit is contained in:
monnand 2014-08-04 12:24:27 -04:00
commit 6ba6807525
3 changed files with 16 additions and 17 deletions

BIN
cadvisor Executable file

Binary file not shown.

View File

@ -22,7 +22,6 @@ import (
"math" "math"
"os" "os"
"path" "path"
"path/filepath"
"strings" "strings"
"github.com/docker/libcontainer" "github.com/docker/libcontainer"
@ -240,7 +239,7 @@ func (self *dockerContainerHandler) ListContainers(listType container.ListType)
} }
ref := info.ContainerReference{ ref := info.ContainerReference{
Name: filepath.Join(containerPrefix, c.ID), Name: path.Join(containerPrefix, c.ID),
Aliases: c.Names, Aliases: c.Names,
} }
ret = append(ret, ref) ret = append(ret, ref)

View File

@ -18,7 +18,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"path/filepath" "path"
"strconv" "strconv"
"strings" "strings"
@ -56,8 +56,8 @@ func (self *rawContainerHandler) ContainerReference() (info.ContainerReference,
}, nil }, nil
} }
func readString(path string, file string) string { func readString(dirpath string, file string) string {
cgroupFile := filepath.Join(path, file) cgroupFile := path.Join(dirpath, file)
// Ignore non-existent files // Ignore non-existent files
if !utils.FileExists(cgroupFile) { if !utils.FileExists(cgroupFile) {
@ -73,15 +73,15 @@ func readString(path string, file string) string {
return string(out) return string(out)
} }
func readInt64(path string, file string) uint64 { func readInt64(dirpath string, file string) uint64 {
out := readString(path, file) out := readString(dirpath, file)
if out == "" { if out == "" {
return 0 return 0
} }
val, err := strconv.ParseUint(strings.TrimSpace(out), 10, 64) val, err := strconv.ParseUint(strings.TrimSpace(out), 10, 64)
if err != nil { if err != nil {
log.Printf("raw driver: Failed to parse in %q from file %q: %s", out, filepath.Join(path, file), err) log.Printf("raw driver: Failed to parse in %q from file %q: %s", out, path.Join(dirpath, file), err)
return 0 return 0
} }
@ -102,7 +102,7 @@ func (self *rawContainerHandler) GetSpec() (*info.ContainerSpec, error) {
// CPU. // CPU.
cpuRoot, ok := self.cgroupSubsystems.mountPoints["cpu"] cpuRoot, ok := self.cgroupSubsystems.mountPoints["cpu"]
if ok { if ok {
cpuRoot = filepath.Join(cpuRoot, self.name) cpuRoot = path.Join(cpuRoot, self.name)
if utils.FileExists(cpuRoot) { if utils.FileExists(cpuRoot) {
spec.Cpu = new(info.CpuSpec) spec.Cpu = new(info.CpuSpec)
spec.Cpu.Limit = readInt64(cpuRoot, "cpu.shares") spec.Cpu.Limit = readInt64(cpuRoot, "cpu.shares")
@ -116,7 +116,7 @@ func (self *rawContainerHandler) GetSpec() (*info.ContainerSpec, error) {
if spec.Cpu == nil { if spec.Cpu == nil {
spec.Cpu = new(info.CpuSpec) spec.Cpu = new(info.CpuSpec)
} }
cpusetRoot = filepath.Join(cpusetRoot, self.name) cpusetRoot = path.Join(cpusetRoot, self.name)
if utils.FileExists(cpusetRoot) { if utils.FileExists(cpusetRoot) {
spec.Cpu.Mask = readString(cpusetRoot, "cpuset.cpus") spec.Cpu.Mask = readString(cpusetRoot, "cpuset.cpus")
if spec.Cpu.Mask == "" { if spec.Cpu.Mask == "" {
@ -128,7 +128,7 @@ func (self *rawContainerHandler) GetSpec() (*info.ContainerSpec, error) {
// Memory. // Memory.
memoryRoot, ok := self.cgroupSubsystems.mountPoints["memory"] memoryRoot, ok := self.cgroupSubsystems.mountPoints["memory"]
if ok { if ok {
memoryRoot = filepath.Join(memoryRoot, self.name) memoryRoot = path.Join(memoryRoot, self.name)
if utils.FileExists(memoryRoot) { if utils.FileExists(memoryRoot) {
spec.Memory = new(info.MemorySpec) spec.Memory = new(info.MemorySpec)
spec.Memory.Limit = readInt64(memoryRoot, "memory.limit_in_bytes") spec.Memory.Limit = readInt64(memoryRoot, "memory.limit_in_bytes")
@ -144,25 +144,25 @@ func (self *rawContainerHandler) GetStats() (stats *info.ContainerStats, err err
} }
// Lists all directories under "path" and outputs the results as children of "parent". // Lists all directories under "path" and outputs the results as children of "parent".
func listDirectories(path string, parent string, recursive bool, output map[string]struct{}) error { func listDirectories(dirpath string, parent string, recursive bool, output map[string]struct{}) error {
// Ignore if this hierarchy does not exist. // Ignore if this hierarchy does not exist.
if !utils.FileExists(path) { if !utils.FileExists(dirpath) {
return nil return nil
} }
entries, err := ioutil.ReadDir(path) entries, err := ioutil.ReadDir(dirpath)
if err != nil { if err != nil {
return err return err
} }
for _, entry := range entries { for _, entry := range entries {
// We only grab directories. // We only grab directories.
if entry.IsDir() { if entry.IsDir() {
name := filepath.Join(parent, entry.Name()) name := path.Join(parent, entry.Name())
output[name] = struct{}{} output[name] = struct{}{}
// List subcontainers if asked to. // List subcontainers if asked to.
if recursive { if recursive {
err := listDirectories(filepath.Join(path, entry.Name()), name, true, output) err := listDirectories(path.Join(dirpath, entry.Name()), name, true, output)
if err != nil { if err != nil {
return err return err
} }
@ -175,7 +175,7 @@ func listDirectories(path string, parent string, recursive bool, output map[stri
func (self *rawContainerHandler) ListContainers(listType container.ListType) ([]info.ContainerReference, error) { func (self *rawContainerHandler) ListContainers(listType container.ListType) ([]info.ContainerReference, error) {
containers := make(map[string]struct{}, 16) containers := make(map[string]struct{}, 16)
for _, subsystem := range self.cgroupSubsystems.mounts { for _, subsystem := range self.cgroupSubsystems.mounts {
err := listDirectories(filepath.Join(subsystem.Mountpoint, self.name), self.name, listType == container.LIST_RECURSIVE, containers) err := listDirectories(path.Join(subsystem.Mountpoint, self.name), self.name, listType == container.LIST_RECURSIVE, containers)
if err != nil { if err != nil {
return nil, err return nil, err
} }