From 8832c3877b9d61bd41dfab5dfc67a794f939e019 Mon Sep 17 00:00:00 2001 From: Mark Unwin Date: Wed, 31 Jul 2024 13:25:52 +1000 Subject: [PATCH] Fix issue in BenchmarksModel deleting a file. --- app/Models/BenchmarksModel.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/Models/BenchmarksModel.php b/app/Models/BenchmarksModel.php index e161f7abc..5edd93e9d 100644 --- a/app/Models/BenchmarksModel.php +++ b/app/Models/BenchmarksModel.php @@ -361,15 +361,17 @@ public function execute(int $id = 0, int $device_id = 0): array return []; } - try { - unlink('/usr/local/open-audit/other/ssg-results/' . $device_id . '_' . $id . '_' . $microtime . '_report.html'); - } catch (e) { - log_message('error', 'Cannot delete report file from open-audit/other/ssg-results. '. $e); - $this->logCreate($id, $device_id, 'error', 'Cannot delete report file. Error: ' . $e); + if (file_exists('/usr/local/open-audit/other/ssg-results/' . $device_id . '_' . $id . '_' . $microtime . '_report.html')) { + log_message('debug', 'rm command on localhost for ' . $device->attributes->name . ': ' . $parameters->command); + @unlink('/usr/local/open-audit/other/ssg-results/' . $device_id . '_' . $id . '_' . $microtime . '_report.html'); + } + + if (file_exists('/usr/local/open-audit/other/ssg-results/' . $device_id . '_' . $id . '_' . $microtime . '_report.html')) { + log_message('error', 'Cannot delete report file from open-audit/other/ssg-results.'); + $this->logCreate($id, $device_id, 'error', 'Cannot delete report file. /usr/local/open-audit/other/ssg-results/' . $device_id . '_' . $id . '_' . $microtime . '_report.html'); $this->logCreate($id, $device_id, 'info', 'Completed. Memory: ' . round((memory_get_peak_usage(false)/1024/1024), 3) . ' MiB'); return []; } - log_message('debug', 'rm command on localhost for ' . $device->attributes->name . ': ' . $parameters->command); $this->logCreate($id, $device_id, 'info', 'Processing report file.'); log_message('debug', 'Processing report file for ' . $device->attributes->name);