aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-05 21:01:08 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-05 21:01:08 +0000
commit200c748a8643cd127271f4d6849da1e147d4442f (patch)
tree0eacbac147a7d5d59d0e41281c4b11f4784b0c50 /lib
parentcd56727b555fd009c691d1c4ae308fbaf50e0c4f (diff)
downloadexternal_llvm-200c748a8643cd127271f4d6849da1e147d4442f.zip
external_llvm-200c748a8643cd127271f4d6849da1e147d4442f.tar.gz
external_llvm-200c748a8643cd127271f4d6849da1e147d4442f.tar.bz2
Add a createUniqueFile function and switch llvm's users of unique_file.
This function is complementary to createTemporaryFile. It handles the case were the unique file is *not* temporary: we will rename it in the end. Since we will rename it, the file has to be in the same filesystem as the final destination and we don't prepend the system temporary directory. This has a small semantic difference from unique_file: the default mode is 0666. This matches the behavior of most unix tools. For example, with this change lld now produces files with the same permissions as ld. I will add a test of this change when I port clang over to createUniqueFile (next commit). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185726 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Support/FileOutputBuffer.cpp4
-rw-r--r--lib/Support/LockFileManager.cpp7
-rw-r--r--lib/Support/Path.cpp11
3 files changed, 16 insertions, 6 deletions
diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp
index 1ee69b6..fbfda31 100644
--- a/lib/Support/FileOutputBuffer.cpp
+++ b/lib/Support/FileOutputBuffer.cpp
@@ -65,8 +65,8 @@ error_code FileOutputBuffer::create(StringRef FilePath,
// Create new file in same directory but with random name.
SmallString<128> TempFilePath;
int FD;
- EC = sys::fs::unique_file(Twine(FilePath) + ".tmp%%%%%%%",
- FD, TempFilePath, false, 0644);
+ EC = sys::fs::createUniqueFile(Twine(FilePath) + ".tmp%%%%%%%",
+ FD, TempFilePath);
if (EC)
return EC;
diff --git a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp
index 2917e27..21c4d40 100644
--- a/lib/Support/LockFileManager.cpp
+++ b/lib/Support/LockFileManager.cpp
@@ -78,10 +78,9 @@ LockFileManager::LockFileManager(StringRef FileName)
UniqueLockFileName += "-%%%%%%%%";
int UniqueLockFileID;
if (error_code EC
- = sys::fs::unique_file(UniqueLockFileName.str(),
- UniqueLockFileID,
- UniqueLockFileName,
- /*makeAbsolute=*/false)) {
+ = sys::fs::createUniqueFile(UniqueLockFileName.str(),
+ UniqueLockFileID,
+ UniqueLockFileName)) {
Error = EC;
return;
}
diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp
index 36fb9f3..58c7c96 100644
--- a/lib/Support/Path.cpp
+++ b/lib/Support/Path.cpp
@@ -654,6 +654,17 @@ error_code unique_file(const Twine &Model, SmallVectorImpl<char> &ResultPath,
return createUniqueEntity(Model, Dummy, ResultPath, MakeAbsolute, 0, FS_Name);
}
+error_code createUniqueFile(const Twine &Model, int &ResultFd,
+ SmallVectorImpl<char> &ResultPath, unsigned Mode) {
+ return createUniqueEntity(Model, ResultFd, ResultPath, false, Mode, FS_File);
+}
+
+error_code createUniqueFile(const Twine &Model,
+ SmallVectorImpl<char> &ResultPath) {
+ int Dummy;
+ return createUniqueEntity(Model, Dummy, ResultPath, false, 0, FS_Name);
+}
+
static error_code createTemporaryFile(const Twine &Model, int &ResultFD,
llvm::SmallVectorImpl<char> &ResultPath,
FSEntity Type) {