extrahd.cgi: Abort if a device could not be umounted.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Stefan Schantl
2023-08-01 17:48:30 +02:00
committed by Michael Tremer
parent 56ce3e19e6
commit 94aeac8a05

View File

@@ -146,33 +146,35 @@ if ($extrahdsettings{'ACTION'} eq $Lang::tr{'add'}) {
# #
} elsif ($extrahdsettings{'ACTION'} eq $Lang::tr{'delete'}) { } elsif ($extrahdsettings{'ACTION'} eq $Lang::tr{'delete'}) {
# Call helper binary to unmount the device. # Call helper binary to unmount the device.
&General::system("/usr/local/bin/extrahdctrl", "umount", "$extrahdsettings{'PATH'}"); unless(&General::system("/usr/local/bin/extrahdctrl", "umount", "$extrahdsettings{'PATH'}")) {
# Open the device file for reading.
open(FILE, "< $devicefile" ) or die "Unable to read $devicefile";
# Open the device file for reading. # Read the file content into a temporary array.
open(FILE, "< $devicefile" ) or die "Unable to read $devicefile"; my @tmp = <FILE>;
# Read the file content into a temporary array. # Close file handle.
my @tmp = <FILE>; close(FILE);
# Close file handle. # Re-open device file for writing.
close(FILE); open(FILE, "> $devicefile" ) or die "Unable to write $devicefile";
# Re-open device file for writing. # Loop through the previous read file content.
open(FILE, "> $devicefile" ) or die "Unable to write $devicefile"; foreach my $line (sort @tmp) {
# Split line content and assign nice variables.
my ($uuid, $fs, $path) = split( /\;/, $line );
# Loop through the previous read file content. # Write the line in case it does not contain our element to delete.
foreach my $line (sort @tmp) { if ($path ne $extrahdsettings{'PATH'}) {
# Split line content and assign nice variables. print FILE "$line";
my ($uuid, $fs, $path) = split( /\;/, $line ); }
# Write the line in case it does not contain our element to delete.
if ($path ne $extrahdsettings{'PATH'}) {
print FILE "$line";
} }
}
# Close file handle. # Close file handle.
close(FILE); close(FILE);
} else {
$errormessage = "$Lang::tr{'extrahd cant umount'} $extrahdsettings{'PATH'}$Lang::tr{'extrahd maybe the device is in use'}?";
}
} }
if ($errormessage) { if ($errormessage) {