From 3b50efbe025fae9be5c7efa01ad1781ac4221e85 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Thu, 3 Dec 2015 23:56:50 -0800 Subject: [PATCH] WriteFile*() takes file mode --- os.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/os.go b/os.go index 43fed1349..1d0b538d2 100644 --- a/os.go +++ b/os.go @@ -64,8 +64,8 @@ func MustReadFile(filePath string) []byte { return fileBytes } -func WriteFile(filePath string, contents []byte) error { - err := ioutil.WriteFile(filePath, contents, 0600) +func WriteFile(filePath string, contents []byte, mode os.FileMode) error { + err := ioutil.WriteFile(filePath, contents, mode) if err != nil { return err } @@ -73,8 +73,8 @@ func WriteFile(filePath string, contents []byte) error { return nil } -func MustWriteFile(filePath string, contents []byte) { - err := WriteFile(filePath, contents) +func MustWriteFile(filePath string, contents []byte, mode os.FileMode) { + err := WriteFile(filePath, contents, mode) if err != nil { Exit(Fmt("MustWriteFile failed: %v", err)) } @@ -83,20 +83,20 @@ func MustWriteFile(filePath string, contents []byte) { // Writes to newBytes to filePath. // Guaranteed not to lose *both* oldBytes and newBytes, // (assuming that the OS is perfect) -func WriteFileAtomic(filePath string, newBytes []byte) error { +func WriteFileAtomic(filePath string, newBytes []byte, mode os.FileMode) error { // If a file already exists there, copy to filePath+".bak" (overwrite anything) if _, err := os.Stat(filePath); !os.IsNotExist(err) { fileBytes, err := ioutil.ReadFile(filePath) if err != nil { return fmt.Errorf("Could not read file %v. %v", filePath, err) } - err = ioutil.WriteFile(filePath+".bak", fileBytes, 0600) + err = ioutil.WriteFile(filePath+".bak", fileBytes, mode) if err != nil { return fmt.Errorf("Could not write file %v. %v", filePath+".bak", err) } } // Write newBytes to filePath.new - err := ioutil.WriteFile(filePath+".new", newBytes, 0600) + err := ioutil.WriteFile(filePath+".new", newBytes, mode) if err != nil { return fmt.Errorf("Could not write file %v. %v", filePath+".new", err) }