[llvm] r185830 - Create files with the correct permission instead of changing it afterwards.
Rafael Espindola
rafael.espindola at gmail.com
Mon Jul 8 08:22:09 PDT 2013
Author: rafael
Date: Mon Jul 8 10:22:09 2013
New Revision: 185830
URL: http://llvm.org/viewvc/llvm-project?rev=185830&view=rev
Log:
Create files with the correct permission instead of changing it afterwards.
Not intended functionality change.
Modified:
llvm/trunk/lib/Support/FileOutputBuffer.cpp
Modified: llvm/trunk/lib/Support/FileOutputBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FileOutputBuffer.cpp?rev=185830&r1=185829&r2=185830&view=diff
==============================================================================
--- llvm/trunk/lib/Support/FileOutputBuffer.cpp (original)
+++ llvm/trunk/lib/Support/FileOutputBuffer.cpp Mon Jul 8 10:22:09 2013
@@ -62,11 +62,16 @@ error_code FileOutputBuffer::create(Stri
if (EC)
return EC;
+ unsigned Mode = sys::fs::all_read | sys::fs::all_write;
+ // If requested, make the output file executable.
+ if (Flags & F_executable)
+ Mode |= sys::fs::all_exe;
+
// Create new file in same directory but with random name.
SmallString<128> TempFilePath;
int FD;
- EC = sys::fs::createUniqueFile(Twine(FilePath) + ".tmp%%%%%%%",
- FD, TempFilePath);
+ EC = sys::fs::createUniqueFile(Twine(FilePath) + ".tmp%%%%%%%", FD,
+ TempFilePath, Mode);
if (EC)
return EC;
@@ -75,26 +80,6 @@ error_code FileOutputBuffer::create(Stri
if (EC)
return EC;
- // If requested, make the output file executable.
- if ( Flags & F_executable ) {
- sys::fs::file_status Stat2;
- EC = sys::fs::status(Twine(TempFilePath), Stat2);
- if (EC)
- return EC;
-
- sys::fs::perms new_perms = Stat2.permissions();
- if ( new_perms & sys::fs::owner_read )
- new_perms |= sys::fs::owner_exe;
- if ( new_perms & sys::fs::group_read )
- new_perms |= sys::fs::group_exe;
- if ( new_perms & sys::fs::others_read )
- new_perms |= sys::fs::others_exe;
- new_perms |= sys::fs::add_perms;
- EC = sys::fs::permissions(Twine(TempFilePath), new_perms);
- if (EC)
- return EC;
- }
-
Result.reset(new FileOutputBuffer(MappedFile.get(), FilePath, TempFilePath));
if (Result)
MappedFile.take();
More information about the llvm-commits
mailing list