summaryrefslogtreecommitdiff
path: root/vendor/github.com/blang
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/blang')
-rw-r--r--vendor/github.com/blang/vfs/LICENSE22
-rw-r--r--vendor/github.com/blang/vfs/doc.go2
-rw-r--r--vendor/github.com/blang/vfs/dummy.go158
-rw-r--r--vendor/github.com/blang/vfs/filesystem.go139
-rw-r--r--vendor/github.com/blang/vfs/ioutil.go83
-rw-r--r--vendor/github.com/blang/vfs/memfs/buffer.go177
-rw-r--r--vendor/github.com/blang/vfs/memfs/doc.go2
-rw-r--r--vendor/github.com/blang/vfs/memfs/memfile.go89
-rw-r--r--vendor/github.com/blang/vfs/memfs/memfs.go380
-rw-r--r--vendor/github.com/blang/vfs/os.go54
-rw-r--r--vendor/github.com/blang/vfs/path.go29
-rw-r--r--vendor/github.com/blang/vfs/readonly.go78
12 files changed, 0 insertions, 1213 deletions
diff --git a/vendor/github.com/blang/vfs/LICENSE b/vendor/github.com/blang/vfs/LICENSE
deleted file mode 100644
index 4910a62b..00000000
--- a/vendor/github.com/blang/vfs/LICENSE
+++ /dev/null
@@ -1,22 +0,0 @@
-The MIT License
-
-Copyright (c) 2015 Benedikt Lang <github at blang.io>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
diff --git a/vendor/github.com/blang/vfs/doc.go b/vendor/github.com/blang/vfs/doc.go
deleted file mode 100644
index 7f60ebbd..00000000
--- a/vendor/github.com/blang/vfs/doc.go
+++ /dev/null
@@ -1,2 +0,0 @@
-// Package vfs defines an abstract file system and various implementations.
-package vfs
diff --git a/vendor/github.com/blang/vfs/dummy.go b/vendor/github.com/blang/vfs/dummy.go
deleted file mode 100644
index a0359cde..00000000
--- a/vendor/github.com/blang/vfs/dummy.go
+++ /dev/null
@@ -1,158 +0,0 @@
-package vfs
-
-import (
- "os"
- "time"
-)
-
-// Dummy creates a new dummy filesystem which returns the given error on every operation.
-func Dummy(err error) *DummyFS {
- return &DummyFS{err}
-}
-
-// DummyFS is dummy filesystem which returns an error on every operation.
-// It can be used to mock a full filesystem for testing or fs creation.
-type DummyFS struct {
- err error
-}
-
-// PathSeparator returns the path separator
-func (fs DummyFS) PathSeparator() uint8 {
- return '/'
-}
-
-// OpenFile returns dummy error
-func (fs DummyFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
- return nil, fs.err
-}
-
-// Remove returns dummy error
-func (fs DummyFS) Remove(name string) error {
- return fs.err
-}
-
-// Rename returns dummy error
-func (fs DummyFS) Rename(oldpath, newpath string) error {
- return fs.err
-}
-
-// Mkdir returns dummy error
-func (fs DummyFS) Mkdir(name string, perm os.FileMode) error {
- return fs.err
-}
-
-// Stat returns dummy error
-func (fs DummyFS) Stat(name string) (os.FileInfo, error) {
- return nil, fs.err
-}
-
-// Lstat returns dummy error
-func (fs DummyFS) Lstat(name string) (os.FileInfo, error) {
- return nil, fs.err
-}
-
-// ReadDir returns dummy error
-func (fs DummyFS) ReadDir(path string) ([]os.FileInfo, error) {
- return nil, fs.err
-}
-
-// DummyFile mocks a File returning an error on every operation
-// To create a DummyFS returning a dummyFile instead of an error
-// you can your own DummyFS:
-//
-// type writeDummyFS struct {
-// Filesystem
-// }
-//
-// func (fs writeDummyFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
-// return DummyFile(dummyError), nil
-// }
-func DummyFile(err error) *DumFile {
- return &DumFile{err}
-}
-
-// DumFile represents a dummy File
-type DumFile struct {
- err error
-}
-
-// Name returns "dummy"
-func (f DumFile) Name() string {
- return "dummy"
-}
-
-// Sync returns dummy error
-func (f DumFile) Sync() error {
- return f.err
-}
-
-// Truncate returns dummy error
-func (f DumFile) Truncate(size int64) error {
- return f.err
-}
-
-// Close returns dummy error
-func (f DumFile) Close() error {
- return f.err
-}
-
-// Write returns dummy error
-func (f DumFile) Write(p []byte) (n int, err error) {
- return 0, f.err
-}
-
-// Read returns dummy error
-func (f DumFile) Read(p []byte) (n int, err error) {
- return 0, f.err
-}
-
-// ReadAt returns dummy error
-func (f DumFile) ReadAt(p []byte, off int64) (n int, err error) {
- return 0, f.err
-}
-
-// Seek returns dummy error
-func (f DumFile) Seek(offset int64, whence int) (int64, error) {
- return 0, f.err
-}
-
-// DumFileInfo mocks a os.FileInfo returning default values on every operation
-// Struct fields can be set.
-type DumFileInfo struct {
- IName string
- ISize int64
- IMode os.FileMode
- IModTime time.Time
- IDir bool
- ISys interface{}
-}
-
-// Name returns the field IName
-func (fi DumFileInfo) Name() string {
- return fi.IName
-}
-
-// Size returns the field ISize
-func (fi DumFileInfo) Size() int64 {
- return fi.ISize
-}
-
-// Mode returns the field IMode
-func (fi DumFileInfo) Mode() os.FileMode {
- return fi.IMode
-}
-
-// ModTime returns the field IModTime
-func (fi DumFileInfo) ModTime() time.Time {
- return fi.IModTime
-}
-
-// IsDir returns the field IDir
-func (fi DumFileInfo) IsDir() bool {
- return fi.IDir
-}
-
-// Sys returns the field ISys
-func (fi DumFileInfo) Sys() interface{} {
- return fi.ISys
-}
diff --git a/vendor/github.com/blang/vfs/filesystem.go b/vendor/github.com/blang/vfs/filesystem.go
deleted file mode 100644
index 7271206d..00000000
--- a/vendor/github.com/blang/vfs/filesystem.go
+++ /dev/null
@@ -1,139 +0,0 @@
-package vfs
-
-import (
- "errors"
- "io"
- "os"
- "strings"
-)
-
-var (
- // ErrIsDirectory is returned if a file is a directory
- ErrIsDirectory = errors.New("Is directory")
- // ErrNotDirectory is returned if a file is not a directory
- ErrNotDirectory = errors.New("Is not a directory")
-)
-
-// Filesystem represents an abstract filesystem
-type Filesystem interface {
- PathSeparator() uint8
- OpenFile(name string, flag int, perm os.FileMode) (File, error)
- Remove(name string) error
- // RemoveAll(path string) error
- Rename(oldpath, newpath string) error
- Mkdir(name string, perm os.FileMode) error
- // Symlink(oldname, newname string) error
- // TempDir() string
- // Chmod(name string, mode FileMode) error
- // Chown(name string, uid, gid int) error
- Stat(name string) (os.FileInfo, error)
- Lstat(name string) (os.FileInfo, error)
- ReadDir(path string) ([]os.FileInfo, error)
-}
-
-// File represents a File with common operations.
-// It differs from os.File so e.g. Stat() needs to be called from the Filesystem instead.
-// osfile.Stat() -> filesystem.Stat(file.Name())
-type File interface {
- Name() string
- Sync() error
- // Truncate shrinks or extends the size of the File to the specified size.
- Truncate(int64) error
- io.Reader
- io.ReaderAt
- io.Writer
- io.Seeker
- io.Closer
-}
-
-// Create creates the named file mode 0666 (before umask) on the given Filesystem,
-// truncating it if it already exists.
-// The associated file descriptor has mode os.O_RDWR.
-// If there is an error, it will be of type *os.PathError.
-func Create(fs Filesystem, name string) (File, error) {
- return fs.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
-}
-
-// Open opens the named file on the given Filesystem for reading.
-// If successful, methods on the returned file can be used for reading.
-// The associated file descriptor has mode os.O_RDONLY.
-// If there is an error, it will be of type *PathError.
-func Open(fs Filesystem, name string) (File, error) {
- return fs.OpenFile(name, os.O_RDONLY, 0)
-}
-
-// MkdirAll creates a directory named path on the given Filesystem,
-// along with any necessary parents, and returns nil,
-// or else returns an error.
-// The permission bits perm are used for all
-// directories that MkdirAll creates.
-// If path is already a directory, MkdirAll does nothing
-// and returns nil.
-func MkdirAll(fs Filesystem, path string, perm os.FileMode) error {
- if dir, err := fs.Stat(path); err == nil {
- if dir.IsDir() {
- return nil
- }
- return &os.PathError{"mkdir", path, ErrNotDirectory}
- }
-
- parts := SplitPath(path, string(fs.PathSeparator()))
- if len(parts) > 1 {
- // Create parent
- err := MkdirAll(fs, strings.Join(parts[0:len(parts)-1], string(fs.PathSeparator())), perm)
- if err != nil {
- return err
- }
- }
-
- // Parent now exists; invoke Mkdir and use its result.
- err := fs.Mkdir(path, perm)
- if err != nil {
- // Handle arguments like "foo/." by
- // double-checking that directory doesn't exist.
- dir, err1 := fs.Lstat(path)
- if err1 == nil && dir.IsDir() {
- return nil
- }
- return err
- }
- return nil
-}
-
-// RemoveAll removes path and any children it contains.
-// It removes everything it can but returns the first error
-// it encounters. If the path does not exist, RemoveAll
-// returns nil.
-func RemoveAll(fs Filesystem, path string) error {
- if err := fs.Remove(path); err == nil || os.IsNotExist(err) {
- return nil
- }
-
- // We could not delete it, so might be a directory
- fis, err := fs.ReadDir(path)
- if err != nil {
- if os.IsNotExist(err) {
- return nil
- }
- return err
- }
-
- // Remove contents & return first error.
- err = nil
- for _, fi := range fis {
- err1 := RemoveAll(fs, path+string(fs.PathSeparator())+fi.Name())
- if err == nil {
- err = err1
- }
- }
-
- // Remove directory itself.
- err1 := fs.Remove(path)
- if err1 == nil || os.IsNotExist(err1) {
- return nil
- }
- if err == nil {
- err = err1
- }
- return err
-}
diff --git a/vendor/github.com/blang/vfs/ioutil.go b/vendor/github.com/blang/vfs/ioutil.go
deleted file mode 100644
index 04c69824..00000000
--- a/vendor/github.com/blang/vfs/ioutil.go
+++ /dev/null
@@ -1,83 +0,0 @@
-package vfs
-
-import (
- "bytes"
- "io"
- "os"
-)
-
-// WriteFile writes data to a file named by filename on the given Filesystem. If
-// the file does not exist, WriteFile creates it with permissions perm;
-// otherwise WriteFile truncates it before writing.
-//
-// This is a port of the stdlib ioutil.WriteFile function.
-func WriteFile(fs Filesystem, filename string, data []byte, perm os.FileMode) error {
- f, err := fs.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
- if err != nil {
- return err
- }
- n, err := f.Write(data)
- if err == nil && n < len(data) {
- err = io.ErrShortWrite
- }
- if err1 := f.Close(); err == nil {
- err = err1
- }
- return err
-}
-
-// ReadFile reads the file named by filename and returns the contents. A
-// successful call returns err == nil, not err == EOF. Because ReadFile reads
-// the whole file, it does not treat an EOF from Read as an error to be
-// reported.
-//
-// This is a port of the stdlib ioutil.ReadFile function.
-func ReadFile(fs Filesystem, filename string) ([]byte, error) {
- f, err := fs.OpenFile(filename, os.O_RDONLY, 0)
- if err != nil {
- return nil, err
- }
- defer f.Close()
-
- // It's a good but not certain bet that FileInfo will tell us exactly how
- // much to read, so let's try it but be prepared for the answer to be wrong.
- var n int64
- if fi, err := fs.Stat(filename); err == nil {
- if size := fi.Size(); size < 1e9 {
- n = size
- }
- }
-
- // As initial capacity for readAll, use n + a little extra in case Size is
- // zero, and to avoid another allocation after Read has filled the buffer.
- // The readAll call will read into its allocated internal buffer cheaply. If
- // the size was wrong, we'll either waste some space off the end or
- // reallocate as needed, but in the overwhelmingly common case we'll get it
- // just right.
- return readAll(f, n+bytes.MinRead)
-}
-
-// readAll reads from r until an error or EOF and returns the data it read from
-// the internal buffer allocated with a specified capacity.
-//
-// This is a paste of the stdlib ioutil.readAll function.
-func readAll(r io.Reader, capacity int64) (b []byte, err error) {
- buf := bytes.NewBuffer(make([]byte, 0, capacity))
-
- // If the buffer overflows, we will get bytes.ErrTooLarge.
- // Return that as an error. Any other panic remains.
- defer func() {
- e := recover()
- if e == nil {
- return
- }
- if panicErr, ok := e.(error); ok && panicErr == bytes.ErrTooLarge {
- err = panicErr
- } else {
- panic(e)
- }
- }()
-
- _, err = buf.ReadFrom(r)
- return buf.Bytes(), err
-}
diff --git a/vendor/github.com/blang/vfs/memfs/buffer.go b/vendor/github.com/blang/vfs/memfs/buffer.go
deleted file mode 100644
index a0a78c5b..00000000
--- a/vendor/github.com/blang/vfs/memfs/buffer.go
+++ /dev/null
@@ -1,177 +0,0 @@
-package memfs
-
-import (
- "errors"
- "io"
- "os"
-)
-
-// Buffer is a usable block of data similar to a file
-type Buffer interface {
- io.Reader
- io.ReaderAt
- io.Writer
- io.Seeker
- io.Closer
- // Truncate shrinks or extends the size of the Buffer to the specified size.
- Truncate(int64) error
-}
-
-// MinBufferSize is the minimal initial allocated buffer size
-const MinBufferSize = 512
-
-// ErrTooLarge is thrown if it was not possible to enough memory
-var ErrTooLarge = errors.New("Volume too large")
-
-// Buf is a Buffer working on a slice of bytes.
-type Buf struct {
- buf *[]byte
- ptr int64
-}
-
-// NewBuffer creates a new data volume based on a buffer
-func NewBuffer(buf *[]byte) *Buf {
- return &Buf{
- buf: buf,
- }
-}
-
-// Seek sets the offset for the next Read or Write on the buffer to offset,
-// interpreted according to whence:
-// 0 (os.SEEK_SET) means relative to the origin of the file
-// 1 (os.SEEK_CUR) means relative to the current offset
-// 2 (os.SEEK_END) means relative to the end of the file
-// It returns the new offset and an error, if any.
-func (v *Buf) Seek(offset int64, whence int) (int64, error) {
- var abs int64
- switch whence {
- case os.SEEK_SET: // Relative to the origin of the file
- abs = offset
- case os.SEEK_CUR: // Relative to the current offset
- abs = int64(v.ptr) + offset
- case os.SEEK_END: // Relative to the end
- abs = int64(len(*v.buf)) + offset
- default:
- return 0, errors.New("Seek: invalid whence")
- }
- if abs < 0 {
- return 0, errors.New("Seek: negative position")
- }
- if abs > int64(len(*v.buf)) {
- return 0, errors.New("Seek: too far")
- }
- v.ptr = abs
- return abs, nil
-}
-
-// Write writes len(p) byte to the Buffer.
-// It returns the number of bytes written and an error if any.
-// Write returns non-nil error when n!=len(p).
-func (v *Buf) Write(p []byte) (int, error) {
- l := len(p)
- writeEnd := int(v.ptr) + l - len(*v.buf)
- if writeEnd > 0 {
- err := v.grow(writeEnd)
- if err != nil {
- return 0, err
- }
- }
- copy((*v.buf)[v.ptr:], p)
- v.ptr += int64(l)
- return l, nil
-}
-
-// Close the buffer. Currently no effect.
-func (v *Buf) Close() error {
- return nil
-}
-
-// Read reads len(p) byte from the Buffer starting at the current offset.
-// It returns the number of bytes read and an error if any.
-// Returns io.EOF error if pointer is at the end of the Buffer.
-func (v *Buf) Read(p []byte) (n int, err error) {
- if len(p) == 0 {
- return 0, nil
- }
- if v.ptr >= int64(len(*v.buf)) {
- return 0, io.EOF
- }
-
- n = copy(p, (*v.buf)[v.ptr:])
- v.ptr += int64(n)
- return
-}
-
-// ReadAt reads len(b) bytes from the Buffer starting at byte offset off.
-// It returns the number of bytes read and the error, if any.
-// ReadAt always returns a non-nil error when n < len(b).
-// At end of file, that error is io.EOF.
-func (v *Buf) ReadAt(p []byte, off int64) (n int, err error) {
- if len(p) == 0 {
- return 0, nil
- }
- if off >= int64(len(*v.buf)) {
- return 0, io.EOF
- }
-
- n = copy(p, (*v.buf)[off:])
- if n < len(p) {
- err = io.EOF
- }
- return
-}
-
-// Truncate truncates the Buffer to a given size.
-// It returns an error if the given size is negative.
-// If the Buffer is larger than the specified size, the extra data is lost.
-// If the Buffer is smaller, it is extended and the extended part (hole)
-// reads as zero bytes.
-func (v *Buf) Truncate(size int64) (err error) {
- if size < 0 {
- return errors.New("Truncate: size must be non-negative")
- }
- if bufSize := int64(len(*v.buf)); size == bufSize {
- return nil
- } else if size < bufSize {
- *v.buf = (*v.buf)[:size]
- } else /* size > bufSize */ {
- growSize := int(size - bufSize)
- if err = v.grow(growSize); err != nil {
- return err
- }
- }
- return nil
-}
-
-func (v *Buf) grow(n int) error {
- m := len(*v.buf)
- if (m + n) > cap(*v.buf) {
- size := 2*cap(*v.buf) + MinBufferSize
- if size < m+n {
- size = m + n + MinBufferSize
- }
- buf, err := makeSlice(size)
- if err != nil {
- return err
- }
- copy(buf, *v.buf)
- *v.buf = buf
- }
- *v.buf = (*v.buf)[0 : m+n]
- return nil
-}
-
-// makeSlice allocates a slice of size n. If the allocation fails, it panics
-// with ErrTooLarge.
-func makeSlice(n int) (b []byte, err error) {
- // If the make fails, give a known error.
- defer func() {
- if recover() != nil {
- b = nil
- err = ErrTooLarge
- return
- }
- }()
- b = make([]byte, n)
- return
-}
diff --git a/vendor/github.com/blang/vfs/memfs/doc.go b/vendor/github.com/blang/vfs/memfs/doc.go
deleted file mode 100644
index 2cf9fce0..00000000
--- a/vendor/github.com/blang/vfs/memfs/doc.go
+++ /dev/null
@@ -1,2 +0,0 @@
-// Package memfs defines an in-memory filesystem
-package memfs
diff --git a/vendor/github.com/blang/vfs/memfs/memfile.go b/vendor/github.com/blang/vfs/memfs/memfile.go
deleted file mode 100644
index a44d27c0..00000000
--- a/vendor/github.com/blang/vfs/memfs/memfile.go
+++ /dev/null
@@ -1,89 +0,0 @@
-package memfs
-
-import (
- "sync"
-)
-
-// MemFile represents a file backed by a Buffer which is secured from concurrent access.
-type MemFile struct {
- Buffer
- mutex *sync.RWMutex
- name string
-}
-
-// NewMemFile creates a Buffer which byte slice is safe from concurrent access,
-// the file itself is not thread-safe.
-//
-// This means multiple files can work safely on the same byte slice,
-// but multiple go routines working on the same file may corrupt the internal pointer structure.
-func NewMemFile(name string, rwMutex *sync.RWMutex, buf *[]byte) *MemFile {
- return &MemFile{
- Buffer: NewBuffer(buf),
- mutex: rwMutex,
- name: name,
- }
-}
-
-// Name of the file
-func (b MemFile) Name() string {
- return b.name
-}
-
-// Sync has no effect
-func (b MemFile) Sync() error {
- return nil
-}
-
-// Truncate changes the size of the file
-func (b MemFile) Truncate(size int64) (err error) {
- b.mutex.Lock()
- err = b.Buffer.Truncate(size)
- b.mutex.Unlock()
- return
-}
-
-// Read reads len(p) byte from the underlying buffer starting at the current offset.
-// It returns the number of bytes read and an error if any.
-// Returns io.EOF error if pointer is at the end of the Buffer.
-// See Buf.Read()
-func (b *MemFile) Read(p []byte) (n int, err error) {
- b.mutex.RLock()
- n, err = b.Buffer.Read(p)
- b.mutex.RUnlock()
- return
-}
-
-// ReadAt reads len(b) bytes from the Buffer starting at byte offset off.
-// It returns the number of bytes read and the error, if any.
-// ReadAt always returns a non-nil error when n < len(b).
-// At end of file, that error is io.EOF.
-// See Buf.ReadAt()
-func (b *MemFile) ReadAt(p []byte, off int64) (n int, err error) {
- b.mutex.RLock()
- n, err = b.Buffer.ReadAt(p, off)
- b.mutex.RUnlock()
- return
-}
-
-// Write writes len(p) byte to the Buffer.
-// It returns the number of bytes written and an error if any.
-// Write returns non-nil error when n!=len(p).
-func (b *MemFile) Write(p []byte) (n int, err error) {
- b.mutex.Lock()
- n, err = b.Buffer.Write(p)
- b.mutex.Unlock()
- return
-}
-
-// Seek sets the offset for the next Read or Write on the buffer to offset,
-// interpreted according to whence:
-// 0 (os.SEEK_SET) means relative to the origin of the file
-// 1 (os.SEEK_CUR) means relative to the current offset
-// 2 (os.SEEK_END) means relative to the end of the file
-// It returns the new offset and an error, if any.
-func (b *MemFile) Seek(offset int64, whence int) (n int64, err error) {
- b.mutex.RLock()
- n, err = b.Buffer.Seek(offset, whence)
- b.mutex.RUnlock()
- return
-}
diff --git a/vendor/github.com/blang/vfs/memfs/memfs.go b/vendor/github.com/blang/vfs/memfs/memfs.go
deleted file mode 100644
index 6be44bd1..00000000
--- a/vendor/github.com/blang/vfs/memfs/memfs.go
+++ /dev/null
@@ -1,380 +0,0 @@
-package memfs
-
-import (
- "errors"
- "fmt"
- "os"
- filepath "path"
- "sort"
- "sync"
- "time"
-
- "github.com/blang/vfs"
-)
-
-var (
- // ErrReadOnly is returned if the file is read-only and write operations are disabled.
- ErrReadOnly = errors.New("File is read-only")
- // ErrWriteOnly is returned if the file is write-only and read operations are disabled.
- ErrWriteOnly = errors.New("File is write-only")
- // ErrIsDirectory is returned if the file under operation is not a regular file but a directory.
- ErrIsDirectory = errors.New("Is directory")
-)
-
-// PathSeparator used to separate path segments
-const PathSeparator = "/"
-
-// MemFS is a in-memory filesystem
-type MemFS struct {
- root *fileInfo
- wd *fileInfo
- lock *sync.RWMutex
-}
-
-// Create a new MemFS filesystem which entirely resides in memory
-func Create() *MemFS {
- root := &fileInfo{
- name: "/",
- dir: true,
- }
- return &MemFS{
- root: root,
- wd: root,
- lock: &sync.RWMutex{},
- }
-}
-
-type fileInfo struct {
- name string
- dir bool
- mode os.FileMode
- parent *fileInfo
- size int64
- modTime time.Time
- fs vfs.Filesystem
- childs map[string]*fileInfo
- buf *[]byte
- mutex *sync.RWMutex
-}
-
-func (fi fileInfo) Sys() interface{} {
- return fi.fs
-}
-
-func (fi fileInfo) Size() int64 {
- if fi.dir {
- return 0
- }
- fi.mutex.RLock()
- l := len(*(fi.buf))
- fi.mutex.RUnlock()
- return int64(l)
-}
-
-func (fi fileInfo) IsDir() bool {
- return fi.dir
-}
-
-// ModTime returns the modification time.
-// Modification time is updated on:
-// - Creation
-// - Rename
-// - Open (except with O_RDONLY)
-func (fi fileInfo) ModTime() time.Time {
- return fi.modTime
-}
-
-func (fi fileInfo) Mode() os.FileMode {
- return fi.mode
-}
-
-func (fi fileInfo) Name() string {
- return fi.name
-}
-
-func (fi fileInfo) AbsPath() string {
- if fi.parent != nil {
- return filepath.Join(fi.parent.AbsPath(), fi.name)
- }
- return "/"
-}
-
-// PathSeparator returns the path separator
-func (fs *MemFS) PathSeparator() uint8 {
- return '/'
-}
-
-// Mkdir creates a new directory with given permissions
-func (fs *MemFS) Mkdir(name string, perm os.FileMode) error {
- fs.lock.Lock()
- defer fs.lock.Unlock()
- name = filepath.Clean(name)
- base := filepath.Base(name)
- parent, fi, err := fs.fileInfo(name)
- if err != nil {
- return &os.PathError{"mkdir", name, err}
- }
- if fi != nil {
- return &os.PathError{"mkdir", name, fmt.Errorf("Directory %q already exists", name)}
- }
-
- fi = &fileInfo{
- name: base,
- dir: true,
- mode: perm,
- parent: parent,
- modTime: time.Now(),
- fs: fs,
- }
- parent.childs[base] = fi
- return nil
-}
-
-// byName implements sort.Interface
-type byName []os.FileInfo
-
-// Len returns the length of the slice
-func (f byName) Len() int { return len(f) }
-
-// Less sorts slice by Name
-func (f byName) Less(i, j int) bool { return f[i].Name() < f[j].Name() }
-
-// Swap two elements by index
-func (f byName) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
-
-// ReadDir reads the directory named by path and returns a list of sorted directory entries.
-func (fs *MemFS) ReadDir(path string) ([]os.FileInfo, error) {
- fs.lock.RLock()
- defer fs.lock.RUnlock()
-
- path = filepath.Clean(path)
- _, fi, err := fs.fileInfo(path)
- if err != nil {
- return nil, &os.PathError{"readdir", path, err}
- }
- if fi == nil || !fi.dir {
- return nil, &os.PathError{"readdir", path, vfs.ErrNotDirectory}
- }
-
- fis := make([]os.FileInfo, 0, len(fi.childs))
- for _, e := range fi.childs {
- fis = append(fis, e)
- }
- sort.Sort(byName(fis))
- return fis, nil
-}
-
-func (fs *MemFS) fileInfo(path string) (parent *fileInfo, node *fileInfo, err error) {
- path = filepath.Clean(path)
- segments := vfs.SplitPath(path, PathSeparator)
-
- // Shortcut for working directory and root
- if len(segments) == 1 {
- if segments[0] == "" {
- return nil, fs.root, nil
- } else if segments[0] == "." {
- return fs.wd.parent, fs.wd, nil
- }
- }
-
- // Determine root to traverse
- parent = fs.root
- if segments[0] == "." {
- parent = fs.wd
- }
- segments = segments[1:]
-
- // Further directories
- if len(segments) > 1 {
- for _, seg := range segments[:len(segments)-1] {
-
- if parent.childs == nil {
- return nil, nil, os.ErrNotExist
- }
- if entry, ok := parent.childs[seg]; ok && entry.dir {
- parent = entry
- } else {
- return nil, nil, os.ErrNotExist
- }
- }
- }
-
- lastSeg := segments[len(segments)-1]
- if parent.childs != nil {
- if node, ok := parent.childs[lastSeg]; ok {
- return parent, node, nil
- }
- } else {
- parent.childs = make(map[string]*fileInfo)
- }
-
- return parent, nil, nil
-}
-
-func hasFlag(flag int, flags int) bool {
- return flags&flag == flag
-}
-
-// OpenFile opens a file handle with a specified flag (os.O_RDONLY etc.) and perm (e.g. 0666).
-// If success the returned File can be used for I/O. Otherwise an error is returned, which
-// is a *os.PathError and can be extracted for further information.
-func (fs *MemFS) OpenFile(name string, flag int, perm os.FileMode) (vfs.File, error) {
- fs.lock.Lock()
- defer fs.lock.Unlock()
-
- name = filepath.Clean(name)
- base := filepath.Base(name)
- fiParent, fiNode, err := fs.fileInfo(name)
- if err != nil {
- return nil, &os.PathError{"open", name, err}
- }
-
- if fiNode == nil {
- if !hasFlag(os.O_CREATE, flag) {
- return nil, &os.PathError{"open", name, os.ErrNotExist}
- }
- fiNode = &fileInfo{
- name: base,
- dir: false,
- mode: perm,
- parent: fiParent,
- modTime: time.Now(),
- fs: fs,
- }
- fiParent.childs[base] = fiNode
- } else { // file exists
- if hasFlag(os.O_CREATE|os.O_EXCL, flag) {
- return nil, &os.PathError{"open", name, os.ErrExist}
- }
- if fiNode.dir {
- return nil, &os.PathError{"open", name, ErrIsDirectory}
- }
- }
-
- if !hasFlag(os.O_RDONLY, flag) {
- fiNode.modTime = time.Now()
- }
- return fiNode.file(flag)
-}
-
-func (fi *fileInfo) file(flag int) (vfs.File, error) {
- if fi.buf == nil || hasFlag(os.O_TRUNC, flag) {
- buf := make([]byte, 0, MinBufferSize)
- fi.buf = &buf
- fi.mutex = &sync.RWMutex{}
- }
- var f vfs.File = NewMemFile(fi.AbsPath(), fi.mutex, fi.buf)
- if hasFlag(os.O_APPEND, flag) {
- f.Seek(0, os.SEEK_END)
- }
- if hasFlag(os.O_RDWR, flag) {
- return f, nil
- } else if hasFlag(os.O_WRONLY, flag) {
- f = &woFile{f}
- } else {
- f = &roFile{f}
- }
-
- return f, nil
-}
-
-// roFile wraps the given file and disables Write(..) operation.
-type roFile struct {
- vfs.File
-}
-
-// Write is disabled and returns ErrorReadOnly
-func (f *roFile) Write(p []byte) (n int, err error) {
- return 0, ErrReadOnly
-}
-
-// woFile wraps the given file and disables Read(..) operation.
-type woFile struct {
- vfs.File
-}
-
-// Read is disabled and returns ErrorWroteOnly
-func (f *woFile) Read(p []byte) (n int, err error) {
- return 0, ErrWriteOnly
-}
-
-// Remove removes the named file or directory.
-// If there is an error, it will be of type *PathError.
-func (fs *MemFS) Remove(name string) error {
- fs.lock.Lock()
- defer fs.lock.Unlock()
-
- name = filepath.Clean(name)
- fiParent, fiNode, err := fs.fileInfo(name)
- if err != nil {
- return &os.PathError{"remove", name, err}
- }
- if fiNode == nil {
- return &os.PathError{"remove", name, os.ErrNotExist}
- }
-
- delete(fiParent.childs, fiNode.name)
- return nil
-}
-
-// Rename renames (moves) a file.
-// Handles to the oldpath persist but might return oldpath if Name() is called.
-func (fs *MemFS) Rename(oldpath, newpath string) error {
- fs.lock.Lock()
- defer fs.lock.Unlock()
-
- // OldPath
- oldpath = filepath.Clean(oldpath)
- fiOldParent, fiOld, err := fs.fileInfo(oldpath)
- if err != nil {
- return &os.PathError{"rename", oldpath, err}
- }
- if fiOld == nil {
- return &os.PathError{"rename", oldpath, os.ErrNotExist}
- }
-
- newpath = filepath.Clean(newpath)
- fiNewParent, fiNew, err := fs.fileInfo(newpath)
- if err != nil {
- return &os.PathError{"rename", newpath, err}
- }
-
- if fiNew != nil {
- return &os.PathError{"rename", newpath, os.ErrExist}
- }
-
- newBase := filepath.Base(newpath)
-
- // Relink
- delete(fiOldParent.childs, fiOld.name)
- fiOld.parent = fiNewParent
- fiOld.name = newBase
- fiOld.modTime = time.Now()
- fiNewParent.childs[fiOld.name] = fiOld
- return nil
-}
-
-// Stat returns the FileInfo structure describing the named file.
-// If there is an error, it will be of type *PathError.
-func (fs *MemFS) Stat(name string) (os.FileInfo, error) {
- fs.lock.RLock()
- defer fs.lock.RUnlock()
-
- name = filepath.Clean(name)
- // dir, base := filepath.Split(name)
- _, fi, err := fs.fileInfo(name)
- if err != nil {
- return nil, &os.PathError{"stat", name, err}
- }
- if fi == nil {
- return nil, &os.PathError{"stat", name, os.ErrNotExist}
- }
- return fi, nil
-}
-
-// Lstat returns a FileInfo describing the named file.
-// MemFS does not support symbolic links.
-// Alias for fs.Stat(name)
-func (fs *MemFS) Lstat(name string) (os.FileInfo, error) {
- return fs.Stat(name)
-}
diff --git a/vendor/github.com/blang/vfs/os.go b/vendor/github.com/blang/vfs/os.go
deleted file mode 100644
index feb33bb8..00000000
--- a/vendor/github.com/blang/vfs/os.go
+++ /dev/null
@@ -1,54 +0,0 @@
-package vfs
-
-import (
- "io/ioutil"
- "os"
-)
-
-// OsFS represents a filesystem backed by the filesystem of the underlying OS.
-type OsFS struct{}
-
-// OS returns a filesystem backed by the filesystem of the os. It wraps os.* stdlib operations.
-func OS() *OsFS {
- return &OsFS{}
-}
-
-// PathSeparator returns the path separator
-func (fs OsFS) PathSeparator() uint8 {
- return os.PathSeparator
-}
-
-// OpenFile wraps os.OpenFile
-func (fs OsFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
- return os.OpenFile(name, flag, perm)
-}
-
-// Remove wraps os.Remove
-func (fs OsFS) Remove(name string) error {
- return os.Remove(name)
-}
-
-// Mkdir wraps os.Mkdir
-func (fs OsFS) Mkdir(name string, perm os.FileMode) error {
- return os.Mkdir(name, perm)
-}
-
-// Rename wraps os.Rename
-func (fs OsFS) Rename(oldpath, newpath string) error {
- return os.Rename(oldpath, newpath)
-}
-
-// Stat wraps os.Stat
-func (fs OsFS) Stat(name string) (os.FileInfo, error) {
- return os.Stat(name)
-}
-
-// Lstat wraps os.Lstat
-func (fs OsFS) Lstat(name string) (os.FileInfo, error) {
- return os.Lstat(name)
-}
-
-// ReadDir wraps ioutil.ReadDir
-func (fs OsFS) ReadDir(path string) ([]os.FileInfo, error) {
- return ioutil.ReadDir(path)
-}
diff --git a/vendor/github.com/blang/vfs/path.go b/vendor/github.com/blang/vfs/path.go
deleted file mode 100644
index 722e2497..00000000
--- a/vendor/github.com/blang/vfs/path.go
+++ /dev/null
@@ -1,29 +0,0 @@
-package vfs
-
-import (
- "strings"
-)
-
-// SplitPath splits the given path in segments:
-// "/" -> []string{""}
-// "./file" -> []string{".", "file"}
-// "file" -> []string{".", "file"}
-// "/usr/src/linux/" -> []string{"", "usr", "src", "linux"}
-// The returned slice of path segments consists of one more more segments.
-func SplitPath(path string, sep string) []string {
- path = strings.TrimSpace(path)
- path = strings.TrimSuffix(path, sep)
- if path == "" { // was "/"
- return []string{""}
- }
- if path == "." {
- return []string{"."}
- }
-
- if len(path) > 0 && !strings.HasPrefix(path, sep) && !strings.HasPrefix(path, "."+sep) {
- path = "./" + path
- }
- parts := strings.Split(path, sep)
-
- return parts
-}
diff --git a/vendor/github.com/blang/vfs/readonly.go b/vendor/github.com/blang/vfs/readonly.go
deleted file mode 100644
index 406cd84f..00000000
--- a/vendor/github.com/blang/vfs/readonly.go
+++ /dev/null
@@ -1,78 +0,0 @@
-package vfs
-
-import (
- "errors"
- "os"
-)
-
-// ReadOnly creates a readonly wrapper around the given filesystem.
-// It disables the following operations:
-//
-// - Create
-// - Remove
-// - Rename
-// - Mkdir
-//
-// And disables OpenFile flags: os.O_CREATE, os.O_APPEND, os.O_WRONLY
-//
-// OpenFile returns a File with disabled Write() method otherwise.
-func ReadOnly(fs Filesystem) *RoFS {
- return &RoFS{Filesystem: fs}
-}
-
-// RoFS represents a read-only filesystem and
-// works as a wrapper around existing filesystems.
-type RoFS struct {
- Filesystem
-}
-
-// ErrorReadOnly is returned on every disabled operation.
-var ErrReadOnly = errors.New("Filesystem is read-only")
-
-// Remove is disabled and returns ErrorReadOnly
-func (fs RoFS) Remove(name string) error {
- return ErrReadOnly
-}
-
-// Rename is disabled and returns ErrorReadOnly
-func (fs RoFS) Rename(oldpath, newpath string) error {
- return ErrReadOnly
-}
-
-// Mkdir is disabled and returns ErrorReadOnly
-func (fs RoFS) Mkdir(name string, perm os.FileMode) error {
- return ErrReadOnly
-}
-
-// OpenFile returns ErrorReadOnly if flag contains os.O_CREATE, os.O_APPEND, os.O_WRONLY.
-// Otherwise it returns a read-only File with disabled Write(..) operation.
-func (fs RoFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
- if flag&os.O_CREATE == os.O_CREATE {
- return nil, ErrReadOnly
- }
- if flag&os.O_APPEND == os.O_APPEND {
- return nil, ErrReadOnly
- }
- if flag&os.O_WRONLY == os.O_WRONLY {
- return nil, ErrReadOnly
- }
- f, err := fs.Filesystem.OpenFile(name, flag, perm)
- if err != nil {
- return ReadOnlyFile(f), err
- }
- return ReadOnlyFile(f), nil
-}
-
-// ReadOnlyFile wraps the given file and disables Write(..) operation.
-func ReadOnlyFile(f File) File {
- return &roFile{f}
-}
-
-type roFile struct {
- File
-}
-
-// Write is disabled and returns ErrorReadOnly
-func (f roFile) Write(p []byte) (n int, err error) {
- return 0, ErrReadOnly
-}