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

github.com/nextcloud/previewgenerator.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Steinmetz <richard@steinmetz.cloud>2021-12-06 17:08:11 +0300
committerGitHub <noreply@github.com>2021-12-06 17:08:11 +0300
commit476462dfb7479cff39d11a3936d28f20b2475a5f (patch)
tree7a55f363a94c50b2fa747058fbc46fbac0c0dbd2
parent08003189bbf95a6e213a427d7d9dc60ee9847536 (diff)
parent8a357bed1c76bef41057bd5b8e98650184b8cd00 (diff)
Merge pull request #190 from hashworks/filterExternalStorage
Skip external mounts with disabled previews
-rw-r--r--lib/Command/Generate.php45
-rw-r--r--tests/WatcherTest.php2
2 files changed, 38 insertions, 9 deletions
diff --git a/lib/Command/Generate.php b/lib/Command/Generate.php
index 78ae879..7e7663c 100644
--- a/lib/Command/Generate.php
+++ b/lib/Command/Generate.php
@@ -36,6 +36,7 @@ use OCP\IConfig;
use OCP\IPreview;
use OCP\IUser;
use OCP\IUserManager;
+use OCA\Files_External\Service\GlobalStoragesService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -43,6 +44,9 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Generate extends Command {
+
+ /** @var GlobalStoragesService */
+ protected $globalService;
/** @var IUserManager */
protected $userManager;
@@ -69,7 +73,8 @@ class Generate extends Command {
IUserManager $userManager,
IPreview $previewGenerator,
IConfig $config,
- IManager $encryptionManager) {
+ IManager $encryptionManager,
+ GlobalStoragesService $globalService = null) {
parent::__construct();
$this->userManager = $userManager;
@@ -77,6 +82,7 @@ class Generate extends Command {
$this->previewGenerator = $previewGenerator;
$this->config = $config;
$this->encryptionManager = $encryptionManager;
+ $this->globalService = $globalService;
}
protected function configure() {
@@ -133,6 +139,24 @@ class Generate extends Command {
return 0;
}
+ private function getNoPreviewMountPaths(IUser $user) {
+ if ($this->globalService === null) {
+ return [];
+ }
+ $mountPaths = [];
+ $userId = $user->getUID();
+ $mounts = $this->globalService->getStorageForAllUsers();
+ foreach ($mounts as $mount) {
+ if (in_array($userId, $mount->getApplicableUsers()) &&
+ $mount->getMountOptions()['previews'] === false
+ ) {
+ $userFolder = $this->rootFolder->getUserFolder($userId)->getPath();
+ array_push($mountPaths, $userFolder.$mount->getMountPoint());
+ }
+ }
+ return $mountPaths;
+ }
+
private function generatePathPreviews(IUser $user, string $path) {
\OC_Util::tearDownFS();
\OC_Util::setupFS($user->getUID());
@@ -144,7 +168,8 @@ class Generate extends Command {
return;
}
$pathFolder = $userFolder->get($relativePath);
- $this->parseFolder($pathFolder);
+ $noPreviewMountPaths = $this->getNoPreviewMountPaths($user);
+ $this->parseFolder($pathFolder, $noPreviewMountPaths);
}
private function generateUserPreviews(IUser $user) {
@@ -152,24 +177,28 @@ class Generate extends Command {
\OC_Util::setupFS($user->getUID());
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
- $this->parseFolder($userFolder);
+ $noPreviewMountPaths = $this->getNoPreviewMountPaths($user);
+ $this->parseFolder($userFolder, $noPreviewMountPaths);
}
- private function parseFolder(Folder $folder) {
+ private function parseFolder(Folder $folder, $noPreviewMountPaths) {
try {
+ $folderPath = $folder->getPath();
+
// Respect the '.nomedia' file. If present don't traverse the folder
- if ($folder->nodeExists('.nomedia')) {
- $this->output->writeln('Skipping folder ' . $folder->getPath());
+ // Same for external mounts with previews disabled
+ if ($folder->nodeExists('.nomedia') || in_array($folderPath, $noPreviewMountPaths)) {
+ $this->output->writeln('Skipping folder ' . $folderPath);
return;
}
- $this->output->writeln('Scanning folder ' . $folder->getPath());
+ $this->output->writeln('Scanning folder ' . $folderPath);
$nodes = $folder->getDirectoryListing();
foreach ($nodes as $node) {
if ($node instanceof Folder) {
- $this->parseFolder($node);
+ $this->parseFolder($node, $noPreviewMountPaths);
} elseif ($node instanceof File) {
$this->parseFile($node);
}
diff --git a/tests/WatcherTest.php b/tests/WatcherTest.php
index a89bbc0..18c5867 100644
--- a/tests/WatcherTest.php
+++ b/tests/WatcherTest.php
@@ -45,7 +45,7 @@ class WatcherTest extends TestCase {
/** @var Watcher */
private $watcher;
- public function setUp() {
+ public function setUp(): void {
parent::setUp();
$this->connection = \OC::$server->getDatabaseConnection();