From 25d8ca6920f7aa10c171c05cdaa0e50d500cc497 Mon Sep 17 00:00:00 2001 From: localhorst Date: Wed, 26 Jan 2022 19:21:38 +0100 Subject: [PATCH 1/2] filter drives only based on UUID --- src/reHDD.cpp | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 38fb6ee..c679fe9 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -322,29 +322,30 @@ void reHDD::searchDrives(list * plistDrives) */ void reHDD::filterIgnoredDrives(list * plistDrives) { - string sDelimiter = ":"; - string sIgnoredDrivePath; + //string sDelimiter = ":"; + // string sIgnoredDrivePath; string sIgnoredDriveUUID; - list> vtlIgnoredDevices; //store drives from ingnore file + list> 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()); + // 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 - } + // } //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 for(auto row : vtlIgnoredDevices) @@ -353,8 +354,8 @@ void reHDD::filterIgnoredDrives(list * plistDrives) for (it = plistDrives->begin(); it != plistDrives->end(); ++it) { string sUUID; - if (!get<0>(row).compare(it->getPath())) //find same drive based on path - { + //if (!get<0>(row).compare(it->getPath())) //find same drive based on path + // { char * cLine = NULL; size_t len = 0; string sCMD = "blkid "; @@ -380,11 +381,11 @@ void reHDD::filterIgnoredDrives(list * plistDrives) pclose(outputfileBlkid); //cout << "blkid uuid:" << sUUID << endl; - if (get<1>(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; - 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 + //cout << "[ERROR] different uuid found than in ignore file:" << it->getPath() << endl; + //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 { @@ -395,7 +396,7 @@ void reHDD::filterIgnoredDrives(list * plistDrives) it = plistDrives->erase(it); it--; } - } + // } } } } From af38d609822998006b94b2ed0c0865cc6821ea92 Mon Sep 17 00:00:00 2001 From: localhorst Date: Wed, 26 Jan 2022 19:33:41 +0100 Subject: [PATCH 2/2] code cleanup --- src/reHDD.cpp | 86 ++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 56 deletions(-) diff --git a/src/reHDD.cpp b/src/reHDD.cpp index c679fe9..f4a764e 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -322,30 +322,13 @@ void reHDD::searchDrives(list * plistDrives) */ void reHDD::filterIgnoredDrives(list * plistDrives) { - //string sDelimiter = ":"; - // string sIgnoredDrivePath; - string sIgnoredDriveUUID; - list> 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 - Logger::logThis()->info("read uuid: " + sIgnoredDriveUUID); - vtlIgnoredDevices.emplace_back(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) @@ -354,49 +337,40 @@ void reHDD::filterIgnoredDrives(list * 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 "; - sCMD.append(it->getPath()); - //cout << "cmd: " << sCMD << endl; - FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive - if (outputfileBlkid == NULL) - { - exit(EXIT_FAILURE); - } + char * cLine = NULL; + size_t len = 0; + string sCMD = "blkid "; + sCMD.append(it->getPath()); + //cout << "cmd: " << sCMD << endl; + FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive + if (outputfileBlkid == NULL) + { + 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); - sBlkidOut.erase(36, sBlkidOut.length() - 36); - sUUID = sBlkidOut; - //cout << "blkid uuid:" << sUUID << endl; - } + string sBlkidOut = string(cLine); + sBlkidOut.erase(0, 18); + sBlkidOut.erase(36, sBlkidOut.length() - 36); + 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 - { - //cout << "[ERROR] different uuid found than in ignore file:" << it->getPath() << endl; - //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 + 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 - 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 - it = plistDrives->erase(it); - it--; - } - // } + it = plistDrives->erase(it); + it--; + } } } }