🎨 check-backup : improve code readability

move exit conditions on top to avoid if/else nightmare
This commit is contained in:
Pierre Goiffon
2018-11-23 17:57:39 +01:00
parent 8530db347b
commit 44d7abac6e

View File

@@ -214,14 +214,31 @@ catch(Exception $e)
$sZipArchiveFile = MakeArchiveFileName().'.tar.gz'; $sZipArchiveFile = MakeArchiveFileName().'.tar.gz';
echo date('Y-m-d H:i:s')." - Checking file: $sZipArchiveFile\n"; echo date('Y-m-d H:i:s')." - Checking file: $sZipArchiveFile\n";
if (file_exists($sZipArchiveFile)) if (!file_exists($sZipArchiveFile))
{ {
if ($aStat = stat($sZipArchiveFile)) RaiseAlarm("Missing backup file '$sZipArchiveFile'");
return;
}
$aStat = stat($sZipArchiveFile);
if (!$aStat)
{ {
RaiseAlarm("Failed to stat backup file '$sZipArchiveFile'");
return;
}
$iSize = (int)$aStat['size']; $iSize = (int)$aStat['size'];
$iMIN = utils::ReadParam('check_size_min', 0); $iMIN = utils::ReadParam('check_size_min', 0);
if ($iSize > $iMIN) if ($iSize <= $iMIN)
{ {
RaiseAlarm("Backup file '$sZipArchiveFile' too small (Found: $iSize, while expecting $iMIN bytes)");
return;
}
echo "Found the archive\n"; echo "Found the archive\n";
$sOldArchiveFile = MakeArchiveFileName(time() - 86400).'.tar.gz'; // yesterday's archive $sOldArchiveFile = MakeArchiveFileName(time() - 86400).'.tar.gz'; // yesterday's archive
if (file_exists($sOldArchiveFile)) if (file_exists($sOldArchiveFile))
@@ -248,20 +265,3 @@ if (file_exists($sZipArchiveFile))
} }
} }
} }
}
else
{
RaiseAlarm("Backup file '$sZipArchiveFile' too small (Found: $iSize, while expecting $iMIN bytes)");
}
}
else
{
RaiseAlarm("Failed to stat backup file '$sZipArchiveFile'");
}
}
else
{
RaiseAlarm("Missing backup file '$sZipArchiveFile'");
}
?>