diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-06 01:56:16 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-06 01:56:16 +0200 |
commit | 0b7aa259fe3da2236952843fe46db62bdee395eb (patch) | |
tree | ba81a9400695d330ed7e5c8665b84360a6689686 /utils/fs/fs.go | |
parent | 19da30a8ff233285a79df9f1da8b0d88d99eb626 (diff) | |
download | go-git-0b7aa259fe3da2236952843fe46db62bdee395eb.tar.gz |
utils: fs new implementation
Diffstat (limited to 'utils/fs/fs.go')
-rw-r--r-- | utils/fs/fs.go | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/utils/fs/fs.go b/utils/fs/fs.go index cfab692..4c97340 100644 --- a/utils/fs/fs.go +++ b/utils/fs/fs.go @@ -2,21 +2,49 @@ package fs import ( + "errors" "io" "os" ) -// FS interface represent an abstracted filesystem, so you can -// use NewRepositoryFromFS from any medium. -type FS interface { - Stat(path string) (os.FileInfo, error) - Open(path string) (ReadSeekCloser, error) - ReadDir(path string) ([]os.FileInfo, error) +var ( + ErrClosed = errors.New("File: Writing on closed file.") + ErrReadOnly = errors.New("this is a read-only filesystem") + ErrNotSupported = errors.New("feature not supported") +) + +type Filesystem interface { + Create(filename string) (File, error) + Open(filename string) (File, error) + Rename(from, to string) error + Stat(filename string) (FileInfo, error) + ReadDir(path string) ([]FileInfo, error) Join(elem ...string) string + Dir(path string) Filesystem + Base() string } -// ReadSeekCloser is a Reader, Seeker and Closer. -type ReadSeekCloser interface { - io.ReadCloser +type File interface { + Filename() string + io.Writer + io.Reader io.Seeker + io.Closer +} + +type FileInfo os.FileInfo + +type BaseFile struct { + filename string + closed bool +} + +//Filename returns the filename from the File +func (f *BaseFile) Filename() string { + return f.filename +} + +//IsClosed returns if te file is closed +func (f *BaseFile) IsClosed() bool { + return f.closed } |