Adjust name of working copy until unique if unable to override
This commit is contained in:
parent
f50321f414
commit
2347677495
|
@ -251,7 +251,8 @@ string TestApplication::workingCopyPathMode(const string &name, WorkingCopyMode
|
||||||
|
|
||||||
// copy the file
|
// copy the file
|
||||||
const auto origFilePath(testFilePath(name));
|
const auto origFilePath(testFilePath(name));
|
||||||
const auto workingCopyPath(m_workingDir + name);
|
auto workingCopyPath(m_workingDir + name);
|
||||||
|
size_t workingCopyPathAttempt = 0;
|
||||||
fstream origFile, workingCopy;
|
fstream origFile, workingCopy;
|
||||||
origFile.open(origFilePath, ios_base::in | ios_base::binary);
|
origFile.open(origFilePath, ios_base::in | ios_base::binary);
|
||||||
if (origFile.fail()) {
|
if (origFile.fail()) {
|
||||||
|
@ -260,6 +261,12 @@ string TestApplication::workingCopyPathMode(const string &name, WorkingCopyMode
|
||||||
return string();
|
return string();
|
||||||
}
|
}
|
||||||
workingCopy.open(workingCopyPath, ios_base::out | ios_base::binary | ios_base::trunc);
|
workingCopy.open(workingCopyPath, ios_base::out | ios_base::binary | ios_base::trunc);
|
||||||
|
while (workingCopy.fail() && !stat(workingCopyPath.c_str(), ¤tStat)) {
|
||||||
|
// adjust the working copy path if the target file already exists and can not be truncated
|
||||||
|
workingCopyPath = argsToString(m_workingDir, "/tmp-", ++workingCopyPathAttempt, '-', name);
|
||||||
|
workingCopy.clear();
|
||||||
|
workingCopy.open(workingCopyPath, ios_base::out | ios_base::binary | ios_base::trunc);
|
||||||
|
}
|
||||||
if (workingCopy.fail()) {
|
if (workingCopy.fail()) {
|
||||||
cerr << Phrases::Error << "Unable to create working copy for \"" << name << "\": an IO error occurred when opening target file \""
|
cerr << Phrases::Error << "Unable to create working copy for \"" << name << "\": an IO error occurred when opening target file \""
|
||||||
<< workingCopyPath << "\"." << Phrases::EndFlush;
|
<< workingCopyPath << "\"." << Phrases::EndFlush;
|
||||||
|
|
Loading…
Reference in New Issue