parse percentage from shred cmd
This commit is contained in:
parent
df4ed53693
commit
e4b3923f6d
|
@ -36,7 +36,7 @@ using namespace std;
|
|||
|
||||
#include "drive.h"
|
||||
#include "smart.h"
|
||||
#include "wipe.h"
|
||||
#include "shred.h"
|
||||
#include "tui.h"
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* @file shred.h
|
||||
* @brief shred drive
|
||||
* @author hendrik schutter
|
||||
* @date 03.05.2020
|
||||
*/
|
||||
|
||||
#ifndef SHRED_H_
|
||||
#define SHRED_H_
|
||||
|
||||
#include "reHDD.h"
|
||||
|
||||
class Shred
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
static void shredDrive(Drive* drive);
|
||||
|
||||
private:
|
||||
Shred(void);
|
||||
|
||||
};
|
||||
|
||||
#endif // SHRED_H_
|
|
@ -1,25 +0,0 @@
|
|||
/**
|
||||
* @file wipe.h
|
||||
* @brief wipe drive
|
||||
* @author hendrik schutter
|
||||
* @date 03.05.2020
|
||||
*/
|
||||
|
||||
#ifndef WIPE_H_
|
||||
#define WIPE_H_
|
||||
|
||||
#include "reHDD.h"
|
||||
|
||||
class Wipe
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
static void wipeDrive(Drive* drive);
|
||||
|
||||
private:
|
||||
Wipe(void);
|
||||
|
||||
};
|
||||
|
||||
#endif // WIPE_H_
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
echo "starting SHRED DUMMY"
|
||||
|
||||
for i in {1..101..3}
|
||||
for i in {0..100..10}
|
||||
do
|
||||
echo "DUMMY shred $i%"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "finished SHRED DUMMY"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
static int fdSearchDrives[2];//File descriptor for pipe that informs if new drives are found
|
||||
|
||||
static int fdWhipe[2];//File descriptor for pipe that informs if a wipe thread signals
|
||||
static int fdShred[2];//File descriptor for pipe that informs if a wipe thread signals
|
||||
|
||||
static std::mutex mxScannDrives;
|
||||
|
||||
|
@ -48,11 +48,11 @@ void reHDD::app_logic(void)
|
|||
ui->initTUI();
|
||||
|
||||
pipe(fdSearchDrives);
|
||||
pipe(fdWhipe);
|
||||
pipe(fdShred);
|
||||
|
||||
FD_ZERO(&selectSet);
|
||||
FD_SET(fdSearchDrives[0], &selectSet);
|
||||
FD_SET(fdWhipe[0], &selectSet);
|
||||
FD_SET(fdShred[0], &selectSet);
|
||||
|
||||
thread thDevices(ThreadScannDevices); //start thread that scanns for drives
|
||||
thread thUserInput(ThreadUserInput); //start thread that reads user input
|
||||
|
@ -73,11 +73,11 @@ void reHDD::app_logic(void)
|
|||
|
||||
ui->updateTUI(&vecDrives, i32SelectedEntry);
|
||||
}
|
||||
else if (FD_ISSET(fdWhipe[0], &selectSet))
|
||||
else if (FD_ISSET(fdShred[0], &selectSet))
|
||||
{
|
||||
cout << "Whipe signal" << endl;
|
||||
//update percantage & state
|
||||
//update ui
|
||||
cout << "shred signal" << endl;
|
||||
//TODO update percantage & state
|
||||
//TODO update ui
|
||||
}
|
||||
} //endless loop
|
||||
thDevices.join();
|
||||
|
@ -377,7 +377,9 @@ void reHDD::handleEnter()
|
|||
{
|
||||
SELECTED_DRIVE.state = Drive::TaskState::SHRED_ACTIVE;
|
||||
//task for drive is running --> don´t show more task options
|
||||
|
||||
//TODO start shredding
|
||||
Shred::shredDrive(&vecDrives.at(i32SelectedEntry));
|
||||
}
|
||||
|
||||
if(SELECTED_DRIVE.state == Drive::TaskState::DELETE_SELECTED)
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* @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);
|
||||
}
|
72
src/wipe.cpp
72
src/wipe.cpp
|
@ -1,72 +0,0 @@
|
|||
/**
|
||||
* @file wipe.cpp
|
||||
* @brief wipe drive
|
||||
* @author hendrik schutter
|
||||
* @date 03.05.2020
|
||||
*/
|
||||
|
||||
#include "../include/reHDD.h"
|
||||
|
||||
//#define DRYRUN //if defined the drive will not be wiped, a ping cmd is attempted instead
|
||||
|
||||
/**
|
||||
* \brief wipe drive with shred
|
||||
* \param pointer of Drive instance
|
||||
* \return void
|
||||
*/
|
||||
void Wipe::wipeDrive(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");
|
||||
#endif
|
||||
const char* cpComand = sCMD.c_str();
|
||||
|
||||
cout << "wipe: " << cpComand << endl;
|
||||
|
||||
auto t_start = chrono::high_resolution_clock::now();
|
||||
|
||||
FILE* outputfileSmart = popen(cpComand, "r");
|
||||
|
||||
while ((getline(&cLine, &len, outputfileSmart)) != -1)
|
||||
{
|
||||
string sLine = string(cLine);
|
||||
cout << sLine;
|
||||
}
|
||||
fclose(outputfileSmart);
|
||||
|
||||
auto t_end = chrono::high_resolution_clock::now();
|
||||
|
||||
uint64_t u64TimeMS = chrono::duration<double, std::milli>(t_end-t_start).count();
|
||||
|
||||
uint64_t u64hours = 0U;
|
||||
uint64_t u64minutes = 0U;
|
||||
uint64_t u64seconds = 0U;
|
||||
|
||||
while(u64TimeMS >= 1000)
|
||||
{
|
||||
u64seconds++;
|
||||
u64TimeMS = u64TimeMS - 1000;
|
||||
}
|
||||
|
||||
while(u64seconds >= 60)
|
||||
{
|
||||
u64minutes++;
|
||||
u64seconds = u64seconds - 60;
|
||||
}
|
||||
|
||||
while(u64minutes >= 60)
|
||||
{
|
||||
u64hours++;
|
||||
u64minutes = u64minutes - 60;
|
||||
}
|
||||
|
||||
cout << "Elapsed time: " << u64hours << " h - " << u64minutes << " min - " << u64seconds << " sec" << endl;
|
||||
}
|
Loading…
Reference in New Issue