diff options
-rw-r--r-- | include/llvm/System/Path.h | 4 | ||||
-rw-r--r-- | lib/System/Unix/Path.cpp | 8 | ||||
-rw-r--r-- | lib/System/Unix/Path.inc | 8 | ||||
-rw-r--r-- | lib/System/Win32/Path.cpp | 14 | ||||
-rw-r--r-- | lib/System/Win32/Path.inc | 14 |
5 files changed, 34 insertions, 14 deletions
diff --git a/include/llvm/System/Path.h b/include/llvm/System/Path.h index 0e757f5c4e..5be47b21ba 100644 --- a/include/llvm/System/Path.h +++ b/include/llvm/System/Path.h @@ -494,7 +494,7 @@ namespace sys { /// already unique. /// @throws std::string if an unrecoverable error occurs. /// @brief Make the current path name unique in the file system. - void makeUnique(); + void makeUnique( bool reuse_current = true ); /// This method attempts to create a directory in the file system with the /// same name as the Path object. The \p create_parents parameter controls @@ -529,7 +529,7 @@ namespace sys { /// the newly generated temporary file name is unique in the file system. /// @throws std::string if there is an error /// @brief Create a unique temporary file - bool createTemporaryFile(); + bool createTemporaryFile(bool reuse_current = false); /// This method attempts to destroy the directory named by the last in /// the Path name. If \p remove_contents is false, an attempt will be diff --git a/lib/System/Unix/Path.cpp b/lib/System/Unix/Path.cpp index d4bf0260c5..84c2d2d23d 100644 --- a/lib/System/Unix/Path.cpp +++ b/lib/System/Unix/Path.cpp @@ -481,13 +481,13 @@ Path::createFile() { } bool -Path::createTemporaryFile() { +Path::createTemporaryFile(bool reuse_current) { // Make sure we're dealing with a file if (!isFile()) return false; // Make this into a unique file name - makeUnique(); + makeUnique( reuse_current ); // create the file int outFile = ::open(path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666); @@ -600,8 +600,8 @@ CopyFile(const sys::Path &Dest, const sys::Path &Src) { } void -Path::makeUnique() { - if (!exists()) +Path::makeUnique(bool reuse_current) { + if (reuse_current && !exists()) return; // File doesn't exist already, just use it! // Append an XXXXXX pattern to the end of the file for use with mkstemp, diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index d4bf0260c5..84c2d2d23d 100644 --- a/lib/System/Unix/Path.inc +++ b/lib/System/Unix/Path.inc @@ -481,13 +481,13 @@ Path::createFile() { } bool -Path::createTemporaryFile() { +Path::createTemporaryFile(bool reuse_current) { // Make sure we're dealing with a file if (!isFile()) return false; // Make this into a unique file name - makeUnique(); + makeUnique( reuse_current ); // create the file int outFile = ::open(path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666); @@ -600,8 +600,8 @@ CopyFile(const sys::Path &Dest, const sys::Path &Src) { } void -Path::makeUnique() { - if (!exists()) +Path::makeUnique(bool reuse_current) { + if (reuse_current && !exists()) return; // File doesn't exist already, just use it! // Append an XXXXXX pattern to the end of the file for use with mkstemp, diff --git a/lib/System/Win32/Path.cpp b/lib/System/Win32/Path.cpp index 24cfc46518..21e07c8ae1 100644 --- a/lib/System/Win32/Path.cpp +++ b/lib/System/Win32/Path.cpp @@ -587,8 +587,8 @@ CopyFile(const sys::Path &Dest, const sys::Path &Src) { } void -Path::makeUnique() { - if (!exists()) +Path::makeUnique( bool reuse_current ) { + if (reuse_current && !exists()) return; // File doesn't exist already, just use it! Path dir (*this); @@ -602,6 +602,16 @@ Path::makeUnique() { path = newName; } +bool +Path::createTemporaryFile(bool reuse_current) { + // Make sure we're dealing with a file + if (!isFile()) + return false; + + // Make this into a unique file name + makeUnique( reuse_current ); +} + } } diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc index 24cfc46518..21e07c8ae1 100644 --- a/lib/System/Win32/Path.inc +++ b/lib/System/Win32/Path.inc @@ -587,8 +587,8 @@ CopyFile(const sys::Path &Dest, const sys::Path &Src) { } void -Path::makeUnique() { - if (!exists()) +Path::makeUnique( bool reuse_current ) { + if (reuse_current && !exists()) return; // File doesn't exist already, just use it! Path dir (*this); @@ -602,6 +602,16 @@ Path::makeUnique() { path = newName; } +bool +Path::createTemporaryFile(bool reuse_current) { + // Make sure we're dealing with a file + if (!isFile()) + return false; + + // Make this into a unique file name + makeUnique( reuse_current ); +} + } } |