Added more information about files

This commit is contained in:
Diptanu Choudhury
2016-01-27 14:20:10 -08:00
parent d0fbdd8689
commit 12ffecf021
5 changed files with 31 additions and 18 deletions

View File

@@ -7,13 +7,16 @@ import (
"net/http"
"net/url"
"strconv"
"time"
)
// AllocFileInfo holds information about a file inside the AllocDir
type AllocFileInfo struct {
Name string
IsDir bool
Size int64
Name string
IsDir bool
Size int64
FileMode string
ModTime time.Time
}
// AllocFS is used to introspect an allocation directory on a Nomad client

View File

@@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/hashicorp/nomad/nomad/structs"
)
@@ -40,9 +41,11 @@ type AllocDir struct {
// AllocFileInfo holds information about a file inside the AllocDir
type AllocFileInfo struct {
Name string
IsDir bool
Size int64
Name string
IsDir bool
Size int64
FileMode string
ModTime time.Time
}
// AllocDirFS exposes file operations on the alloc dir
@@ -244,9 +247,11 @@ func (d *AllocDir) List(path string) ([]*AllocFileInfo, error) {
files := make([]*AllocFileInfo, len(finfos))
for idx, info := range finfos {
files[idx] = &AllocFileInfo{
Name: info.Name(),
IsDir: info.IsDir(),
Size: info.Size(),
Name: info.Name(),
IsDir: info.IsDir(),
Size: info.Size(),
FileMode: info.Mode().String(),
ModTime: info.ModTime(),
}
}
return files, err
@@ -261,9 +266,11 @@ func (d *AllocDir) Stat(path string) (*AllocFileInfo, error) {
}
return &AllocFileInfo{
Size: info.Size(),
Name: info.Name(),
IsDir: info.IsDir(),
Size: info.Size(),
Name: info.Name(),
IsDir: info.IsDir(),
FileMode: info.Mode().String(),
ModTime: info.ModTime(),
}, nil
}

View File

@@ -119,7 +119,7 @@ func (f *FSCatCommand) Run(args []string) int {
return 1
}
if file.IsDir {
f.Ui.Error("The file %q is a directory")
f.Ui.Error(fmt.Sprintf("The file %q is a directory", file.Name))
return 1
}

View File

@@ -120,15 +120,18 @@ func (f *FSListCommand) Run(args []string) int {
// Display the file information in a tabular format
out := make([]string, len(files)+1)
out[0] = "Name|Size"
out[0] = "Mode|Size|Modfied Time|Name"
for i, file := range files {
fn := file.Name
if file.IsDir {
fn = fmt.Sprintf("%s/", fn)
}
out[i+1] = fmt.Sprintf("%s|%d",
out[i+1] = fmt.Sprintf("%s|%d|%s|%s",
file.FileMode,
file.Size,
file.ModTime,
fn,
file.Size)
)
}
f.Ui.Output(formatList(out))

View File

@@ -119,13 +119,13 @@ func (f *FSStatCommand) Run(args []string) int {
// Display the file information
out := make([]string, 2)
out[0] = "Name|Size"
out[0] = "Mode|Size|Modified Time|Name"
if file != nil {
fn := file.Name
if file.IsDir {
fn = fmt.Sprintf("%s/", fn)
}
out[1] = fmt.Sprintf("%s|%d", fn, file.Size)
out[1] = fmt.Sprintf("%s|%d|%s|%s", file.FileMode, file.Size, file.ModTime, fn)
}
f.Ui.Output(formatList(out))
return 0