code cleanup
This commit is contained in:
parent
25d8ca6920
commit
af38d60982
|
@ -322,30 +322,13 @@ void reHDD::searchDrives(list <Drive>* plistDrives)
|
||||||
*/
|
*/
|
||||||
void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
|
void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
|
||||||
{
|
{
|
||||||
//string sDelimiter = ":";
|
|
||||||
// string sIgnoredDrivePath;
|
|
||||||
string sIgnoredDriveUUID;
|
|
||||||
|
|
||||||
list<tuple<string>> vtlIgnoredDevices; //store drives from ingnore file
|
list<tuple<string>> vtlIgnoredDevices; //store drives from ingnore file
|
||||||
|
|
||||||
ifstream input( "ignoreDrives.conf" ); //read ingnore file
|
ifstream input( "ignoreDrives.conf" ); //read ingnore file
|
||||||
|
|
||||||
for(string sLine; getline( input, sLine );)
|
for(string sLine; getline( input, sLine );)
|
||||||
{
|
{
|
||||||
// if (string(sLine).find("/dev/sd") != string::npos)
|
Logger::logThis()->info("read uuid: " + sLine);
|
||||||
// {
|
vtlIgnoredDevices.emplace_back(sLine); //add found path and uuid from ignore file to vector
|
||||||
//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
|
|
||||||
Logger::logThis()->info("read uuid: " + sIgnoredDriveUUID);
|
|
||||||
vtlIgnoredDevices.emplace_back(sIgnoredDriveUUID); //add found path and uuid from ignore file to vector
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
//loop through found entries in ingnore file
|
//loop through found entries in ingnore file
|
||||||
for(auto row : vtlIgnoredDevices)
|
for(auto row : vtlIgnoredDevices)
|
||||||
|
@ -354,49 +337,40 @@ void reHDD::filterIgnoredDrives(list <Drive>* plistDrives)
|
||||||
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
|
for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
|
||||||
{
|
{
|
||||||
string sUUID;
|
string sUUID;
|
||||||
//if (!get<0>(row).compare(it->getPath())) //find same drive based on path
|
char * cLine = NULL;
|
||||||
// {
|
size_t len = 0;
|
||||||
char * cLine = NULL;
|
string sCMD = "blkid ";
|
||||||
size_t len = 0;
|
sCMD.append(it->getPath());
|
||||||
string sCMD = "blkid ";
|
//cout << "cmd: " << sCMD << endl;
|
||||||
sCMD.append(it->getPath());
|
FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive
|
||||||
//cout << "cmd: " << sCMD << endl;
|
if (outputfileBlkid == NULL)
|
||||||
FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive
|
{
|
||||||
if (outputfileBlkid == NULL)
|
exit(EXIT_FAILURE);
|
||||||
{
|
}
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((getline(&cLine, &len, outputfileBlkid)) != -1) //parse UUID from blkid
|
while ((getline(&cLine, &len, outputfileBlkid)) != -1) //parse UUID from blkid
|
||||||
|
{
|
||||||
|
if (string(cLine).find("PTUUID") != string::npos)
|
||||||
{
|
{
|
||||||
if (string(cLine).find("PTUUID") != string::npos)
|
string sBlkidOut = string(cLine);
|
||||||
{
|
sBlkidOut.erase(0, 18);
|
||||||
string sBlkidOut = string(cLine);
|
sBlkidOut.erase(36, sBlkidOut.length() - 36);
|
||||||
sBlkidOut.erase(0, 18);
|
sUUID = sBlkidOut;
|
||||||
sBlkidOut.erase(36, sBlkidOut.length() - 36);
|
//cout << "blkid uuid:" << sUUID << endl;
|
||||||
sUUID = sBlkidOut;
|
|
||||||
//cout << "blkid uuid:" << sUUID << endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pclose(outputfileBlkid);
|
}
|
||||||
//cout << "blkid uuid:" << sUUID << endl;
|
pclose(outputfileBlkid);
|
||||||
|
//cout << "blkid uuid:" << sUUID << endl;
|
||||||
|
|
||||||
if (get<0>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive
|
if (!get<0>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive
|
||||||
{
|
{
|
||||||
//cout << "[ERROR] different uuid found than in ignore file:" << it->getPath() << endl;
|
// same uuid found than in ignore file --> ignore this drive
|
||||||
//Logger::logThis()->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
|
|
||||||
{
|
|
||||||
// same uuid found than in ignore file --> ignore this drive
|
|
||||||
#ifdef LOG_LEVEL_HIGH
|
#ifdef LOG_LEVEL_HIGH
|
||||||
Logger::logThis()->info("same uuid found than in ignore file --> ignore this drive: " + it->getPath());
|
Logger::logThis()->info("same uuid found than in ignore file --> ignore this drive: " + it->getPath());
|
||||||
#endif
|
#endif
|
||||||
it = plistDrives->erase(it);
|
it = plistDrives->erase(it);
|
||||||
it--;
|
it--;
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue