summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorAlex Brachet <alexbrachetmialot@gmail.com>2019-06-28 03:21:00 +0000
committerAlex Brachet <alexbrachetmialot@gmail.com>2019-06-28 03:21:00 +0000
commit3b715d67ddea3599623090212f9a0880cf164806 (patch)
treeeae1a57a9bd366d59ad7ab96f427931d1d281d19 /llvm/lib/Support
parent588a17097038d5e0e4053116306aca80f766d853 (diff)
downloadbcm5719-llvm-3b715d67ddea3599623090212f9a0880cf164806.tar.gz
bcm5719-llvm-3b715d67ddea3599623090212f9a0880cf164806.zip
[Support] Add fs::getUmask() function and change fs::setPermissions
Summary: This patch changes fs::setPermissions to optionally set permissions while respecting the umask. It also adds the function fs::getUmask() which returns the current umask. Reviewers: jhenderson, rupprecht, aprantl, lhames Reviewed By: jhenderson, rupprecht Subscribers: sanaanajjar231288, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63583 llvm-svn: 364621
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/Unix/Path.inc14
-rw-r--r--llvm/lib/Support/Windows/Path.inc7
2 files changed, 19 insertions, 2 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 280624e9e51..761d183e91b 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -694,10 +694,22 @@ std::error_code status(int FD, file_status &Result) {
return fillStatus(StatRet, Status, Result);
}
-std::error_code setPermissions(const Twine &Path, perms Permissions) {
+unsigned getUmask() {
+ // Chose arbitary new mask and reset the umask to the old mask.
+ // umask(2) never fails so ignore the return of the second call.
+ unsigned Mask = ::umask(0);
+ (void) ::umask(Mask);
+ return Mask;
+}
+
+std::error_code setPermissions(const Twine &Path, perms Permissions,
+ bool RespectUmask) {
SmallString<128> PathStorage;
StringRef P = Path.toNullTerminatedStringRef(PathStorage);
+ if (RespectUmask)
+ Permissions = static_cast<perms>(Permissions & ~getUmask());
+
if (::chmod(P.begin(), Permissions))
return std::error_code(errno, std::generic_category());
return std::error_code();
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 012e5ce8406..9adda233c02 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -734,7 +734,12 @@ std::error_code status(int FD, file_status &Result) {
return getStatus(FileHandle, Result);
}
-std::error_code setPermissions(const Twine &Path, perms Permissions) {
+unsigned getUmask() {
+ return 0;
+}
+
+std::error_code setPermissions(const Twine &Path, perms Permissions,
+ bool /*RespectUmask*/) {
SmallVector<wchar_t, 128> PathUTF16;
if (std::error_code EC = widenPath(Path, PathUTF16))
return EC;
OpenPOWER on IntegriCloud