diff --git a/src/Console/Commands/Command.php b/src/Console/Commands/Command.php index b64402f..6539c81 100644 --- a/src/Console/Commands/Command.php +++ b/src/Console/Commands/Command.php @@ -22,6 +22,12 @@ abstract class Command extends SymfonyCommand */ protected $output; + /** + * Should this command block additional execution? + * @var bool + */ + protected $shouldLock = true; + /** * @param InputInterface $input * @param OutputInterface $output @@ -34,19 +40,23 @@ public function execute(InputInterface $input, OutputInterface $output) $this->input = $input; $this->output = $output; - $lockFilePathname = $this->input->getOption('site-dir').DIRECTORY_SEPARATOR.'.lock'; - $lockFile = fopen($lockFilePathname, 'w+'); + if ($this->shouldLock === true) { + $lockFilePathname = $this->input->getOption('site-dir').DIRECTORY_SEPARATOR.'.lock'; + $lockFile = fopen($lockFilePathname, 'w+'); + + if (flock($lockFile, LOCK_EX | LOCK_NB)) { + $result = (int) $this->fire(); + } else { + fclose($lockFile); + throw new LockException('Tapestry is already running; please wait for the previous process to complete or delete the .lock file.'); + } - if (flock($lockFile, LOCK_EX | LOCK_NB)) { - $result = (int) $this->fire(); - } else { fclose($lockFile); - throw new LockException('Tapestry is already running; please wait for the previous process to complete or delete the .lock file.'); + unlink($lockFilePathname); + } else { + $result = (int) $this->fire(); } - fclose($lockFile); - unlink($lockFilePathname); - if (defined('TAPESTRY_START') === true && $this->input->getOption('stopwatch')) { $this->renderStopwatchReport($output); } diff --git a/src/Console/Commands/ServeCommand.php b/src/Console/Commands/ServeCommand.php index b8836a4..790d332 100644 --- a/src/Console/Commands/ServeCommand.php +++ b/src/Console/Commands/ServeCommand.php @@ -15,6 +15,12 @@ class ServeCommand extends Command */ private $tapestry; + /** + * Should this command block additional execution? + * @var bool + */ + protected $shouldLock = false; + /** * ServeCommand constructor. *