Add `mode` parameter to FileUtil.h writeFile
authorAndrew Krieger <andrew.krieger@oculus.com>
Wed, 28 Jun 2017 23:42:40 +0000 (16:42 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 28 Jun 2017 23:50:47 +0000 (16:50 -0700)
Summary:
writeFileAtomic variants all have a mode, lets just hoist the mode parameter
up and use what was hardcoded as the default.

Reviewed By: Orvid

Differential Revision: D5341481

fbshipit-source-id: 6976915dd73d2382b42bd991782730601b918978

folly/FileUtil.h

index 063fa2385c110d888ba8e07abc5a09f0b8b33529..7386b934fe5ff96dda9a3b5f0a3d5363ff3c7403 100644 (file)
@@ -200,11 +200,13 @@ bool readFile(
  * state will be unchanged on error.
  */
 template <class Container>
-bool writeFile(const Container& data, const char* filename,
-              int flags = O_WRONLY | O_CREAT | O_TRUNC) {
+bool writeFile(const Container& data,
+               const char* filename,
+               int flags = O_WRONLY | O_CREAT | O_TRUNC,
+               mode_t mode = 0666) {
   static_assert(sizeof(data[0]) == 1,
                 "writeFile works with element size equal to 1");
-  int fd = open(filename, flags, 0666);
+  int fd = open(filename, flags, mode);
   if (fd == -1) {
     return false;
   }