Skip to content

Commit

Permalink
Use better filesystem functions (librenms#13735)
Browse files Browse the repository at this point in the history
* Use better filesystem functions

* Update DeviceObserver.php

* Update DeviceObserver.php

Co-authored-by: Tony Murray <[email protected]>
  • Loading branch information
Jellyfrog and murrant authored Feb 2, 2022
1 parent b93a892 commit 0da5457
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/Observers/DeviceObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App;
use App\ApiClients\Oxidized;
use App\Models\Device;
use Illuminate\Support\Str;
use File;
use Log;

class DeviceObserver
Expand Down Expand Up @@ -59,10 +59,15 @@ public function updated(Device $device): void
public function deleted(Device $device): void
{
// delete rrd files
$host_dir = addcslashes(escapeshellarg(\Rrd::dirFromHost($device->hostname)), '\'');
$result = trim(shell_exec("bash -c '( [ ! -d $host_dir ] || rm -vrf $host_dir 2>&1 ) && echo -n OK'"));
if (! Str::endsWith($result, 'OK')) {
Log::debug("Could not $device->hostname files: $result");
$host_dir = \Rrd::dirFromHost($device->hostname);
try {
$result = File::deleteDirectory($host_dir);

if (! $result) {
Log::debug("Could not delete RRD files for: $device->hostname");
}
} catch (\Exception $e) {
Log::error("Could not delete RRD files for: $device->hostname", [$e]);
}

Log::event("Device $device->hostname has been removed", 0, 'system', 3);
Expand Down

0 comments on commit 0da5457

Please sign in to comment.