Skip to content

Commit 5472947

Browse files
author
Tony Tao
committed
Prevent loss of file type flags when creating temporary
1 parent e797ec6 commit 5472947

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

llvm/lib/Support/VirtualOutputBackends.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,16 @@ Error OnDiskOutputFile::tryToCreateTemporary(std::optional<int> &FD) {
269269
return createDirectoriesOnDemand(OutputPath, Config, [&]() -> Error {
270270
int NewFD;
271271
SmallString<128> UniquePath;
272+
sys::fs::OpenFlags OF = sys::fs::OF_None;
273+
if (Config.getTextWithCRLF())
274+
OF |= sys::fs::OF_TextWithCRLF;
275+
else if (Config.getText())
276+
OF |= sys::fs::OF_Text;
277+
if (Config.getAppend())
278+
OF |= sys::fs::OF_Append;
272279
if (std::error_code EC =
273-
sys::fs::createUniqueFile(ModelPath, NewFD, UniquePath))
274-
return make_error<TempFileOutputError>(ModelPath, OutputPath, EC);
280+
sys::fs::createUniqueFile(ModelPath, NewFD, UniquePath, OF))
281+
return make_error<TempFileOutputError>(ModelPath, OutputPath, EC);
275282

276283
if (Config.getDiscardOnSignal())
277284
sys::RemoveFileOnSignal(UniquePath);

0 commit comments

Comments
 (0)