From feed1b4a97d20b30e7e04725d299c96031bbbfc9 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 23 Jun 2024 11:11:20 +0200 Subject: [PATCH 1/4] fix deletion of dialog --- src/tui.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/tui.cpp b/src/tui.cpp index 8941c0f..9078b11 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -613,6 +613,7 @@ void TUI::vTruncateText(string *psText, uint16_t u16MaxLenght) void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY) { struct MenuState menustate; + static bool dialogIsActive; menustate.bAbort = false; menustate.bConfirmDelete = false; menustate.bConfirmShred = false; @@ -659,15 +660,21 @@ void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY) { dialog = createDialog(40, 10, ((stdscrX) - (int)(stdscrX / 3) - 7) - (int)((stdscrX / 3) + 5) / 2, (int)(stdscrY / 2) - 5, "Confirm SHRED", "Press ENTER for SHRED", "Press ESC for cancel"); wrefresh(dialog); + dialogIsActive = true; } else if (menustate.bConfirmDelete == true) { dialog = createDialog(40, 10, ((stdscrX) - (int)(stdscrX / 3) - 7) - (int)((stdscrX / 3) + 5) / 2, (int)(stdscrY / 2) - 5, "Confirm DELETE", "Press ENTER for DELETE", "Press ESC for cancel"); wrefresh(dialog); + dialogIsActive = true; } else { - delwin(dialog); + if (dialogIsActive) + { + delwin(dialog); + dialogIsActive = false; + } } } -- 2.47.1 From 1e545993b0debac81dc5053f901c69be226131f8 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sun, 23 Jun 2024 11:30:25 +0200 Subject: [PATCH 2/4] add new flag --- include/drive.h | 1 + src/reHDD.cpp | 2 +- src/shred.cpp | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/drive.h b/include/drive.h index f1e28ab..71b2d1d 100644 --- a/include/drive.h +++ b/include/drive.h @@ -34,6 +34,7 @@ public: } sShredSpeed; bool bWasShredded = false; // all shred iterations done + bool bWasShredStarted = false; // shred was atleast once started bool bWasChecked = false; // all shred iterations and optional checking done bool bWasDeleted = false; bool bIsOffline = false; diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 9338242..e05ee75 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -585,7 +585,7 @@ void reHDD::handleEnter() thread(ThreadShred, pTmpDrive).detach(); } - if (getSelectedDrive()->state == Drive::TaskState::DELETE_SELECTED) + if ((getSelectedDrive()->state == Drive::TaskState::DELETE_SELECTED) && (getSelectedDrive()->bWasShredStarted == false)) { Logger::logThis()->info("Started delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial()); getSelectedDrive()->state = Drive::TaskState::DELETE_ACTIVE; diff --git a/src/shred.cpp b/src/shred.cpp index 3cb9c48..6ae0236 100644 --- a/src/shred.cpp +++ b/src/shred.cpp @@ -36,6 +36,7 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd) ostringstream address; address << (void const *)&(*drive); Logger::logThis()->info("Shred-Task started - Drive: " + drive->getModelName() + "-" + drive->getSerial() + " @" + address.str()); + drive->bWasShredStarted = true; //Mark drive as partly shredded #ifdef DRYRUN for (int i = 0; i <= 500; i++) -- 2.47.1 From ad6a95c21bcaaa505ce3a02a906066fb6b426391 Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 16 Aug 2024 10:24:12 +0200 Subject: [PATCH 3/4] skip delete if drive was shredded before --- src/delete.cpp | 14 +++++++++----- src/reHDD.cpp | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/delete.cpp b/src/delete.cpp index b7ca4bd..94560ab 100644 --- a/src/delete.cpp +++ b/src/delete.cpp @@ -32,11 +32,15 @@ void Delete::deleteDrive(Drive *drive) const char *cpComand = sCMD.c_str(); // cout << "delete: " << cpComand << endl; - FILE *deleteCmdOutput = popen(cpComand, "r"); - - while ((getline(&cLine, &len, deleteCmdOutput)) != -1) + if (drive->bWasShredStarted == false) { - // wipefs running + //only start delete if the drive was not shredded before + FILE *deleteCmdOutput = popen(cpComand, "r"); + + while ((getline(&cLine, &len, deleteCmdOutput)) != -1) + { + // wipefs running + } + pclose(deleteCmdOutput); } - pclose(deleteCmdOutput); } diff --git a/src/reHDD.cpp b/src/reHDD.cpp index e05ee75..9338242 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -585,7 +585,7 @@ void reHDD::handleEnter() thread(ThreadShred, pTmpDrive).detach(); } - if ((getSelectedDrive()->state == Drive::TaskState::DELETE_SELECTED) && (getSelectedDrive()->bWasShredStarted == false)) + if (getSelectedDrive()->state == Drive::TaskState::DELETE_SELECTED) { Logger::logThis()->info("Started delete for: " + getSelectedDrive()->getModelName() + "-" + getSelectedDrive()->getSerial()); getSelectedDrive()->state = Drive::TaskState::DELETE_ACTIVE; -- 2.47.1 From e6dcfe09c9dd2e2ecc0547a39650d1486c1c1062 Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 16 Aug 2024 10:25:28 +0200 Subject: [PATCH 4/4] fix dryrun shred finish --- src/shred.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/shred.cpp b/src/shred.cpp index 6ae0236..d6b53c9 100644 --- a/src/shred.cpp +++ b/src/shred.cpp @@ -49,6 +49,7 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd) write(*ipSignalFd, "A", 1); usleep(20000); } + drive->bWasShredded = true; #endif #ifndef DRYRUN -- 2.47.1