[llvm] r244172 - [dsymutil] Do not create temporary files in -no-output mode.

Frederic Riss friss at apple.com
Wed Aug 5 16:33:50 PDT 2015


Author: friss
Date: Wed Aug  5 18:33:50 2015
New Revision: 244172

URL: http://llvm.org/viewvc/llvm-project?rev=244172&view=rev
Log:
[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.

Modified:
    llvm/trunk/tools/dsymutil/dsymutil.cpp

Modified: llvm/trunk/tools/dsymutil/dsymutil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/dsymutil.cpp?rev=244172&r1=244171&r2=244172&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/dsymutil.cpp (original)
+++ llvm/trunk/tools/dsymutil/dsymutil.cpp Wed Aug  5 18:33:50 2015
@@ -79,21 +79,35 @@ static opt<bool> InputIsYAMLDebugMap(
     init(false), cat(DsymCategory));
 }
 
+static std::error_code getUniqueFile(const llvm::Twine &Model, int &ResultFD,
+                                     llvm::SmallVectorImpl<char> &ResultPath) {
+  // If in NoOutput mode, use the createUniqueFile variant that
+  // doesn't open the file but still generates a somewhat unique
+  // name. In the real usage scenario, we'll want to ensure that the
+  // file is trully unique, and creating it is the only way to achieve
+  // that.
+  if (NoOutput)
+    return llvm::sys::fs::createUniqueFile(Model, ResultPath);
+  return llvm::sys::fs::createUniqueFile(Model, ResultFD, ResultPath);
+}
+
 static std::string getOutputFileName(llvm::StringRef InputFile,
                                      bool TempFile = false) {
   if (TempFile) {
-    std::string OutputFile = (InputFile + ".tmp%%%%%%.dwarf").str();
+    llvm::Twine OutputFile = InputFile + ".tmp%%%%%%.dwarf";
     int FD;
     llvm::SmallString<128> UniqueFile;
-    if (auto EC = llvm::sys::fs::createUniqueFile(OutputFile, FD, UniqueFile)) {
+    if (auto EC = getUniqueFile(OutputFile, FD, UniqueFile)) {
       llvm::errs() << "error: failed to create temporary outfile '"
                    << OutputFile << "': " << EC.message() << '\n';
       return "";
     }
     llvm::sys::RemoveFileOnSignal(UniqueFile);
-    // Close the file immediately. We know it is unique. It will be
-    // reopened and written to later.
-    llvm::raw_fd_ostream CloseImmediately(FD, true /* shouldClose */, true);
+    if (!NoOutput) {
+      // Close the file immediately. We know it is unique. It will be
+      // reopened and written to later.
+      llvm::raw_fd_ostream CloseImmediately(FD, true /* shouldClose */, true);
+    }
     return UniqueFile.str();
   }
 




More information about the llvm-commits mailing list