Skip to content

Commit

Permalink
🐛 bug fix for #294 (#295)
Browse files Browse the repository at this point in the history
* 🐛 bug fix for #294

* 🚨 Apply fixes from StyleCI (#296)
  • Loading branch information
carbontwelve authored Jan 17, 2018
1 parent da1d36c commit ba9ab7b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/Console/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Console/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class ServeCommand extends Command
*/
private $tapestry;

/**
* Should this command block additional execution?
* @var bool
*/
protected $shouldLock = false;

/**
* ServeCommand constructor.
*
Expand Down

0 comments on commit ba9ab7b

Please sign in to comment.