diff options
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index ef223ae..f49affb 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -167,8 +167,8 @@ enum FSEntity { static std::error_code createUniqueEntity(const Twine &Model, int &ResultFD, SmallVectorImpl<char> &ResultPath, bool MakeAbsolute, - unsigned Mode, FSEntity Type, - sys::fs::OpenFlags Flags = sys::fs::OF_None) { + FSEntity Type, sys::fs::OpenFlags Flags = sys::fs::OF_None, + unsigned Mode = 0) { // Limit the number of attempts we make, so that we don't infinite loop. E.g. // "permission denied" could be for a specific file (so we retry with a @@ -816,22 +816,16 @@ void createUniquePath(const Twine &Model, SmallVectorImpl<char> &ResultPath, std::error_code createUniqueFile(const Twine &Model, int &ResultFd, SmallVectorImpl<char> &ResultPath, - unsigned Mode) { - return createUniqueEntity(Model, ResultFd, ResultPath, false, Mode, FS_File); -} - -static std::error_code createUniqueFile(const Twine &Model, int &ResultFd, - SmallVectorImpl<char> &ResultPath, - unsigned Mode, OpenFlags Flags) { - return createUniqueEntity(Model, ResultFd, ResultPath, false, Mode, FS_File, - Flags); + OpenFlags Flags, unsigned Mode) { + return createUniqueEntity(Model, ResultFd, ResultPath, false, FS_File, Flags, + Mode); } std::error_code createUniqueFile(const Twine &Model, SmallVectorImpl<char> &ResultPath, unsigned Mode) { int FD; - auto EC = createUniqueFile(Model, FD, ResultPath, Mode); + auto EC = createUniqueFile(Model, FD, ResultPath, OF_None, Mode); if (EC) return EC; // FD is only needed to avoid race conditions. Close it right away. @@ -841,34 +835,39 @@ std::error_code createUniqueFile(const Twine &Model, static std::error_code createTemporaryFile(const Twine &Model, int &ResultFD, - llvm::SmallVectorImpl<char> &ResultPath, FSEntity Type) { + llvm::SmallVectorImpl<char> &ResultPath, FSEntity Type, + sys::fs::OpenFlags Flags = sys::fs::OF_None) { SmallString<128> Storage; StringRef P = Model.toNullTerminatedStringRef(Storage); assert(P.find_first_of(separators(Style::native)) == StringRef::npos && "Model must be a simple filename."); // Use P.begin() so that createUniqueEntity doesn't need to recreate Storage. - return createUniqueEntity(P.begin(), ResultFD, ResultPath, true, - owner_read | owner_write, Type); + return createUniqueEntity(P.begin(), ResultFD, ResultPath, true, Type, Flags, + owner_read | owner_write); } static std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, - llvm::SmallVectorImpl<char> &ResultPath, FSEntity Type) { + llvm::SmallVectorImpl<char> &ResultPath, FSEntity Type, + sys::fs::OpenFlags Flags = sys::fs::OF_None) { const char *Middle = Suffix.empty() ? "-%%%%%%" : "-%%%%%%."; return createTemporaryFile(Prefix + Middle + Suffix, ResultFD, ResultPath, - Type); + Type, Flags); } std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, - SmallVectorImpl<char> &ResultPath) { - return createTemporaryFile(Prefix, Suffix, ResultFD, ResultPath, FS_File); + SmallVectorImpl<char> &ResultPath, + sys::fs::OpenFlags Flags) { + return createTemporaryFile(Prefix, Suffix, ResultFD, ResultPath, FS_File, + Flags); } std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, - SmallVectorImpl<char> &ResultPath) { + SmallVectorImpl<char> &ResultPath, + sys::fs::OpenFlags Flags) { int FD; - auto EC = createTemporaryFile(Prefix, Suffix, FD, ResultPath); + auto EC = createTemporaryFile(Prefix, Suffix, FD, ResultPath, Flags); if (EC) return EC; // FD is only needed to avoid race conditions. Close it right away. @@ -876,13 +875,12 @@ std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, return EC; } - // This is a mkdtemp with a different pattern. We use createUniqueEntity mostly // for consistency. We should try using mkdtemp. std::error_code createUniqueDirectory(const Twine &Prefix, SmallVectorImpl<char> &ResultPath) { int Dummy; - return createUniqueEntity(Prefix + "-%%%%%%", Dummy, ResultPath, true, 0, + return createUniqueEntity(Prefix + "-%%%%%%", Dummy, ResultPath, true, FS_Dir); } @@ -890,7 +888,7 @@ std::error_code getPotentiallyUniqueFileName(const Twine &Model, SmallVectorImpl<char> &ResultPath) { int Dummy; - return createUniqueEntity(Model, Dummy, ResultPath, false, 0, FS_Name); + return createUniqueEntity(Model, Dummy, ResultPath, false, FS_Name); } std::error_code @@ -1279,7 +1277,7 @@ Expected<TempFile> TempFile::create(const Twine &Model, unsigned Mode) { int FD; SmallString<128> ResultPath; if (std::error_code EC = - createUniqueFile(Model, FD, ResultPath, Mode, OF_Delete)) + createUniqueFile(Model, FD, ResultPath, OF_Delete, Mode)) return errorCodeToError(EC); TempFile Ret(ResultPath, FD); |