Skip to content

Commit bfa45f0

Browse files
authored
Merge pull request #34 from mcuadros/v3
V3 reorganization
2 parents 7a2368f + 1120c69 commit bfa45f0

35 files changed

+3126
-2410
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go:
44
- 1.8
55
- tip
66

7-
go_import_path: gopkg.in/src-d/go-billy.v2
7+
go_import_path: gopkg.in/src-d/go-billy.v3
88

99
matrix:
1010
allow_failures:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# go-billy [![GoDoc](https://godoc.org/gopkg.in/src-d/go-billy.v2?status.svg)](https://godoc.org/gopkg.in/src-d/go-billy.v2) [![Build Status](https://travis-ci.org/src-d/go-billy.svg)](https://travis-ci.org/src-d/go-billy) [![Build status](https://ci.appveyor.com/api/projects/status/vx2qn6vlakbi724t?svg=true)](https://ci.appveyor.com/project/mcuadros/go-billy) [![codecov](https://codecov.io/gh/src-d/go-billy/branch/master/graph/badge.svg)](https://codecov.io/gh/src-d/go-billy) [![codebeat badge](https://codebeat.co/badges/03bdec03-b477-4472-bbe3-b552e3799174)](https://codebeat.co/projects/github-com-src-d-go-billy)
1+
# go-billy [![GoDoc](https://godoc.org/gopkg.in/src-d/go-billy.v3?status.svg)](https://godoc.org/gopkg.in/src-d/go-billy.v3) [![Build Status](https://travis-ci.org/src-d/go-billy.svg)](https://travis-ci.org/src-d/go-billy) [![Build status](https://ci.appveyor.com/api/projects/status/vx2qn6vlakbi724t?svg=true)](https://ci.appveyor.com/project/mcuadros/go-billy) [![codecov](https://codecov.io/gh/src-d/go-billy/branch/master/graph/badge.svg)](https://codecov.io/gh/src-d/go-billy) [![codebeat badge](https://codebeat.co/badges/03bdec03-b477-4472-bbe3-b552e3799174)](https://codebeat.co/projects/github-com-src-d-go-billy)
22

33
The missing interface filesystem abstraction for Go.
44
Billy implements an interface based on the `os` standard library, allowing to develop applications without dependency on the underlying storage. Make virtually free implement an mocks and testing over filesystem operations.
@@ -8,7 +8,7 @@ Billy was born as part of [src-d/go-git](https://github.com/src-d/go-git) projec
88
## Installation
99

1010
```go
11-
go get -u gopkg.in/src-d/go-billy.v2/...
11+
go get -u gopkg.in/src-d/go-billy.v3/...
1212
```
1313

1414
## Why billy?

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "{build}"
22
platform: x64
33

4-
clone_folder: c:\gopath\src\gopkg.in\src-d\go-billy.v2
4+
clone_folder: c:\gopath\src\gopkg.in\src-d\go-billy.v3
55

66
environment:
77
GOPATH: c:\gopath

fs.go

Lines changed: 105 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,82 +4,135 @@ import (
44
"errors"
55
"io"
66
"os"
7+
"time"
78
)
89

910
var (
10-
ErrClosed = errors.New("file: Writing on closed file.")
11-
ErrReadOnly = errors.New("this is a read-only filesystem")
12-
ErrNotSupported = errors.New("feature not supported")
11+
ErrReadOnly = errors.New("read-only filesystem")
12+
ErrNotSupported = errors.New("feature not supported")
13+
ErrCrossedBoundary = errors.New("chroot boundary crossed")
1314
)
1415

1516
// Filesystem abstract the operations in a storage-agnostic interface.
16-
// It allows you to:
17-
// * Create files.
18-
// * Open existing files.
19-
// * Get info about files.
20-
// * List files in a directory.
21-
// * Get a temporal file.
22-
// * Rename files.
23-
// * Remove files.
24-
// * Create directories.
25-
// * Join parts of path.
26-
// * Obtain a filesystem starting on a subdirectory in the current filesystem.
27-
// * Get the base path for the filesystem.
28-
// Each method implementation varies from implementation to implementation. Refer to
29-
// the specific documentation for more info.
17+
// Each method implementation mimics the behavior of the equivalent functions
18+
// at the os package from the standard library.
3019
type Filesystem interface {
20+
Basic
21+
TempFile
22+
Dir
23+
Symlink
24+
Chroot
25+
}
26+
27+
// Basic abstract the basic operations in a storage-agnostic interface as
28+
// an extension to the Basic interface.
29+
type Basic interface {
30+
// Create creates the named file with mode 0666 (before umask), truncating
31+
// it if it already exists. If successful, methods on the returned File can
32+
// be used for I/O; the associated file descriptor has mode O_RDWR.
3133
Create(filename string) (File, error)
34+
// Open opens the named file for reading. If successful, methods on the
35+
// returned file can be used for reading; the associated file descriptor has
36+
// mode O_RDONLY.
3237
Open(filename string) (File, error)
38+
// OpenFile is the generalized open call; most users will use Open or Create
39+
// instead. It opens the named file with specified flag (O_RDONLY etc.) and
40+
// perm, (0666 etc.) if applicable. If successful, methods on the returned
41+
// File can be used for I/O.
3342
OpenFile(filename string, flag int, perm os.FileMode) (File, error)
3443
// Stat returns a FileInfo describing the named file.
35-
Stat(filename string) (FileInfo, error)
44+
Stat(filename string) (os.FileInfo, error)
45+
// Rename renames (moves) oldpath to newpath. If newpath already exists and
46+
// is not a directory, Rename replaces it. OS-specific restrictions may
47+
// apply when oldpath and newpath are in different directories.
48+
Rename(oldpath, newpath string) error
49+
// Remove removes the named file or directory.
50+
Remove(filename string) error
51+
// Join joins any number of path elements into a single path, adding a
52+
// Separator if necessary. Join calls filepath.Clean on the result; in
53+
// particular, all empty strings are ignored. On Windows, the result is a
54+
// UNC path if and only if the first path element is a UNC path.
55+
Join(elem ...string) string
56+
}
57+
58+
type TempFile interface {
59+
// TempFile creates a new temporary file in the directory dir with a name
60+
// beginning with prefix, opens the file for reading and writing, and
61+
// returns the resulting *os.File. If dir is the empty string, TempFile
62+
// uses the default directory for temporary files (see os.TempDir).
63+
// Multiple programs calling TempFile simultaneously will not choose the
64+
// same file. The caller can use f.Name() to find the pathname of the file.
65+
// It is the caller's responsibility to remove the file when no longer
66+
// needed.
67+
TempFile(dir, prefix string) (File, error)
68+
}
69+
70+
// Dir abstract the dir related operations in a storage-agnostic interface as
71+
// an extension to the Basic interface.
72+
type Dir interface {
73+
// ReadDir reads the directory named by dirname and returns a list of
74+
// directory entries sorted by filename.
75+
ReadDir(path string) ([]os.FileInfo, error)
76+
// MkdirAll creates a directory named path, along with any necessary
77+
// parents, and returns nil, or else returns an error. The permission bits
78+
// perm are used for all directories that MkdirAll creates. If path is/
79+
// already a directory, MkdirAll does nothing and returns nil.
80+
MkdirAll(filename string, perm os.FileMode) error
81+
}
82+
83+
// Symlink abstract the symlink related operations in a storage-agnostic
84+
// interface as an extension to the Basic interface.
85+
type Symlink interface {
3686
// Lstat returns a FileInfo describing the named file. If the file is a
3787
// symbolic link, the returned FileInfo describes the symbolic link. Lstat
3888
// makes no attempt to follow the link.
39-
Lstat(filename string) (FileInfo, error)
40-
ReadDir(path string) ([]FileInfo, error)
41-
TempFile(dir, prefix string) (File, error)
42-
Rename(from, to string) error
43-
Remove(filename string) error
44-
MkdirAll(filename string, perm os.FileMode) error
45-
Join(elem ...string) string
46-
Dir(path string) Filesystem
89+
Lstat(filename string) (os.FileInfo, error)
4790
// Symlink creates a symbolic-link from link to target. target may be an
4891
// absolute or relative path, and need not refer to an existing node.
4992
// Parent directories of link are created as necessary.
5093
Symlink(target, link string) error
51-
// Readlink returns the target path of link. An error is returned if link is
52-
// not a symbolic-link.
94+
// Readlink returns the target path of link.
5395
Readlink(link string) (string, error)
54-
Base() string
5596
}
5697

57-
// File implements io.Closer, io.Reader, io.Seeker, and io.Writer>
58-
// Provides method to obtain the file name and the state of the file (open or closed).
98+
// Change abstract the FileInfo change related operations in a storage-agnostic
99+
// interface as an extension to the Basic interface
100+
type Change interface {
101+
// Chmod changes the mode of the named file to mode. If the file is a
102+
// symbolic link, it changes the mode of the link's target.
103+
Chmod(name string, mode os.FileMode) error
104+
// Lchown changes the numeric uid and gid of the named file. If the file is
105+
// a symbolic link, it changes the uid and gid of the link itself.
106+
Lchown(name string, uid, gid int) error
107+
// Chown changes the numeric uid and gid of the named file. If the file is a
108+
// symbolic link, it changes the uid and gid of the link's target.
109+
Chown(name string, uid, gid int) error
110+
// Chtimes changes the access and modification times of the named file,
111+
// similar to the Unix utime() or utimes() functions.
112+
//
113+
// The underlying filesystem may truncate or round the values to a less
114+
// precise time unit.
115+
Chtimes(name string, atime time.Time, mtime time.Time) error
116+
}
117+
118+
// Chroot abstract the chroot related operations in a storage-agnostic interface
119+
// as an extension to the Basic interface.
120+
type Chroot interface {
121+
// Chroot returns a new filesystem from the same type where the new root is
122+
// the given path. Files outside of the designated directory tree cannot be
123+
// accessed.
124+
Chroot(path string) (Basic, error)
125+
// Root returns the root path of the filesystem.
126+
Root() string
127+
}
128+
129+
// File represent a file, being a subset of the os.File
59130
type File interface {
60-
Filename() string
61-
IsClosed() bool
131+
// Name returns the name of the file as presented to Open.
132+
Name() string
62133
io.Writer
63134
io.Reader
135+
io.ReaderAt
64136
io.Seeker
65137
io.Closer
66138
}
67-
68-
type FileInfo os.FileInfo
69-
70-
type BaseFile struct {
71-
BaseFilename string
72-
Closed bool
73-
}
74-
75-
func (f *BaseFile) Filename() string {
76-
return f.BaseFilename
77-
}
78-
79-
func (f *BaseFile) IsClosed() bool {
80-
return f.Closed
81-
}
82-
83-
type removerAll interface {
84-
RemoveAll(string) error
85-
}

0 commit comments

Comments
 (0)