aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorPierre Guilleminot <pierre.guilleminot@gmail.com>2016-11-07 10:52:34 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-11-07 10:52:34 +0100
commit1b2f95c971a2492f012db76bd49a948c2691c9bd (patch)
tree6102ba115180d87c14efa73b010491ec6f554ad5 /utils
parent1da0de4423bcba9ff98c53f15cbf9cb8f11ebe27 (diff)
downloadgo-git-1b2f95c971a2492f012db76bd49a948c2691c9bd.tar.gz
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.
Diffstat (limited to 'utils')
-rw-r--r--utils/fs/os/os.go2
-rw-r--r--utils/fs/os/os_test.go8
2 files changed, 9 insertions, 1 deletions
diff --git a/utils/fs/os/os.go b/utils/fs/os/os.go
index 3ff825e..4f4e651 100644
--- a/utils/fs/os/os.go
+++ b/utils/fs/os/os.go
@@ -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
}
diff --git a/utils/fs/os/os_test.go b/utils/fs/os/os_test.go
index 756e284..2bb9391 100644
--- a/utils/fs/os/os_test.go
+++ b/utils/fs/os/os_test.go
@@ -3,6 +3,7 @@ package os_test
import (
"io/ioutil"
stdos "os"
+ "path/filepath"
"testing"
. "gopkg.in/check.v1"
@@ -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)
+}