Skip to content

Commit 1862711

Browse files
committed
Use llvm::sys::fs::createUniqueFile.
Include a test that clang now produces output files with permissions matching the umask. llvm-svn: 185727
1 parent c9d2e5b commit 1862711

File tree

6 files changed

+20
-12
lines changed

6 files changed

+20
-12
lines changed

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,8 +2521,7 @@ bool ASTUnit::Save(StringRef File) {
25212521
TempPath = File;
25222522
TempPath += "-%%%%%%%%";
25232523
int fd;
2524-
if (llvm::sys::fs::unique_file(TempPath.str(), fd, TempPath,
2525-
/*makeAbsolute=*/false))
2524+
if (llvm::sys::fs::createUniqueFile(TempPath.str(), fd, TempPath))
25262525
return true;
25272526

25282527
// FIXME: Can we somehow regenerate the stat cache here, or do we need to

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,16 +544,15 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
544544
TempPath = OutFile;
545545
TempPath += "-%%%%%%%%";
546546
int fd;
547-
llvm::error_code EC = llvm::sys::fs::unique_file(
548-
TempPath.str(), fd, TempPath, /*makeAbsolute=*/ false, 0664);
547+
llvm::error_code EC =
548+
llvm::sys::fs::createUniqueFile(TempPath.str(), fd, TempPath);
549549

550550
if (CreateMissingDirectories &&
551551
EC == llvm::errc::no_such_file_or_directory) {
552552
StringRef Parent = llvm::sys::path::parent_path(OutputPath);
553553
EC = llvm::sys::fs::create_directories(Parent);
554554
if (!EC) {
555-
EC = llvm::sys::fs::unique_file(TempPath.str(), fd, TempPath,
556-
/*makeAbsolute=*/ false, 0664);
555+
EC = llvm::sys::fs::createUniqueFile(TempPath.str(), fd, TempPath);
557556
}
558557
}
559558

clang/lib/Rewrite/Core/Rewriter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,7 @@ class AtomicallyMovedFile {
433433
TempFilename = Filename;
434434
TempFilename += "-%%%%%%%%";
435435
int FD;
436-
if (llvm::sys::fs::unique_file(TempFilename.str(), FD, TempFilename,
437-
/*makeAbsolute=*/true, 0664)) {
436+
if (llvm::sys::fs::createUniqueFile(TempFilename.str(), FD, TempFilename)) {
438437
AllWritten = false;
439438
Diagnostics.Report(clang::diag::err_unable_to_make_temp)
440439
<< TempFilename;

clang/lib/Serialization/GlobalModuleIndex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,8 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr, StringRef Path) {
790790
// Write the global index file to a temporary file.
791791
llvm::SmallString<128> IndexTmpPath;
792792
int TmpFD;
793-
if (llvm::sys::fs::unique_file(IndexPath + "-%%%%%%%%", TmpFD, IndexTmpPath))
793+
if (llvm::sys::fs::createUniqueFile(IndexPath + "-%%%%%%%%", TmpFD,
794+
IndexTmpPath))
794795
return EC_IOError;
795796

796797
// Open the temporary global index file for output.

clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,8 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
247247
SmallString<128> Model, ResultPath;
248248
llvm::sys::path::append(Model, Directory, "report-%%%%%%.html");
249249

250-
if (llvm::error_code EC = llvm::sys::fs::unique_file(
251-
Model.str(), FD, ResultPath, false,
252-
llvm::sys::fs::all_read | llvm::sys::fs::all_write)) {
250+
if (llvm::error_code EC =
251+
llvm::sys::fs::createUniqueFile(Model.str(), FD, ResultPath)) {
253252
llvm::errs() << "warning: could not create file in '" << Directory
254253
<< "': " << EC.message() << '\n';
255254
return;

clang/test/Misc/permissions.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// REQUIRES: shell
2+
3+
// RUN: umask 000
4+
// RUN: %clang_cc1 -emit-llvm-bc %s -o %t
5+
// RUN: ls -l %t | FileCheck --check-prefix=CHECK000 %s
6+
// CHECK000: rw-rw-rw-
7+
8+
// RUN: umask 002
9+
// RUN: %clang_cc1 -emit-llvm-bc %s -o %t
10+
// RUN: ls -l %t | FileCheck --check-prefix=CHECK002 %s
11+
// CHECK002: rw-rw-r--

0 commit comments

Comments
 (0)