Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 1b2f95c

Browse files
jinrohmcuadros
authored andcommitted
utils/fs: Fix O_CREATE flag check in OpenFile (#116)
* utils/fs: Fix O_CREATE flag check in OpenFile * utils/fs/os: test that Open does not create dirs.
1 parent 1da0de4 commit 1b2f95c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

utils/fs/os/os.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (fs *OS) Create(filename string) (fs.File, error) {
3232
func (fs *OS) OpenFile(filename string, flag int, perm os.FileMode) (fs.File, error) {
3333
fullpath := path.Join(fs.base, filename)
3434

35-
if flag|os.O_CREATE != 0 {
35+
if flag&os.O_CREATE != 0 {
3636
if err := fs.createDir(fullpath); err != nil {
3737
return nil, err
3838
}

utils/fs/os/os_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package os_test
33
import (
44
"io/ioutil"
55
stdos "os"
6+
"path/filepath"
67
"testing"
78

89
. "gopkg.in/check.v1"
@@ -27,3 +28,10 @@ func (s *OSSuite) TearDownTest(c *C) {
2728
err := stdos.RemoveAll(s.path)
2829
c.Assert(err, IsNil)
2930
}
31+
32+
func (s *OSSuite) TestOpenDoesNotCreateDir(c *C) {
33+
_, err := s.Fs.Open("dir/non-existant")
34+
c.Assert(err, NotNil)
35+
_, err = stdos.Stat(filepath.Join(s.path, "dir"))
36+
c.Assert(stdos.IsNotExist(err), Equals, true)
37+
}

0 commit comments

Comments
 (0)