diff options
author | Bob Haarman <llvm@inglorion.net> | 2018-08-02 17:41:38 +0000 |
---|---|---|
committer | Bob Haarman <llvm@inglorion.net> | 2018-08-02 17:41:38 +0000 |
commit | 9b36f51ae7618e2684d54c99fc88a379462dbeec (patch) | |
tree | deaab7995e513db7d1aed7c4389ecd6f9ff4b6e7 /llvm/unittests/Support/Path.cpp | |
parent | 41d7047de59f9c40067658df900ccc9d58eb7a3e (diff) | |
download | bcm5719-llvm-9b36f51ae7618e2684d54c99fc88a379462dbeec.tar.gz bcm5719-llvm-9b36f51ae7618e2684d54c99fc88a379462dbeec.zip |
[Support] fix TempFile infinite loop and permission denied errors
Summary:
On Windows, TempFile::create() was prone to failing with permission
denied errors when a process created many tempfiles without providing
a model large enough to accommodate them. There was also a problem
with createUniqueEntity getting into an infinite loop when all names
permitted by the model are in use. This change fixes both of these
problems and adds a unit test for them.
Reviewers: pcc, rnk, zturner
Reviewed By: zturner
Subscribers: inglorion, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D50126
llvm-svn: 338745
Diffstat (limited to 'llvm/unittests/Support/Path.cpp')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index dc5bfb8c7bd..158d6cfa3c3 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -681,6 +681,37 @@ TEST_F(FileSystemTest, TempFiles) { #endif } +TEST_F(FileSystemTest, TempFileCollisions) { + SmallString<128> TestDirectory; + ASSERT_NO_ERROR( + fs::createUniqueDirectory("CreateUniqueFileTest", TestDirectory)); + FileRemover Cleanup(TestDirectory); + SmallString<128> Model = TestDirectory; + path::append(Model, "%.tmp"); + SmallString<128> Path; + std::vector<fs::TempFile> TempFiles; + + auto TryCreateTempFile = [&]() { + Expected<fs::TempFile> T = fs::TempFile::create(Model); + if (T) { + TempFiles.push_back(std::move(*T)); + return true; + } else { + logAllUnhandledErrors(T.takeError(), errs(), + "Failed to create temporary file: "); + return false; + } + }; + + // We should be able to create exactly 16 temporary files. + for (int i = 0; i < 16; ++i) + EXPECT_TRUE(TryCreateTempFile()); + EXPECT_FALSE(TryCreateTempFile()); + + for (fs::TempFile &T : TempFiles) + cantFail(T.discard()); +} + TEST_F(FileSystemTest, CreateDir) { ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "foo")); ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "foo")); |