mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-23 17:24:48 +00:00
Fix a file overwrite bug in llvm-ar introduced by changes to
createTemporaryFile semantics where it doesn't create a fully unique name if the basename doesn't exist. This functionality is now optionally provided by the boolean reuse_current parameter to createTemporaryFile and makeUnique. The default values differ because of the way these functions are used in LLVM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18961 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -494,7 +494,7 @@ namespace sys {
|
|||||||
/// already unique.
|
/// already unique.
|
||||||
/// @throws std::string if an unrecoverable error occurs.
|
/// @throws std::string if an unrecoverable error occurs.
|
||||||
/// @brief Make the current path name unique in the file system.
|
/// @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
|
/// 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
|
/// 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.
|
/// the newly generated temporary file name is unique in the file system.
|
||||||
/// @throws std::string if there is an error
|
/// @throws std::string if there is an error
|
||||||
/// @brief Create a unique temporary file
|
/// @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
|
/// 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
|
/// the Path name. If \p remove_contents is false, an attempt will be
|
||||||
|
@ -481,13 +481,13 @@ Path::createFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Path::createTemporaryFile() {
|
Path::createTemporaryFile(bool reuse_current) {
|
||||||
// Make sure we're dealing with a file
|
// Make sure we're dealing with a file
|
||||||
if (!isFile())
|
if (!isFile())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Make this into a unique file name
|
// Make this into a unique file name
|
||||||
makeUnique();
|
makeUnique( reuse_current );
|
||||||
|
|
||||||
// create the file
|
// create the file
|
||||||
int outFile = ::open(path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
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
|
void
|
||||||
Path::makeUnique() {
|
Path::makeUnique(bool reuse_current) {
|
||||||
if (!exists())
|
if (reuse_current && !exists())
|
||||||
return; // File doesn't exist already, just use it!
|
return; // File doesn't exist already, just use it!
|
||||||
|
|
||||||
// Append an XXXXXX pattern to the end of the file for use with mkstemp,
|
// Append an XXXXXX pattern to the end of the file for use with mkstemp,
|
||||||
|
@ -481,13 +481,13 @@ Path::createFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Path::createTemporaryFile() {
|
Path::createTemporaryFile(bool reuse_current) {
|
||||||
// Make sure we're dealing with a file
|
// Make sure we're dealing with a file
|
||||||
if (!isFile())
|
if (!isFile())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Make this into a unique file name
|
// Make this into a unique file name
|
||||||
makeUnique();
|
makeUnique( reuse_current );
|
||||||
|
|
||||||
// create the file
|
// create the file
|
||||||
int outFile = ::open(path.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
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
|
void
|
||||||
Path::makeUnique() {
|
Path::makeUnique(bool reuse_current) {
|
||||||
if (!exists())
|
if (reuse_current && !exists())
|
||||||
return; // File doesn't exist already, just use it!
|
return; // File doesn't exist already, just use it!
|
||||||
|
|
||||||
// Append an XXXXXX pattern to the end of the file for use with mkstemp,
|
// Append an XXXXXX pattern to the end of the file for use with mkstemp,
|
||||||
|
@ -587,8 +587,8 @@ CopyFile(const sys::Path &Dest, const sys::Path &Src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Path::makeUnique() {
|
Path::makeUnique( bool reuse_current ) {
|
||||||
if (!exists())
|
if (reuse_current && !exists())
|
||||||
return; // File doesn't exist already, just use it!
|
return; // File doesn't exist already, just use it!
|
||||||
|
|
||||||
Path dir (*this);
|
Path dir (*this);
|
||||||
@ -602,6 +602,16 @@ Path::makeUnique() {
|
|||||||
path = newName;
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,8 +587,8 @@ CopyFile(const sys::Path &Dest, const sys::Path &Src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Path::makeUnique() {
|
Path::makeUnique( bool reuse_current ) {
|
||||||
if (!exists())
|
if (reuse_current && !exists())
|
||||||
return; // File doesn't exist already, just use it!
|
return; // File doesn't exist already, just use it!
|
||||||
|
|
||||||
Path dir (*this);
|
Path dir (*this);
|
||||||
@ -602,6 +602,16 @@ Path::makeUnique() {
|
|||||||
path = newName;
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user