Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-10-08 22:31:29 +0300
committerGitHub <noreply@github.com>2018-10-08 22:31:29 +0300
commit1178e852068cc220e6d27757c7db79709a602971 (patch)
treed54bdb12759d481174f7588e5b3ce8eadbcc491d
parent6994a2a87d691b3bf869219cb21ca2ae6625a8d5 (diff)
parent311de17730174dae1f951bdf38a657e6c5453574 (diff)
Merge pull request #11664 from nextcloud/feature/noid/has-been-interrupted-throw-exception
Syntactic sugar for hasBeenInterrupted
-rw-r--r--apps/files/lib/Command/Scan.php26
-rw-r--r--apps/files/lib/Command/ScanAppData.php20
-rw-r--r--core/Command/Base.php20
3 files changed, 28 insertions, 38 deletions
diff --git a/apps/files/lib/Command/Scan.php b/apps/files/lib/Command/Scan.php
index 36fa39e043d..a50d9abfc3d 100644
--- a/apps/files/lib/Command/Scan.php
+++ b/apps/files/lib/Command/Scan.php
@@ -129,33 +129,25 @@ class Scan extends Base {
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
$output->writeln("\tFile <info>$path</info>");
$this->filesCounter += 1;
- if ($this->hasBeenInterrupted()) {
- throw new InterruptedException();
- }
+ $this->abortIfInterrupted();
});
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) {
$output->writeln("\tFolder <info>$path</info>");
$this->foldersCounter += 1;
- if ($this->hasBeenInterrupted()) {
- throw new InterruptedException();
- }
+ $this->abortIfInterrupted();
});
$scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) {
- $output->writeln("Error while scanning, storage not available (" . $e->getMessage() . ")");
+ $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')');
});
# count only
} else {
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) {
$this->filesCounter += 1;
- if ($this->hasBeenInterrupted()) {
- throw new InterruptedException();
- }
+ $this->abortIfInterrupted();
});
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) {
$this->foldersCounter += 1;
- if ($this->hasBeenInterrupted()) {
- throw new InterruptedException();
- }
+ $this->abortIfInterrupted();
});
}
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
@@ -173,7 +165,7 @@ class Scan extends Base {
}
} catch (ForbiddenException $e) {
$output->writeln("<error>Home storage for user $user not writable</error>");
- $output->writeln("Make sure you're running the scan command only as the user the web server runs as");
+ $output->writeln('Make sure you\'re running the scan command only as the user the web server runs as');
} catch (InterruptedException $e) {
# exit the function if ctrl-c has been pressed
$output->writeln('Interrupted by user');
@@ -250,8 +242,10 @@ class Scan extends Base {
} else {
$output->writeln("<error>Unknown user $user_count $user</error>");
}
- # check on each user if there was a user interrupt (ctrl-c) and exit foreach
- if ($this->hasBeenInterrupted()) {
+
+ try {
+ $this->abortIfInterrupted();
+ } catch(InterruptedException $e) {
break;
}
}
diff --git a/apps/files/lib/Command/ScanAppData.php b/apps/files/lib/Command/ScanAppData.php
index 1eb22d5f68a..988bcd1e62f 100644
--- a/apps/files/lib/Command/ScanAppData.php
+++ b/apps/files/lib/Command/ScanAppData.php
@@ -102,33 +102,25 @@ class ScanAppData extends Base {
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
$output->writeln("\tFile <info>$path</info>");
$this->filesCounter += 1;
- if ($this->hasBeenInterrupted()) {
- throw new InterruptedException();
- }
+ $this->abortIfInterrupted();
});
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) {
$output->writeln("\tFolder <info>$path</info>");
$this->foldersCounter += 1;
- if ($this->hasBeenInterrupted()) {
- throw new InterruptedException();
- }
+ $this->abortIfInterrupted();
});
$scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) {
- $output->writeln("Error while scanning, storage not available (" . $e->getMessage() . ")");
+ $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')');
});
# count only
} else {
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) {
$this->filesCounter += 1;
- if ($this->hasBeenInterrupted()) {
- throw new InterruptedException();
- }
+ $this->abortIfInterrupted();
});
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) {
$this->foldersCounter += 1;
- if ($this->hasBeenInterrupted()) {
- throw new InterruptedException();
- }
+ $this->abortIfInterrupted();
});
}
$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) {
@@ -142,7 +134,7 @@ class ScanAppData extends Base {
$scanner->scan($appData->getPath());
} catch (ForbiddenException $e) {
$output->writeln("<error>Storage not writable</error>");
- $output->writeln("Make sure you're running the scan command only as the user the web server runs as");
+ $output->writeln('Make sure you\'re running the scan command only as the user the web server runs as');
} catch (InterruptedException $e) {
# exit the function if ctrl-c has been pressed
$output->writeln('Interrupted by user');
diff --git a/core/Command/Base.php b/core/Command/Base.php
index dbf6c71b8f4..4eca5bcaab7 100644
--- a/core/Command/Base.php
+++ b/core/Command/Base.php
@@ -129,15 +129,19 @@ class Base extends Command implements CompletionAwareInterface {
}
/**
- * @return bool
+ * Throw InterruptedException when interrupted by user
+ *
+ * @throws InterruptedException
*/
- protected function hasBeenInterrupted() {
- // return always false if pcntl_signal functions are not accessible
- if ($this->php_pcntl_signal) {
- pcntl_signal_dispatch();
- return $this->interrupted;
- } else {
- return false;
+ protected function abortIfInterrupted() {
+ if ($this->php_pcntl_signal === false) {
+ return;
+ }
+
+ pcntl_signal_dispatch();
+
+ if ($this->interrupted === true) {
+ throw new InterruptedException('Command interrupted by user');
}
}