mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
[PathV2] In llvm::sys::fs::unique_file, make sure it doesn't fall into an infinite loop by constantly trying
to create the parent path. This can happen if the path is a relative filename and the current directory was removed. Thanks to Daniel D. for the hint in fixing it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176226 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -417,6 +417,10 @@ retry_random_path:
|
|||||||
RandomPath[i] = "0123456789abcdef"[sys::Process::GetRandomNumber() & 15];
|
RandomPath[i] = "0123456789abcdef"[sys::Process::GetRandomNumber() & 15];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure we don't fall into an infinite loop by constantly trying
|
||||||
|
// to create the parent path.
|
||||||
|
bool TriedToCreateParent = false;
|
||||||
|
|
||||||
// Try to open + create the file.
|
// Try to open + create the file.
|
||||||
rety_open_create:
|
rety_open_create:
|
||||||
int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, mode);
|
int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, mode);
|
||||||
@@ -427,7 +431,9 @@ rety_open_create:
|
|||||||
goto retry_random_path;
|
goto retry_random_path;
|
||||||
// If path prefix doesn't exist, try to create it.
|
// If path prefix doesn't exist, try to create it.
|
||||||
if (SavedErrno == errc::no_such_file_or_directory &&
|
if (SavedErrno == errc::no_such_file_or_directory &&
|
||||||
!exists(path::parent_path(RandomPath))) {
|
!exists(path::parent_path(RandomPath)) &&
|
||||||
|
!TriedToCreateParent) {
|
||||||
|
TriedToCreateParent = true;
|
||||||
StringRef p(RandomPath);
|
StringRef p(RandomPath);
|
||||||
SmallString<64> dir_to_create;
|
SmallString<64> dir_to_create;
|
||||||
for (path::const_iterator i = path::begin(p),
|
for (path::const_iterator i = path::begin(p),
|
||||||
|
Reference in New Issue
Block a user