Browse Source

Start filling out PID file exceptions

rpm
J. King 3 years ago
parent
commit
9595c4f019
  1. 4
      lib/AbstractException.php
  2. 8
      lib/CLI.php
  3. 10
      lib/CLI/Exception.php
  4. 6
      locale/en.php

4
lib/AbstractException.php

@ -102,6 +102,10 @@ abstract class AbstractException extends \Exception {
"ImportExport/Exception.invalidFolderCopy" => 10614, "ImportExport/Exception.invalidFolderCopy" => 10614,
"ImportExport/Exception.invalidTagName" => 10615, "ImportExport/Exception.invalidTagName" => 10615,
"Rule/Exception.invalidPattern" => 10701, "Rule/Exception.invalidPattern" => 10701,
"CLI/Exception.pidNotFile" => 10801,
"CLI/Exception.pidDirNotFound" => 10802,
"CLI/Exception.pidUnwritable" => 10803,
"CLI/Exception.pidUncreatable" => 10804,
]; ];
protected $symbol; protected $symbol;

8
lib/CLI.php

@ -331,24 +331,24 @@ USAGE_TEXT;
} }
/** Resolves the PID file path and ensures the file or parent directory is writable */ /** Resolves the PID file path and ensures the file or parent directory is writable */
protected function resolvePID(string $pidfile): string { public function resolvePID(string $pidfile): string {
$dir = dirname($pidfile); $dir = dirname($pidfile);
$file = basename($pidfile); $file = basename($pidfile);
if (!strlen($file)) { if (!strlen($file)) {
throw new \Exception("Specified PID file location must be a regular file"); throw new CLI\Exception("pidNotFile", ['pidfile' => $dir]);
} elseif ($base = @realpath($dir)) { } elseif ($base = @realpath($dir)) {
$out = "$base/$file"; $out = "$base/$file";
if (file_exists($out)) { if (file_exists($out)) {
if (!is_writable($out)) { if (!is_writable($out)) {
throw new \Exception("PID file is not writable"); throw new \Exception("PID file is not writable");
} elseif (!is_file($out)) { } elseif (!is_file($out)) {
throw new \Exception("Specified PID file location must be a regular file"); throw new CLI\Exception("pidNotFile", ['pidfile' => $out]);
} }
} elseif (!is_writable($base)) { } elseif (!is_writable($base)) {
throw new \Exception("Cannot create PID file"); throw new \Exception("Cannot create PID file");
} }
} else { } else {
throw new \Exception("Parent directory of PID file does not exist"); throw new \Exception("pidDirNotFound", ['piddir' => $dir]);
} }
return $out; return $out;
} }

10
lib/CLI/Exception.php

@ -0,0 +1,10 @@
<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\CLI;
class Exception extends \JKingWeb\Arsse\AbstractException {
}

6
locale/en.php

@ -207,5 +207,9 @@ return [
'Exception.JKingWeb/Arsse/ImportExport/Exception.invalidFolderName' => 'Input data contains an invalid folder name', 'Exception.JKingWeb/Arsse/ImportExport/Exception.invalidFolderName' => 'Input data contains an invalid folder name',
'Exception.JKingWeb/Arsse/ImportExport/Exception.invalidFolderCopy' => 'Input data contains multiple folders of the same name under the same parent', 'Exception.JKingWeb/Arsse/ImportExport/Exception.invalidFolderCopy' => 'Input data contains multiple folders of the same name under the same parent',
'Exception.JKingWeb/Arsse/ImportExport/Exception.invalidTagName' => 'Input data contains an invalid tag name', 'Exception.JKingWeb/Arsse/ImportExport/Exception.invalidTagName' => 'Input data contains an invalid tag name',
'Exception.JKingWeb/Arsse/Rule/Exception.invalidPattern' => 'Specified rule pattern is invalid' 'Exception.JKingWeb/Arsse/Rule/Exception.invalidPattern' => 'Specified rule pattern is invalid',
'Exception.JKingWeb/Arsse/CLI/Exception.pidNotFile' => 'Specified PID file location "{pidfile}" must be a regular file',
'Exception.JKingWeb/Arsse/CLI/Exception.pidDirNotFound' => 'Parent directory "{piddir}" of PID file does not exist',
'Exception.JKingWeb/Arsse/CLI/Exception.pidUnwritable' => 'Insufficient permissions to open PID file "{pidfile}" for writing',
'Exception.JKingWeb/Arsse/CLI/Exception.pidNotFile' => 'Specified PID file location "{pidfile}" must be a regular file',
]; ];

Loading…
Cancel
Save