Merge pull request 'change drive filter for system drive' (#36) from develop into master

Reviewed-on: #36
This commit is contained in:
Hendrik Schutter 2022-01-26 19:34:37 +01:00
commit 46a2de7bc4
1 changed files with 29 additions and 54 deletions

View File

@ -322,29 +322,13 @@ void reHDD::searchDrives(list <Drive>* plistDrives)
*/
void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
{
string sDelimiter = ":";
string sIgnoredDrivePath;
string sIgnoredDriveUUID;
list<tuple<string, string>> vtlIgnoredDevices; //store drives from ingnore file
list<tuple<string>> vtlIgnoredDevices; //store drives from ingnore file
ifstream input( "ignoreDrives.conf" ); //read ingnore file
for(string sLine; getline( input, sLine );)
{
if (string(sLine).find("/dev/sd") != string::npos)
{
size_t pos = 0;
string token;
while ((pos = sLine.find(sDelimiter)) != string::npos)
{
token = sLine.substr(0, pos);
sIgnoredDrivePath = token;
sLine.erase(0, pos + sDelimiter.length());
sIgnoredDriveUUID = sLine;
} //end while
vtlIgnoredDevices.emplace_back(sIgnoredDrivePath, sIgnoredDriveUUID); //add found path and uuid from ignore file to vector
}
Logger::logThis()->info("read uuid: " + sLine);
vtlIgnoredDevices.emplace_back(sLine); //add found path and uuid from ignore file to vector
}
//loop through found entries in ingnore file
for(auto row : vtlIgnoredDevices)
@ -353,8 +337,6 @@ void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
{
string sUUID;
if (!get<0>(row).compare(it->getPath())) //find same drive based on path
{
char * cLine = NULL;
size_t len = 0;
string sCMD = "blkid ";
@ -380,13 +362,7 @@ void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
pclose(outputfileBlkid);
//cout << "blkid uuid:" << sUUID << endl;
if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive
{
cout << "[ERROR] different uuid found than in ignore file:" << it->getPath() << endl;
Logger::logThis()->error("[ERROR] different uuid found than in ignore file: " + it->getPath() + " uuid from drive: " + sUUID);
exit(EXIT_FAILURE); // exit to prevent accidentally shred a system drive
}
else
if (!get<0>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive
{
// same uuid found than in ignore file --> ignore this drive
#ifdef LOG_LEVEL_HIGH
@ -397,7 +373,6 @@ void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
}
}
}
}
}
/**