@@ -119,18 +119,53 @@ TEST(Support, Path) {
119
119
outs ().flush ();
120
120
}
121
121
122
+ // Create a temp file.
122
123
int FileDescriptor;
123
124
SmallString<64 > TempPath;
124
125
ASSERT_FALSE (fs::unique_file (" %%-%%-%%-%%.temp" , FileDescriptor, TempPath));
125
126
127
+ // Make sure it exists.
126
128
bool TempFileExists;
127
129
ASSERT_FALSE (sys::fs::exists (Twine (TempPath), TempFileExists));
128
130
EXPECT_TRUE (TempFileExists);
129
131
132
+ // Create another temp tile.
133
+ int FD2;
134
+ SmallString<64 > TempPath2;
135
+ ASSERT_FALSE (fs::unique_file (" %%-%%-%%-%%.temp" , FD2, TempPath2));
136
+ ASSERT_NE (TempPath.str (), TempPath2.str ());
137
+
138
+ // Try to copy the first to the second.
139
+ EXPECT_EQ (fs::copy_file (Twine (TempPath), Twine (TempPath2)), errc::file_exists);
140
+
141
+ ::close (FD2);
142
+ // Try again with the proper options.
143
+ ASSERT_FALSE (fs::copy_file (Twine (TempPath), Twine (TempPath2),
144
+ fs::copy_option::overwrite_if_exists));
145
+ // Remove Temp2.
146
+ ASSERT_FALSE (fs::remove (Twine (TempPath2), TempFileExists));
147
+ EXPECT_TRUE (TempFileExists);
148
+
149
+ // Make sure Temp2 doesn't exist.
150
+ ASSERT_FALSE (fs::exists (Twine (TempPath2), TempFileExists));
151
+ EXPECT_FALSE (TempFileExists);
152
+
153
+ // Create a hard link to Temp1.
154
+ ASSERT_FALSE (fs::create_hard_link (Twine (TempPath), Twine (TempPath2)));
155
+ bool equal;
156
+ ASSERT_FALSE (fs::equivalent (Twine (TempPath), Twine (TempPath2), equal));
157
+ EXPECT_TRUE (equal);
158
+
159
+ // Remove Temp1.
130
160
::close (FileDescriptor);
131
161
ASSERT_FALSE (fs::remove (Twine (TempPath), TempFileExists));
132
162
EXPECT_TRUE (TempFileExists);
133
163
164
+ // Remove the hard link.
165
+ ASSERT_FALSE (fs::remove (Twine (TempPath2), TempFileExists));
166
+ EXPECT_TRUE (TempFileExists);
167
+
168
+ // Make sure Temp1 doesn't exist.
134
169
ASSERT_FALSE (fs::exists (Twine (TempPath), TempFileExists));
135
170
EXPECT_FALSE (TempFileExists);
136
171
}
0 commit comments