/** * @file shred.cpp * @brief shred drive * @author hendrik schutter * @date 03.05.2020 */ #include "../include/reHDD.h" /** * \brief shred drive with shred * \param pointer of Drive instance * \return void */ void Shred::shredDrive(Drive* drive) { size_t len = 0; //lenght of found line char* cLine = NULL; //found line #ifndef DRYRUN string sCMD = ("shred -v "); sCMD.append(drive->getPath()); #endif #ifdef DRYRUN cout << "dryrun for " << drive->getPath() << endl; // string sCMD = ("ping ::1 -c 5"); string sCMD = ("bash shred_dummy.sh"); #endif const char* cpComand = sCMD.c_str(); cout << "shred: " << cpComand << endl; FILE* shredCmdOutput = popen(cpComand, "r"); while ((getline(&cLine, &len, shredCmdOutput)) != -1) { string sLine = string(cLine); // TODO parse percentage string search("%"); size_t found = sLine.find(search); if (found!=string::npos){ uint8_t percent = 0U; sLine.erase(0, sLine.find("%")-2); sLine.erase(std::remove(sLine.begin(), sLine.end(), '\n'), sLine.end()); int i = std::stoi(sLine); cout << i << " percent" << endl; } } fclose(shredCmdOutput); }