From f635033e3e953e74d67b76a520c9760786330af5 Mon Sep 17 00:00:00 2001 From: Niall Sheridan Date: Tue, 24 Jan 2017 23:43:28 +0000 Subject: Switch to scl, an extension of hcl --- vendor/github.com/homemade/scl/disk_file_system.go | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 vendor/github.com/homemade/scl/disk_file_system.go (limited to 'vendor/github.com/homemade/scl/disk_file_system.go') diff --git a/vendor/github.com/homemade/scl/disk_file_system.go b/vendor/github.com/homemade/scl/disk_file_system.go new file mode 100644 index 0000000..edd11f0 --- /dev/null +++ b/vendor/github.com/homemade/scl/disk_file_system.go @@ -0,0 +1,53 @@ +package scl + +import ( + "io" + "os" + "path/filepath" + "strings" + "time" +) + +type diskFileSystem struct { + basePath string +} + +/* +NewDiskSystem creates a filesystem that uses the local disk, at an optional +base path. The default base path is the current working directory. +*/ +func NewDiskSystem(basePath ...string) FileSystem { + + base := "" + + if len(basePath) > 0 { + base = basePath[0] + } + + return &diskFileSystem{base} +} + +func (d *diskFileSystem) path(path string) string { + return filepath.Join(d.basePath, strings.TrimPrefix(path, d.basePath)) +} + +func (d *diskFileSystem) Glob(pattern string) (out []string, err error) { + return filepath.Glob(d.path(pattern)) +} + +func (d *diskFileSystem) ReadCloser(path string) (data io.ReadCloser, lastModified time.Time, err error) { + + reader, err := os.Open(d.path(path)) + + if err != nil { + return nil, time.Time{}, err + } + + stat, err := reader.Stat() + + if err != nil { + return nil, time.Time{}, err + } + + return reader, stat.ModTime(), nil +} -- cgit v1.2.3