mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 12:43:36 +01:00
[Path] Set FD to -1 in moved-from TempFile
When moving a temp file, explicitly set the file descriptor to -1 so we can never accidentally close the moved-from TempFile. Differential revision: https://reviews.llvm.org/D63087 llvm-svn: 363083
This commit is contained in:
parent
e131342efa
commit
6359609b7d
@ -1125,6 +1125,7 @@ TempFile &TempFile::operator=(TempFile &&Other) {
|
||||
TmpName = std::move(Other.TmpName);
|
||||
FD = Other.FD;
|
||||
Other.Done = true;
|
||||
Other.FD = -1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -578,6 +578,7 @@ TEST_F(FileSystemTest, TempFileKeepDiscard) {
|
||||
auto TempFileOrError = fs::TempFile::create(TestDirectory + "/test-%%%%");
|
||||
ASSERT_TRUE((bool)TempFileOrError);
|
||||
fs::TempFile File = std::move(*TempFileOrError);
|
||||
ASSERT_EQ(-1, TempFileOrError->FD);
|
||||
ASSERT_FALSE((bool)File.keep(TestDirectory + "/keep"));
|
||||
ASSERT_FALSE((bool)File.discard());
|
||||
ASSERT_TRUE(fs::exists(TestDirectory + "/keep"));
|
||||
@ -589,6 +590,7 @@ TEST_F(FileSystemTest, TempFileDiscardDiscard) {
|
||||
auto TempFileOrError = fs::TempFile::create(TestDirectory + "/test-%%%%");
|
||||
ASSERT_TRUE((bool)TempFileOrError);
|
||||
fs::TempFile File = std::move(*TempFileOrError);
|
||||
ASSERT_EQ(-1, TempFileOrError->FD);
|
||||
ASSERT_FALSE((bool)File.discard());
|
||||
ASSERT_FALSE((bool)File.discard());
|
||||
ASSERT_FALSE(fs::exists(TestDirectory + "/keep"));
|
||||
|
Loading…
Reference in New Issue
Block a user