Skip to content

Commit 42ead41

Browse files
committed
osfs: fix js implementation based on menfs
1 parent 43a34ba commit 42ead41

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

osfs/os_js.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build js
2+
13
package osfs
24

35
import (
@@ -9,15 +11,7 @@ import (
911
// globalMemFs is the global memory fs
1012
var globalMemFs = memfs.New()
1113

12-
const (
13-
defaultDirectoryMode = 0755
14-
defaultCreateMode = 0666
15-
)
16-
17-
// OS is a filesystem shim for js.
18-
type OS struct{}
19-
2014
// New returns a new OS filesystem.
2115
func New(baseDir string) billy.Filesystem {
22-
return chroot.New(globalMemFs, baseDir)
16+
return chroot.New(globalMemFs, globalMemFs.Join("/", baseDir))
2317
}

osfs/os_js_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// +build js
2+
3+
package osfs
4+
5+
import (
6+
"fmt"
7+
"os"
8+
"path/filepath"
9+
"testing"
10+
11+
"github.com/go-git/go-billy/v5"
12+
"github.com/go-git/go-billy/v5/test"
13+
14+
. "gopkg.in/check.v1"
15+
)
16+
17+
func Test(t *testing.T) { TestingT(t) }
18+
19+
type OSSuite struct {
20+
test.FilesystemSuite
21+
path string
22+
tempCounter int
23+
}
24+
25+
var _ = Suite(&OSSuite{})
26+
27+
func (s *OSSuite) SetUpTest(c *C) {
28+
s.tempCounter++
29+
s.path = fmt.Sprintf("test_%d", s.tempCounter)
30+
s.FilesystemSuite = test.NewFilesystemSuite(New(s.path))
31+
}
32+
33+
func (s *OSSuite) TestOpenDoesNotCreateDir(c *C) {
34+
_, err := s.FS.Open("dir/non-existent")
35+
c.Assert(err, NotNil)
36+
37+
_, err = s.FS.Stat(filepath.Join(s.path, "dir"))
38+
c.Assert(os.IsNotExist(err), Equals, true)
39+
}
40+
41+
func (s *OSSuite) TestCapabilities(c *C) {
42+
_, ok := s.FS.(billy.Capable)
43+
c.Assert(ok, Equals, true)
44+
45+
caps := billy.Capabilities(s.FS)
46+
c.Assert(caps, Equals, billy.DefaultCapabilities&^billy.LockCapability)
47+
}

osfs/os_plan9.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build plan9
2+
13
package osfs
24

35
import (

osfs/os_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build !js
2+
13
package osfs
24

35
import (

0 commit comments

Comments
 (0)