fixed bug with filtering new attached drives

This commit is contained in:
Hendrik Schutter 2020-09-09 16:11:25 +02:00
parent 938f267813
commit cb361acfd4
4 changed files with 58 additions and 22 deletions

View File

@ -23,6 +23,7 @@ public:
bool bWasShredded = false;
bool bWasDeleteted = false;
bool bIsOffline = false;
private:
string sPath;
@ -36,6 +37,7 @@ private:
double d32TaskPercentage = 0U; //in percent for Shred (1 to 100)
protected:
public:

View File

@ -74,8 +74,6 @@ public:
private:
//static Logger* logging;
static void searchDrives(vector <Drive>* pvecDrives);
static void printDrives(vector <Drive>* pvecDrives);
static void filterIgnoredDrives(vector <Drive>* pvecDrives);

View File

@ -13,7 +13,7 @@ static int fdShredInformPipe[2];//File descriptor for pipe that informs if a wip
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
@ -33,6 +33,8 @@ static fd_set selectSet;
reHDD::reHDD(void)
{
u8SelectedEntry = 0U;
vecDrives.reserve(128);
}
/**
@ -64,8 +66,8 @@ void reHDD::app_logic(void)
char dummy;
read (fdNewDrivesInformPipe[0],&dummy,1);
mxScannDrives.lock();
filterNewDrives(&vecDrives, &vecNewDrives); //filter and copy to app logic vector
printDrives(&vecDrives);
mxScannDrives.unlock();
}
@ -104,7 +106,6 @@ void reHDD::ThreadScannDevices()
addSMARTData(&vecNewDrives); //add S.M.A.R.T. Data to the drives
mxScannDrives.unlock();
write(fdNewDrivesInformPipe[1], "A",1);
printDrives(&vecNewDrives);
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 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)
{
bool bOldDriveIsOffline = true;
for (itNew = pvecNewDrives->begin(); itNew != pvecNewDrives->end(); ++itNew)
itOld->bIsOffline = true; //set offline befor seachring in the new list
for (itNew = pvecNewDrives->begin(); itNew != pvecNewDrives->end();)
{
if(itOld->getSerial() == itNew->getSerial())
{
bOldDriveIsOffline = false;
// copy old drive instance date in new instance
itNew->state = itOld->state; //copy state
itNew->setTaskPercentage(itOld->getTaskPercentage()); //copy percentage
itNew->bWasDeleteted = itOld->bWasDeleteted; //copy finished task delete
itNew->bWasShredded = itOld->bWasShredded; //copy finished task shred
itOld->bIsOffline = false; //drive is still attached
#ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("Delete new drive, because allready attached: " + itNew->getModelName());
#endif
itNew = pvecNewDrives->erase(itNew); //This drive is allready attached, remove from new list
}
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;
Logger::logThis()->warning("offline drive found delete for: " + itOld->getPath());
itOld->state = Drive::NONE;
Logger::logThis()->warning("Mark offline drive found: " + itOld->getPath());
itOld->state = Drive::NONE; //clear state --> shred task will terminate
}
}
pvecOldDrives->clear();
for (long unsigned int i=0; i<pvecNewDrives->size(); i++)
//add new drives to drive list
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));
tmpDrive->state = Drive::NONE;
tmpDrive->bIsOffline = false;
pvecDrives->push_back(*tmpDrive);
}
}
@ -361,7 +392,12 @@ void reHDD::printDrives(vector <Drive>* pvecDrives)
cout << "PowerCycle: " << it->getPowerCycles() << endl;
cout << "ErrorCount: " << it->getErrorCount() << 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("---------------------------------");
//cout << "---------------------------------" << endl;
@ -463,7 +499,7 @@ void reHDD::handleAbort()
if(getSelectedDrive()->state == Drive::SHRED_ACTIVE || getSelectedDrive()->state == Drive::DELETE_ACTIVE )
{
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
}
}

View File

@ -288,7 +288,7 @@ _return:
drive->bWasShredded = true;
drive->state= Drive::NONE;
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