diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-28 19:12:35 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-28 19:12:35 +1000 |
commit | 7e1e97d050dd38b08e0131776bf130bae1fb1a4c (patch) | |
tree | ddf77f98afc9e005f7a739bef4ba1eb90448bc7b /pkg/commands/os.go | |
parent | 320ccdb22afc89e7bd77695eafb262281b323095 (diff) |
dont panic when catting directories
Diffstat (limited to 'pkg/commands/os.go')
-rw-r--r-- | pkg/commands/os.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/pkg/commands/os.go b/pkg/commands/os.go index 10f78c7c3..0fa92f724 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -59,6 +59,18 @@ func (c *OSCommand) RunCommand(command string) error { return err } +// FileType tells us if the file is a file, directory or other +func (c *OSCommand) FileType(path string) string { + fileInfo, err := os.Stat(path) + if err != nil { + return "other" + } + if fileInfo.IsDir() { + return "directory" + } + return "file" +} + // RunDirectCommand wrapper around direct commands func (c *OSCommand) RunDirectCommand(command string) (string, error) { c.Log.WithField("command", command).Info("RunDirectCommand") |