Skip to content

Commit fa6d8dc

Browse files
authored
Merge pull request #8 from dotkernel/issue-7
Issue #7: Fixed command that lists all commands.
2 parents 6aa9508 + 6c4560c commit fa6d8dc

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __destruct()
4545
*/
4646
public function doRun(InputInterface $input, OutputInterface $output): int
4747
{
48-
$this->fileLocker->setCommandName($this->getCommandName($input))->initLockFile();
48+
$this->fileLocker->setCommandName($this->getCommandName($input));
4949

5050
try {
5151
$this->fileLocker->lock();

src/FileLocker.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ class FileLocker implements FileLockerInterface
3232
*/
3333
public function initLockFile(): self
3434
{
35-
if ($this->enabled) {
36-
$this->lockFile = fopen($this->getLockFilePath(), 'w+');
37-
}
35+
$this->lockFile = fopen($this->getLockFilePath(), 'w+');
36+
3837
return $this;
3938
}
4039

@@ -135,6 +134,12 @@ public function lock(): void
135134
return;
136135
}
137136

137+
if (empty($this->commandName)) {
138+
return;
139+
}
140+
141+
$this->initLockFile();
142+
138143
if (!flock($this->lockFile, LOCK_EX|LOCK_NB, $wouldBlock)) {
139144
if ($wouldBlock) {
140145
throw new \Exception('Another process holds the lock!');
@@ -150,7 +155,11 @@ public function unlock(): void
150155
if (!$this->enabled) {
151156
return;
152157
}
153-
158+
159+
if (empty($this->commandName)) {
160+
return;
161+
}
162+
154163
flock($this->lockFile, LOCK_UN);
155164
fclose($this->lockFile);
156165
}

0 commit comments

Comments
 (0)