Skip to content

Commit

Permalink
Add a utility for container file listing [Updates #2]
Browse files Browse the repository at this point in the history
  • Loading branch information
jandre committed Aug 26, 2015
1 parent 2553700 commit 348e2c1
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ endif
all: bindata
@mkdir -p bin/
@$(ECHO) "$(OK_COLOR)==> Building $(NAME) $(VERSION) $(NO_COLOR)"
@godep go build -o bin/$(NAME) cmd/*
@godep go build -o bin/$(NAME) cmd/*.go
@mkdir -p bin/util/
@$(ECHO) "$(OK_COLOR)==> Building utils $(NO_COLOR)"
@godep go build -o bin/util/files cmd/util/files.go
@chmod +x bin/$(NAME)
@chmod +x bin/util/*
@$(ECHO) "$(OK_COLOR)==> Done building$(NO_COLOR)"

build: bindata all
Expand Down
73 changes: 73 additions & 0 deletions cmd/util/files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package main

import (
"encoding/json"
"io/ioutil"
"log"
"os"
"time"

kingpin "gopkg.in/alecthomas/kingpin.v1"
)

var (
Version = "0.1.0"
app = kingpin.New("files", "Command for listing a file in JSON")
appPath = app.Flag("path", "path to list").Required().Short('s').String()
)

type ShortFileInfo struct {
Name string
Size int64
IsDir bool
IsLink bool
ModTime time.Time
}

func NewShortFileInfo(f os.FileInfo) *ShortFileInfo {
fi := ShortFileInfo{}
fi.Name = f.Name()
fi.Size = f.Size()
fi.IsDir = f.IsDir()
fi.ModTime = f.ModTime()
fi.IsLink = (f.Mode()&os.ModeType)&os.ModeSymlink > 0

return &fi
}

//
// Go helper utility for container
// to perform file commands.
//
// Will output FileInfo to JSON
//
func main() {

app.Version(Version)
_, err := app.Parse(os.Args[1:])

if err != nil {
app.Usage(os.Stderr)
log.Fatal(err)
os.Exit(1)
}

files, err := ioutil.ReadDir(*appPath)
if err != nil {
log.Fatal(err)
}

sfiles := make([]*ShortFileInfo, 0)
for _, f := range files {
sfile := NewShortFileInfo(f)
sfiles = append(sfiles, sfile)
}
bytes, err := json.Marshal(sfiles)

if err != nil {
log.Fatal(err)
}
os.Stdout.Write(bytes)

os.Exit(0)
}
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package codetainer
package codetainer

import (
"fmt"
Expand Down
10 changes: 10 additions & 0 deletions http-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ func RouteApiV1CodetainerStop(ctx *Context) error {
return nil
}

type FileDesc struct {
name string
size int64
}

func parseFiles(output string) []FileDesc {
files := make([]FileDesc, 0)
return files
}

//
// List files in a codetainer
//
Expand Down

0 comments on commit 348e2c1

Please sign in to comment.