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

utils/fs: Fix O_CREATE flag check in OpenFile #116

Merged
merged 2 commits into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion utils/fs/os/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (fs *OS) Create(filename string) (fs.File, error) {
func (fs *OS) OpenFile(filename string, flag int, perm os.FileMode) (fs.File, error) {
fullpath := path.Join(fs.base, filename)

if flag|os.O_CREATE != 0 {
if flag&os.O_CREATE != 0 {
if err := fs.createDir(fullpath); err != nil {
return nil, err
}
Expand Down
8 changes: 8 additions & 0 deletions utils/fs/os/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package os_test
import (
"io/ioutil"
stdos "os"
"path/filepath"
"testing"

. "gopkg.in/check.v1"
Expand All @@ -27,3 +28,10 @@ func (s *OSSuite) TearDownTest(c *C) {
err := stdos.RemoveAll(s.path)
c.Assert(err, IsNil)
}

func (s *OSSuite) TestOpenDoesNotCreateDir(c *C) {
_, err := s.Fs.Open("dir/non-existant")
c.Assert(err, NotNil)
_, err = stdos.Stat(filepath.Join(s.path, "dir"))
c.Assert(stdos.IsNotExist(err), Equals, true)
}