Enable util/file to set permissions
Super handy at times.
Change-Id: Iea590c6aae34469d0f529024632aabb9f906390b
diff --git a/aos/util/file.cc b/aos/util/file.cc
index 97500d1..a11e330 100644
--- a/aos/util/file.cc
+++ b/aos/util/file.cc
@@ -30,10 +30,11 @@
}
void WriteStringToFileOrDie(const std::string_view filename,
- const std::string_view contents) {
+ const std::string_view contents,
+ mode_t permissions) {
::std::string r;
ScopedFD fd(open(::std::string(filename).c_str(),
- O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU));
+ O_CREAT | O_WRONLY | O_TRUNC, permissions));
PCHECK(fd.get() != -1) << ": opening " << filename;
size_t size_written = 0;
while (size_written != contents.size()) {
diff --git a/aos/util/file.h b/aos/util/file.h
index 4d0ed2d..8089225 100644
--- a/aos/util/file.h
+++ b/aos/util/file.h
@@ -1,6 +1,7 @@
#ifndef AOS_UTIL_FILE_H_
#define AOS_UTIL_FILE_H_
+#include <sys/stat.h>
#include <string>
#include <string_view>
@@ -15,7 +16,8 @@
// Creates filename if it doesn't exist and sets the contents to contents.
void WriteStringToFileOrDie(const std::string_view filename,
- const std::string_view contents);
+ const std::string_view contents,
+ mode_t permissions = S_IRWXU);
// Returns true if it succeeds or false if the filesystem is full.
bool MkdirPIfSpace(std::string_view path, mode_t mode);