diff --git a/api/fs.go b/api/fs.go index 4e103a4ef..dc8440520 100644 --- a/api/fs.go +++ b/api/fs.go @@ -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 diff --git a/client/allocdir/alloc_dir.go b/client/allocdir/alloc_dir.go index c95b34165..010b68110 100644 --- a/client/allocdir/alloc_dir.go +++ b/client/allocdir/alloc_dir.go @@ -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 } diff --git a/command/fs_cat.go b/command/fs_cat.go index c684273cb..3f88e7529 100644 --- a/command/fs_cat.go +++ b/command/fs_cat.go @@ -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 } diff --git a/command/fs_list.go b/command/fs_list.go index 63c0a25ad..8f0084700 100644 --- a/command/fs_list.go +++ b/command/fs_list.go @@ -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)) diff --git a/command/fs_stat.go b/command/fs_stat.go index 19d580091..f0c0772a7 100644 --- a/command/fs_stat.go +++ b/command/fs_stat.go @@ -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