Skip to content

Commit 7f92107

Browse files
committed
add
1 parent 2c3e227 commit 7f92107

34 files changed

+856
-182
lines changed

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"cSpell.words": [
3+
"newname",
4+
"newpath",
5+
"oldname",
6+
"oldpath"
7+
]
8+
}

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
vfs for golang [![Build Status](https://travis-ci.org/blang/vfs.svg?branch=master)](https://travis-ci.org/blang/vfs) [![GoDoc](https://godoc.org/github.com/blang/vfs?status.png)](https://godoc.org/github.com/blang/vfs) [![Coverage Status](https://img.shields.io/coveralls/blang/vfs.svg)](https://coveralls.io/r/blang/vfs?branch=master) [![Join the chat at https://gitter.im/blang/vfs](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/blang/vfs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
1+
vfs for golang [![Build Status](https://travis-ci.org/blang/vfs.svg?branch=master)](https://travis-ci.org/blang/vfs) [![GoDoc](https://godoc.org/github.com/3JoB/vfs?status.png)](https://godoc.org/github.com/3JoB/vfs) [![Coverage Status](https://img.shields.io/coveralls/blang/vfs.svg)](https://coveralls.io/r/blang/vfs?branch=master) [![Join the chat at https://gitter.im/blang/vfs](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/blang/vfs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
22
======
33

44
vfs is library to support virtual filesystems. It provides basic abstractions of filesystems and implementations, like `OS` accessing the file system of the underlying OS and `memfs` a full filesystem in-memory.
55

66
Usage
77
-----
88
```bash
9-
$ go get github.com/blang/vfs
9+
$ go get github.com/3JoB/vfs
1010
```
1111
Note: Always vendor your dependencies or fix on a specific version tag.
1212

1313
```go
14-
import github.com/blang/vfs
14+
import github.com/3JoB/vfs
1515
```
1616

1717
```go
@@ -52,7 +52,7 @@ fs.Mkdir("/memfs/testdir", 0777)
5252
fs.Mkdir("/tmp/testdir", 0777)
5353
```
5454

55-
Check detailed examples below. Also check the [GoDocs](http://godoc.org/github.com/blang/vfs).
55+
Check detailed examples below. Also check the [GoDocs](http://godoc.org/github.com/3JoB/vfs).
5656

5757
Why should I use this lib?
5858
-----
@@ -62,16 +62,16 @@ Why should I use this lib?
6262
- Easy to create your own filesystem
6363
- Mock a full filesystem for testing (or use included `memfs`)
6464
- Compose/Wrap Filesystems `ReadOnly(OS())` and write simple Wrappers
65-
- Many features, see [GoDocs](http://godoc.org/github.com/blang/vfs) and examples below
65+
- Many features, see [GoDocs](http://godoc.org/github.com/3JoB/vfs) and examples below
6666

6767
Features and Examples
6868
-----
6969

70-
- [OS Filesystem support](http://godoc.org/github.com/blang/vfs#example-OsFS)
71-
- [ReadOnly Wrapper](http://godoc.org/github.com/blang/vfs#example-RoFS)
72-
- [DummyFS for quick mocking](http://godoc.org/github.com/blang/vfs#example-DummyFS)
73-
- [MemFS - full in-memory filesystem](http://godoc.org/github.com/blang/vfs/memfs#example-MemFS)
74-
- [MountFS - support mounts across filesystems](http://godoc.org/github.com/blang/vfs/mountfs#example-MountFS)
70+
- [OS Filesystem support](http://godoc.org/github.com/3JoB/vfs#example-OsFS)
71+
- [ReadOnly Wrapper](http://godoc.org/github.com/3JoB/vfs#example-RoFS)
72+
- [DummyFS for quick mocking](http://godoc.org/github.com/3JoB/vfs#example-DummyFS)
73+
- [MemFS - full in-memory filesystem](http://godoc.org/github.com/3JoB/vfs/memfs#example-MemFS)
74+
- [MountFS - support mounts across filesystems](http://godoc.org/github.com/3JoB/vfs/mountfs#example-MountFS)
7575

7676
Current state: ALPHA
7777
-----

dummy.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
// Dummy creates a new dummy filesystem which returns the given error on every operation.
99
func Dummy(err error) *DummyFS {
10-
return &DummyFS{err}
10+
return &DummyFS{err: err}
1111
}
1212

1313
// DummyFS is dummy filesystem which returns an error on every operation.
@@ -21,6 +21,11 @@ func (fs DummyFS) PathSeparator() uint8 {
2121
return '/'
2222
}
2323

24+
// Open returns dummy error
25+
func (fs DummyFS) Open(name string) (File, error) {
26+
return fs.OpenFile(name, os.O_RDONLY, 0)
27+
}
28+
2429
// OpenFile returns dummy error
2530
func (fs DummyFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
2631
return nil, fs.err
@@ -41,6 +46,11 @@ func (fs DummyFS) Mkdir(name string, perm os.FileMode) error {
4146
return fs.err
4247
}
4348

49+
// Symlink returns dummy error
50+
func (fs DummyFS) Symlink(oldname, newname string) error {
51+
return fs.err
52+
}
53+
4454
// Stat returns dummy error
4555
func (fs DummyFS) Stat(name string) (os.FileInfo, error) {
4656
return nil, fs.err
@@ -60,15 +70,15 @@ func (fs DummyFS) ReadDir(path string) ([]os.FileInfo, error) {
6070
// To create a DummyFS returning a dummyFile instead of an error
6171
// you can your own DummyFS:
6272
//
63-
// type writeDummyFS struct {
64-
// Filesystem
65-
// }
73+
// type writeDummyFS struct {
74+
// Filesystem
75+
// }
6676
//
67-
// func (fs writeDummyFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
68-
// return DummyFile(dummyError), nil
69-
// }
77+
// func (fs writeDummyFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
78+
// return DummyFile(dummyError), nil
79+
// }
7080
func DummyFile(err error) *DumFile {
71-
return &DumFile{err}
81+
return &DumFile{err: err}
7282
}
7383

7484
// DumFile represents a dummy File
@@ -124,7 +134,7 @@ type DumFileInfo struct {
124134
IMode os.FileMode
125135
IModTime time.Time
126136
IDir bool
127-
ISys interface{}
137+
ISys any
128138
}
129139

130140
// Name returns the field IName
@@ -153,6 +163,6 @@ func (fi DumFileInfo) IsDir() bool {
153163
}
154164

155165
// Sys returns the field ISys
156-
func (fi DumFileInfo) Sys() interface{} {
166+
func (fi DumFileInfo) Sys() any {
157167
return fi.ISys
158168
}

dummy_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ func TestInterface(t *testing.T) {
1313

1414
func TestDummyFS(t *testing.T) {
1515
fs := Dummy(errDum)
16+
if _, err := fs.Open("/tmp/test123"); err != errDum {
17+
t.Errorf("Open DummyError expected: %s", err)
18+
}
1619
if _, err := fs.OpenFile("test", 0, 0); err != errDum {
1720
t.Errorf("OpenFile DummyError expected: %s", err)
1821
}

example_dummy_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/blang/vfs"
8+
"github.com/3JoB/vfs"
99
)
1010

1111
type myFS struct {
@@ -14,7 +14,7 @@ type myFS struct {
1414

1515
func MyFS() *myFS {
1616
return &myFS{
17-
vfs.Dummy(errors.New("Not implemented yet!")),
17+
Filesystem: vfs.Dummy(errors.New("Not implemented yet!")),
1818
}
1919
}
2020

@@ -35,7 +35,6 @@ func ExampleDummyFS() {
3535
// and return the dummys error
3636
_, err := vfs.Create(fs, "/tmp/vfs/example.txt")
3737
if err != nil {
38-
fmt.Printf("Error will be: Not implemented yet!\n")
38+
fmt.Print("Error will be: Not implemented yet!\n")
3939
}
40-
4140
}

example_os_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package vfs_test
33
import (
44
"fmt"
55

6-
"github.com/blang/vfs"
6+
"github.com/3JoB/vfs"
77
)
88

99
func ExampleOsFS() {
10-
1110
// Create a vfs accessing the filesystem of the underlying OS
1211
osFS := vfs.OS()
1312
err := osFS.Mkdir("/tmp/vfs_example", 0777)

example_readonly_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"os"
66

7-
"github.com/blang/vfs"
7+
"github.com/3JoB/vfs"
88
)
99

1010
// Every vfs.Filesystem could be easily wrapped
@@ -26,7 +26,6 @@ func ExampleRoFS() {
2626
if err != nil {
2727
fmt.Printf("Could not create file: %s\n", err)
2828
return
29-
3029
}
3130
defer f.Close()
3231

example_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package vfs_test
22

33
import (
4-
"fmt"
5-
"github.com/blang/vfs"
6-
"github.com/blang/vfs/memfs"
7-
"github.com/blang/vfs/mountfs"
4+
"errors"
85
"os"
6+
7+
"github.com/3JoB/vfs"
8+
"github.com/3JoB/vfs/memfs"
9+
"github.com/3JoB/vfs/mountfs"
910
)
1011

1112
func Example() {
@@ -23,7 +24,7 @@ func Example() {
2324
// Return vfs.ErrReadOnly
2425
_, err := f.Write([]byte("Write on readonly fs?"))
2526
if err != nil {
26-
fmt.Errorf("Filesystem is read only!\n")
27+
panic(errors.New("filesystem is read only!\n"))
2728
}
2829

2930
// Create a fully writable filesystem in memory

example_wrapping_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/blang/vfs"
8+
"github.com/3JoB/vfs"
99
)
1010

1111
type noNewDirs struct {
1212
vfs.Filesystem
1313
}
1414

1515
func NoNewDirs(fs vfs.Filesystem) *noNewDirs {
16-
return &noNewDirs{fs}
16+
return &noNewDirs{Filesystem: fs}
1717
}
1818

1919
// Mkdir is disabled
@@ -22,12 +22,11 @@ func (fs *noNewDirs) Mkdir(name string, perm os.FileMode) error {
2222
}
2323

2424
func ExampleOsFS_myWrapper() {
25-
2625
// Disable Mkdirs on the OS Filesystem
2726
var fs vfs.Filesystem = NoNewDirs(vfs.OS())
2827

2928
err := fs.Mkdir("/tmp", 0777)
3029
if err != nil {
31-
fmt.Printf("Mkdir disabled!\n")
30+
fmt.Print("Mkdir disabled!\n")
3231
}
3332
}

filesystem.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,45 @@ import (
99

1010
var (
1111
// ErrIsDirectory is returned if a file is a directory
12-
ErrIsDirectory = errors.New("Is directory")
12+
ErrIsDirectory = errors.New("is directory")
13+
1314
// ErrNotDirectory is returned if a file is not a directory
14-
ErrNotDirectory = errors.New("Is not a directory")
15+
ErrNotDirectory = errors.New("is not a directory")
1516
)
1617

1718
// Filesystem represents an abstract filesystem
1819
type Filesystem interface {
1920
PathSeparator() uint8
2021
OpenFile(name string, flag int, perm os.FileMode) (File, error)
2122
Remove(name string) error
23+
2224
// RemoveAll(path string) error
2325
Rename(oldpath, newpath string) error
26+
2427
Mkdir(name string, perm os.FileMode) error
25-
// Symlink(oldname, newname string) error
28+
29+
Symlink(oldname, newname string) error
30+
2631
// TempDir() string
2732
// Chmod(name string, mode FileMode) error
2833
// Chown(name string, uid, gid int) error
2934
Stat(name string) (os.FileInfo, error)
35+
3036
Lstat(name string) (os.FileInfo, error)
3137
ReadDir(path string) ([]os.FileInfo, error)
3238
}
3339

3440
// File represents a File with common operations.
3541
// It differs from os.File so e.g. Stat() needs to be called from the Filesystem instead.
36-
// osfile.Stat() -> filesystem.Stat(file.Name())
42+
//
43+
// osfile.Stat() -> filesystem.Stat(file.Name())
3744
type File interface {
3845
Name() string
3946
Sync() error
47+
4048
// Truncate shrinks or extends the size of the File to the specified size.
4149
Truncate(int64) error
50+
4251
io.Reader
4352
io.ReaderAt
4453
io.Writer
@@ -74,7 +83,7 @@ func MkdirAll(fs Filesystem, path string, perm os.FileMode) error {
7483
if dir.IsDir() {
7584
return nil
7685
}
77-
return &os.PathError{"mkdir", path, ErrNotDirectory}
86+
return &os.PathError{Op: "mkdir", Path: path, Err: ErrNotDirectory}
7887
}
7988

8089
parts := SplitPath(path, string(fs.PathSeparator()))

0 commit comments

Comments
 (0)