Commit 7adf7c6c authored by Vladimír Ulman's avatar Vladimír Ulman
Browse files

ADD,CHG: File and FlightDisplayUnits create ~N "versioned" filenames,

         to prevent from overwriting of the previous records
parent 8866df9d
Pipeline #9874 failed with stages
in 47 seconds
......@@ -15,7 +15,31 @@ class FileDisplayUnit : public DisplayUnit
public:
FileDisplayUnit(const char* filename)
{
logger.open(filename);
char fn[1024];
int tryCnt = 0;
std::ifstream testingFile(filename);
while (testingFile.is_open() && tryCnt < 100)
{
//try another "version" of the filename
++tryCnt;
sprintf(fn,"%s~%d", filename, tryCnt);
testingFile.close();
testingFile.open(fn);
}
if (testingFile.is_open())
{
testingFile.close();
throw ERROR_REPORT("Refusing to create 101st flight record, please clean up your disk.");
}
if (tryCnt == 0)
logger.open(filename); //the original filename
else
logger.open(fn); //the last "versioned" filename
}
~FileDisplayUnit()
......
......@@ -16,7 +16,31 @@ class FlightRecorderDisplayUnit : public DisplayUnit
public:
FlightRecorderDisplayUnit(const char* filename)
{
logger.open(filename);
char fn[1024];
int tryCnt = 0;
std::ifstream testingFile(filename);
while (testingFile.is_open() && tryCnt < 100)
{
//try another "version" of the filename
++tryCnt;
sprintf(fn,"%s~%d", filename, tryCnt);
testingFile.close();
testingFile.open(fn);
}
if (testingFile.is_open())
{
testingFile.close();
throw ERROR_REPORT("Refusing to create 101st flight record, please clean up your disk.");
}
if (tryCnt == 0)
logger.open(filename); //the original filename
else
logger.open(fn); //the last "versioned" filename
}
~FlightRecorderDisplayUnit()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment