aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/osutil/osutil.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-07-03 14:00:47 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-07-03 14:00:47 +0200
commita7b199253f7a517fd62f36a5d632efee3bac737e (patch)
tree9f981ff2814ed7389e973c02376f8b2618224be2 /pkg/osutil/osutil.go
parent1438a6de8130467a2fcde187ba80b8a616f8daa0 (diff)
all: use consistent file permissions
Currently we have unix permissions for new files/dirs hardcoded throughout the code base. Some places use 0644, some - 0640, some - 0600 and a variety of other constants. Introduce osutil.MkdirAll/WriteFile that use the default permissions and use them throughout the code base. This makes permissions consistent and also allows to easily change the permissions later if we change our minds. Also merge pkg/fileutil into pkg/osutil as they become dependent on each other. The line between them was poorly defined anyway as both operate on files.
Diffstat (limited to 'pkg/osutil/osutil.go')
-rw-r--r--pkg/osutil/osutil.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go
index b63fffc1e..4a411c38e 100644
--- a/pkg/osutil/osutil.go
+++ b/pkg/osutil/osutil.go
@@ -7,19 +7,19 @@ import (
"bytes"
"fmt"
"io"
+ "io/ioutil"
"os"
"os/exec"
"os/signal"
"path/filepath"
"syscall"
"time"
-
- "github.com/google/syzkaller/pkg/fileutil"
)
const (
DefaultDirPerm = 0755
DefaultFilePerm = 0644
+ DefaultExecPerm = 0755
)
// RunCmd runs "bin args..." in dir with timeout and returns its output.
@@ -121,16 +121,16 @@ func CopyFiles(srcDir, dstDir string, files []string) error {
if err := os.RemoveAll(tmpDir); err != nil {
return err
}
- if err := os.MkdirAll(tmpDir, DefaultDirPerm); err != nil {
+ if err := MkdirAll(tmpDir); err != nil {
return err
}
for _, f := range files {
src := filepath.Join(srcDir, filepath.FromSlash(f))
dst := filepath.Join(tmpDir, filepath.FromSlash(f))
- if err := os.MkdirAll(filepath.Dir(dst), DefaultDirPerm); err != nil {
+ if err := MkdirAll(filepath.Dir(dst)); err != nil {
return err
}
- if err := fileutil.CopyFile(src, dst); err != nil {
+ if err := CopyFile(src, dst); err != nil {
return err
}
}
@@ -147,13 +147,13 @@ func LinkFiles(srcDir, dstDir string, files []string) error {
if err := os.RemoveAll(dstDir); err != nil {
return err
}
- if err := os.MkdirAll(dstDir, DefaultDirPerm); err != nil {
+ if err := MkdirAll(dstDir); err != nil {
return err
}
for _, f := range files {
src := filepath.Join(srcDir, filepath.FromSlash(f))
dst := filepath.Join(dstDir, filepath.FromSlash(f))
- if err := os.MkdirAll(filepath.Dir(dst), DefaultDirPerm); err != nil {
+ if err := MkdirAll(filepath.Dir(dst)); err != nil {
return err
}
if err := os.Link(src, dst); err != nil {
@@ -162,3 +162,15 @@ func LinkFiles(srcDir, dstDir string, files []string) error {
}
return nil
}
+
+func MkdirAll(dir string) error {
+ return os.MkdirAll(dir, DefaultDirPerm)
+}
+
+func WriteFile(filename string, data []byte) error {
+ return ioutil.WriteFile(filename, data, DefaultFilePerm)
+}
+
+func WriteExecFile(filename string, data []byte) error {
+ return ioutil.WriteFile(filename, data, DefaultExecPerm)
+}