fixed bug with filtering new attached drives
This commit is contained in:
parent
938f267813
commit
cb361acfd4
@ -23,6 +23,7 @@ public:
|
|||||||
|
|
||||||
bool bWasShredded = false;
|
bool bWasShredded = false;
|
||||||
bool bWasDeleteted = false;
|
bool bWasDeleteted = false;
|
||||||
|
bool bIsOffline = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string sPath;
|
string sPath;
|
||||||
@ -36,6 +37,7 @@ private:
|
|||||||
|
|
||||||
double d32TaskPercentage = 0U; //in percent for Shred (1 to 100)
|
double d32TaskPercentage = 0U; //in percent for Shred (1 to 100)
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -74,8 +74,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//static Logger* logging;
|
|
||||||
|
|
||||||
static void searchDrives(vector <Drive>* pvecDrives);
|
static void searchDrives(vector <Drive>* pvecDrives);
|
||||||
static void printDrives(vector <Drive>* pvecDrives);
|
static void printDrives(vector <Drive>* pvecDrives);
|
||||||
static void filterIgnoredDrives(vector <Drive>* pvecDrives);
|
static void filterIgnoredDrives(vector <Drive>* pvecDrives);
|
||||||
|
@ -13,7 +13,7 @@ static int fdShredInformPipe[2];//File descriptor for pipe that informs if a wip
|
|||||||
|
|
||||||
static std::mutex mxScannDrives;
|
static std::mutex mxScannDrives;
|
||||||
|
|
||||||
static vector <Drive> vecNewDrives; //store found drives that are updated every 5sec
|
vector <Drive> vecNewDrives; //store found drives that are updated every 5sec
|
||||||
|
|
||||||
static vector <Drive> vecDrives; //stores all drive data from scann thread
|
static vector <Drive> vecDrives; //stores all drive data from scann thread
|
||||||
|
|
||||||
@ -33,6 +33,8 @@ static fd_set selectSet;
|
|||||||
reHDD::reHDD(void)
|
reHDD::reHDD(void)
|
||||||
{
|
{
|
||||||
u8SelectedEntry = 0U;
|
u8SelectedEntry = 0U;
|
||||||
|
|
||||||
|
vecDrives.reserve(128);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,8 +66,8 @@ void reHDD::app_logic(void)
|
|||||||
char dummy;
|
char dummy;
|
||||||
read (fdNewDrivesInformPipe[0],&dummy,1);
|
read (fdNewDrivesInformPipe[0],&dummy,1);
|
||||||
mxScannDrives.lock();
|
mxScannDrives.lock();
|
||||||
|
|
||||||
filterNewDrives(&vecDrives, &vecNewDrives); //filter and copy to app logic vector
|
filterNewDrives(&vecDrives, &vecNewDrives); //filter and copy to app logic vector
|
||||||
|
printDrives(&vecDrives);
|
||||||
mxScannDrives.unlock();
|
mxScannDrives.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +106,6 @@ void reHDD::ThreadScannDevices()
|
|||||||
addSMARTData(&vecNewDrives); //add S.M.A.R.T. Data to the drives
|
addSMARTData(&vecNewDrives); //add S.M.A.R.T. Data to the drives
|
||||||
mxScannDrives.unlock();
|
mxScannDrives.unlock();
|
||||||
write(fdNewDrivesInformPipe[1], "A",1);
|
write(fdNewDrivesInformPipe[1], "A",1);
|
||||||
printDrives(&vecNewDrives);
|
|
||||||
sleep(5); //sleep 5 sec
|
sleep(5); //sleep 5 sec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,35 +191,64 @@ void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecN
|
|||||||
vector <Drive>::iterator itOld; //Iterator for current (old) drive list
|
vector <Drive>::iterator itOld; //Iterator for current (old) drive list
|
||||||
vector <Drive>::iterator itNew; //Iterator for new drive list that was created from to scann thread
|
vector <Drive>::iterator itNew; //Iterator for new drive list that was created from to scann thread
|
||||||
|
|
||||||
|
//remove offline old drives from previously run
|
||||||
|
for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end();)
|
||||||
|
{
|
||||||
|
if(itOld->bIsOffline == true)
|
||||||
|
{
|
||||||
|
Logger::logThis()->warning("Offline drive found: " + itOld->getPath());
|
||||||
|
itOld = pvecOldDrives->erase(itOld);
|
||||||
|
/*
|
||||||
|
if(pvecOldDrives->size() > 0){ //This can be a risk if the user starts a task for the selected drive and the selected drive changes
|
||||||
|
u8SelectedEntry = 0U;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++itOld;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//search offline drives and mark them
|
||||||
for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end(); ++itOld)
|
for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end(); ++itOld)
|
||||||
{
|
{
|
||||||
bool bOldDriveIsOffline = true;
|
itOld->bIsOffline = true; //set offline befor seachring in the new list
|
||||||
for (itNew = pvecNewDrives->begin(); itNew != pvecNewDrives->end(); ++itNew)
|
for (itNew = pvecNewDrives->begin(); itNew != pvecNewDrives->end();)
|
||||||
{
|
{
|
||||||
if(itOld->getSerial() == itNew->getSerial())
|
if(itOld->getSerial() == itNew->getSerial())
|
||||||
{
|
{
|
||||||
bOldDriveIsOffline = false;
|
itOld->bIsOffline = false; //drive is still attached
|
||||||
// copy old drive instance date in new instance
|
#ifdef LOG_LEVEL_HIGH
|
||||||
itNew->state = itOld->state; //copy state
|
Logger::logThis()->info("Delete new drive, because allready attached: " + itNew->getModelName());
|
||||||
itNew->setTaskPercentage(itOld->getTaskPercentage()); //copy percentage
|
#endif
|
||||||
itNew->bWasDeleteted = itOld->bWasDeleteted; //copy finished task delete
|
itNew = pvecNewDrives->erase(itNew); //This drive is allready attached, remove from new list
|
||||||
itNew->bWasShredded = itOld->bWasShredded; //copy finished task shred
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++itNew;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(bOldDriveIsOffline == true)
|
//mark offline old drives
|
||||||
|
for (itOld = pvecOldDrives->begin(); itOld != pvecOldDrives->end(); ++itOld)
|
||||||
|
{
|
||||||
|
if(itOld->bIsOffline == true)
|
||||||
{
|
{
|
||||||
//cout << "offline drive found: " << itOld->getPath() << endl;
|
//cout << "offline drive found: " << itOld->getPath() << endl;
|
||||||
Logger::logThis()->warning("offline drive found delete for: " + itOld->getPath());
|
Logger::logThis()->warning("Mark offline drive found: " + itOld->getPath());
|
||||||
itOld->state = Drive::NONE;
|
itOld->state = Drive::NONE; //clear state --> shred task will terminate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pvecOldDrives->clear();
|
//add new drives to drive list
|
||||||
for (long unsigned int i=0; i<pvecNewDrives->size(); i++)
|
for (itNew = pvecNewDrives->begin(); itNew != pvecNewDrives->end(); ++itNew)
|
||||||
{
|
{
|
||||||
pvecOldDrives->push_back((*pvecNewDrives)[i]);
|
pvecOldDrives->push_back(pvecNewDrives->at(itNew - pvecNewDrives->begin()));
|
||||||
|
Logger::logThis()->info("Add new drive: " + itNew->getModelName());
|
||||||
}
|
}
|
||||||
|
pvecNewDrives->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -246,6 +276,7 @@ void reHDD::searchDrives(vector <Drive>* pvecDrives)
|
|||||||
{
|
{
|
||||||
Drive* tmpDrive = new Drive(string(cLine).substr (2,8));
|
Drive* tmpDrive = new Drive(string(cLine).substr (2,8));
|
||||||
tmpDrive->state = Drive::NONE;
|
tmpDrive->state = Drive::NONE;
|
||||||
|
tmpDrive->bIsOffline = false;
|
||||||
pvecDrives->push_back(*tmpDrive);
|
pvecDrives->push_back(*tmpDrive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -361,7 +392,12 @@ void reHDD::printDrives(vector <Drive>* pvecDrives)
|
|||||||
cout << "PowerCycle: " << it->getPowerCycles() << endl;
|
cout << "PowerCycle: " << it->getPowerCycles() << endl;
|
||||||
cout << "ErrorCount: " << it->getErrorCount() << endl;
|
cout << "ErrorCount: " << it->getErrorCount() << endl;
|
||||||
cout << endl;*/
|
cout << endl;*/
|
||||||
Logger::logThis()->info(to_string(it - pvecDrives->begin()) + ": " + it->getPath() + " - " + it->getModelFamily() + " - " + it->getSerial());
|
|
||||||
|
ostringstream address;
|
||||||
|
address << (void const *)&pvecDrives->at(it - pvecDrives->begin());
|
||||||
|
|
||||||
|
|
||||||
|
Logger::logThis()->info(to_string(it - pvecDrives->begin()) + ": " + it->getPath() + " - " + it->getModelFamily() + " - " + it->getSerial() + " @" + address.str());
|
||||||
}
|
}
|
||||||
Logger::logThis()->info("---------------------------------");
|
Logger::logThis()->info("---------------------------------");
|
||||||
//cout << "---------------------------------" << endl;
|
//cout << "---------------------------------" << endl;
|
||||||
@ -463,7 +499,7 @@ void reHDD::handleAbort()
|
|||||||
if(getSelectedDrive()->state == Drive::SHRED_ACTIVE || getSelectedDrive()->state == Drive::DELETE_ACTIVE )
|
if(getSelectedDrive()->state == Drive::SHRED_ACTIVE || getSelectedDrive()->state == Drive::DELETE_ACTIVE )
|
||||||
{
|
{
|
||||||
getSelectedDrive()->state = Drive::NONE;
|
getSelectedDrive()->state = Drive::NONE;
|
||||||
Logger::logThis()->info("Abort-Shred for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial());
|
Logger::logThis()->info("Abort-Shred-Signal for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial());
|
||||||
//task for drive is running --> remove selection
|
//task for drive is running --> remove selection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,7 @@ _return:
|
|||||||
drive->bWasShredded = true;
|
drive->bWasShredded = true;
|
||||||
drive->state= Drive::NONE;
|
drive->state= Drive::NONE;
|
||||||
drive->setTaskPercentage(0);
|
drive->setTaskPercentage(0);
|
||||||
Logger::logThis()->info("Finished shred for: " + drive->getModelName() + "-" + drive->getSerial());
|
Logger::logThis()->info("Finished shred for: " + drive->getModelName() + "-" + drive->getSerial());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef DRYRUN
|
#ifndef DRYRUN
|
||||||
|
Loading…
Reference in New Issue
Block a user