llvm.org GIT mirror llvm / e04f789
[dsymutil] Do not create temporary files in -no-output mode. The files were never written to and then deleted, but they were created nonetheless. To prevent that, create a wrapper around the 2 variants of createUniqueFile and use the one that only does an access(Exists) call to check for name unicity in -no-output mode. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244172 91177308-0d34-0410-b5e6-96231b3b80d8 Frederic Riss 5 years ago
1 changed file(s) with 19 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
7878 init(false), cat(DsymCategory));
7979 }
8080
81 static std::error_code getUniqueFile(const llvm::Twine &Model, int &ResultFD,
82 llvm::SmallVectorImpl &ResultPath) {
83 // If in NoOutput mode, use the createUniqueFile variant that
84 // doesn't open the file but still generates a somewhat unique
85 // name. In the real usage scenario, we'll want to ensure that the
86 // file is trully unique, and creating it is the only way to achieve
87 // that.
88 if (NoOutput)
89 return llvm::sys::fs::createUniqueFile(Model, ResultPath);
90 return llvm::sys::fs::createUniqueFile(Model, ResultFD, ResultPath);
91 }
92
8193 static std::string getOutputFileName(llvm::StringRef InputFile,
8294 bool TempFile = false) {
8395 if (TempFile) {
84 std::string OutputFile = (InputFile + ".tmp%%%%%%.dwarf").str();
96 llvm::Twine OutputFile = InputFile + ".tmp%%%%%%.dwarf";
8597 int FD;
8698 llvm::SmallString<128> UniqueFile;
87 if (auto EC = llvm::sys::fs::createUniqueFile(OutputFile, FD, UniqueFile)) {
99 if (auto EC = getUniqueFile(OutputFile, FD, UniqueFile)) {
88100 llvm::errs() << "error: failed to create temporary outfile '"
89101 << OutputFile << "': " << EC.message() << '\n';
90102 return "";
91103 }
92104 llvm::sys::RemoveFileOnSignal(UniqueFile);
93 // Close the file immediately. We know it is unique. It will be
94 // reopened and written to later.
95 llvm::raw_fd_ostream CloseImmediately(FD, true /* shouldClose */, true);
105 if (!NoOutput) {
106 // Close the file immediately. We know it is unique. It will be
107 // reopened and written to later.
108 llvm::raw_fd_ostream CloseImmediately(FD, true /* shouldClose */, true);
109 }
96110 return UniqueFile.str();
97111 }
98112