summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
authorJames Henderson <jh7370@my.bristol.ac.uk>2017-03-16 11:22:09 +0000
committerJames Henderson <jh7370@my.bristol.ac.uk>2017-03-16 11:22:09 +0000
commit566fdf4a2a898bc9b1bd4b5e1cd110b8e94d2fcc (patch)
tree95d821925c4603b8eadb7b548ce7051de58d6499 /llvm/lib/Support/Path.cpp
parent7702bc237e9671b7203f2aa2eb6daf73efe4e85b (diff)
downloadbcm5719-llvm-566fdf4a2a898bc9b1bd4b5e1cd110b8e94d2fcc.tar.gz
bcm5719-llvm-566fdf4a2a898bc9b1bd4b5e1cd110b8e94d2fcc.zip
[Support] Add support for getting file system permissions on Windows and implement sys::fs::set/getPermissions to work with them
This change adds support for functions to set and get file permissions, in a similar manner to the C++17 permissions() function in <filesystem>. The setter uses chmod on Unix systems and SetFileAttributes on Windows, setting the permissions as passed in. The getter simply uses the existing status() function. Prior to this change, status() would always return an unknown value for the permissions on a Windows file, making it impossible to test the new function on Windows. I have therefore added support for this as well. On Linux, prior to this change, the permissions included the file type, which should actually be accessed via a different member of the file_status class. Note that on Windows, only the *_write permission bits have any affect - if any are set, the file is writable, and if not, the file is read-only. This is in common with what MSDN describes for their behaviour of std::filesystem::permissions(), and also what boost::filesystem does. The motivation behind this change is so that we can easily test behaviour on read-only files in LLVM unit tests, but I am sure that others may find it useful in some situations. Reviewers: zturner, amccarth, aaron.ballman Differential Revision: https://reviews.llvm.org/D30736 llvm-svn: 297945
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r--llvm/lib/Support/Path.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index fc3cf525c93..26b3eadb289 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -1192,6 +1192,14 @@ std::error_code directory_entry::status(file_status &result) const {
return fs::status(Path, result, FollowSymlinks);
}
+ErrorOr<perms> getPermissions(const Twine &Path) {
+ file_status Status;
+ if (std::error_code EC = status(Path, Status))
+ return EC;
+
+ return Status.permissions();
+}
+
} // end namespace fs
} // end namespace sys
} // end namespace llvm
OpenPOWER on IntegriCloud