From 4762c069dead49ba96c05da0b827f52fad117164 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Tue, 9 Jan 2018 17:27:45 +0000 Subject: [Support] Use realpath(3) instead of trying to open a file. If we don't have read permissions on the directory the call would fail. llvm-svn: 322095 --- llvm/unittests/Support/Path.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'llvm/unittests/Support/Path.cpp') diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index f624626f5e5..f30ef69b565 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -564,6 +564,25 @@ TEST_F(FileSystemTest, RealPath) { ASSERT_NO_ERROR(fs::remove_directories(Twine(TestDirectory) + "/test1")); } +#ifdef LLVM_ON_UNIX +TEST_F(FileSystemTest, RealPathNoReadPerm) { + SmallString<64> Expanded; + + ASSERT_NO_ERROR( + fs::create_directories(Twine(TestDirectory) + "/noreadperm")); + ASSERT_TRUE(fs::exists(Twine(TestDirectory) + "/noreadperm")); + + fs::setPermissions(Twine(TestDirectory) + "/noreadperm", fs::no_perms); + fs::setPermissions(Twine(TestDirectory) + "/noreadperm", fs::all_exe); + + ASSERT_NO_ERROR(fs::real_path(Twine(TestDirectory) + "/noreadperm", Expanded, + false)); + + ASSERT_NO_ERROR(fs::remove_directories(Twine(TestDirectory) + "/noreadperm")); +} +#endif + + TEST_F(FileSystemTest, TempFileKeepDiscard) { // We can keep then discard. auto TempFileOrError = fs::TempFile::create(TestDirectory + "/test-%%%%"); -- cgit v1.2.3