-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make FileListener respect .nomedia #497
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d7b5a09
Chec in test_wasmtensorflow.js
marcelklehr 89cfdfa
Add bg job mode status in admin settings
marcelklehr 5ec7498
Factor out ignored directories functionality into IgnoreService
marcelklehr deb25d8
Use IgnoreService in FileListener
marcelklehr bfdc432
Test FileListener
marcelklehr 867dd08
Fix psalm errors
marcelklehr 9fc54f8
Fix FileListener
marcelklehr 199bfb4
Fix Classifier tests
marcelklehr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace OCA\Recognize\Service; | ||
|
||
use OC\Files\Cache\CacheQueryBuilder; | ||
use OC\SystemConfig; | ||
use OCA\Recognize\Constants; | ||
use OCP\DB\QueryBuilder\IQueryBuilder; | ||
use OCP\Files\IMimeTypeLoader; | ||
use OCP\IDBConnection; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class IgnoreService { | ||
private IDBConnection $db; | ||
private SystemConfig $systemConfig; | ||
private LoggerInterface $logger; | ||
private IMimeTypeLoader $mimeTypes; | ||
|
||
public function __construct(IDBConnection $db, SystemConfig $systemConfig, LoggerInterface $logger, IMimeTypeLoader $mimeTypes) { | ||
$this->db = $db; | ||
$this->systemConfig = $systemConfig; | ||
$this->logger = $logger; | ||
$this->mimeTypes = $mimeTypes; | ||
} | ||
|
||
/** | ||
* @param int $fileid | ||
* @param array $directoryTypes | ||
* @param bool $recursive | ||
* @return list<array> | ||
*/ | ||
public function getDir(int $fileid, array $directoryTypes, bool $recursive = false): array { | ||
$qb = new CacheQueryBuilder($this->db, $this->systemConfig, $this->logger); | ||
$result = $qb->selectFileCache() | ||
->andWhere($qb->expr()->in('mimetype', $qb->createNamedParameter($directoryTypes, IQueryBuilder::PARAM_INT_ARRAY))) | ||
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($fileid))) | ||
->executeQuery(); | ||
/** | ||
* @var list<array> $dir | ||
*/ | ||
$dir = $result->fetchAll(); | ||
|
||
if ($recursive) { | ||
foreach ($dir as $item) { | ||
$dir = array_merge($dir, $this->getDir((int) $item['fileid'], $directoryTypes, $recursive)); | ||
} | ||
} | ||
return $dir; | ||
} | ||
|
||
/** | ||
* @param int $storageId | ||
* @param array $ignoreMarkers | ||
* @return array | ||
*/ | ||
public function getIgnoredDirectories(int $storageId, array $ignoreMarkers): array { | ||
$directoryTypes = array_map(fn ($mimeType) => $this->mimeTypes->getId($mimeType), Constants::DIRECTORY_FORMATS); | ||
$qb = new CacheQueryBuilder($this->db, $this->systemConfig, $this->logger); | ||
$result = $qb->selectFileCache() | ||
->andWhere($qb->expr()->in('name', $qb->createNamedParameter($ignoreMarkers, IQueryBuilder::PARAM_STR_ARRAY))) | ||
->andWhere($qb->expr()->eq('storage', $qb->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) | ||
->executeQuery(); | ||
/** | ||
* @var list<array> $ignoreFiles | ||
*/ | ||
$ignoreFiles = $result->fetchAll(); | ||
$ignoreFileIds = array_map(fn ($dir): int => (int)$dir['parent'], $ignoreFiles); | ||
foreach ($ignoreFiles as $ignoreFile) { | ||
$ignoreDir = $this->getDir((int) $ignoreFile['parent'], $directoryTypes, true); | ||
$fileIds = array_map(fn ($dir): int => (int) $dir['fileid'], $ignoreDir); | ||
$ignoreFileIds = array_merge($ignoreFileIds, $fileIds); | ||
} | ||
return $ignoreFileIds; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,3 @@ | |
|
||
// load all enabled apps | ||
\OC_App::loadApps(); | ||
|
||
OC_Hook::clear(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juliushaertl Shouldn't this trigger the file event listener?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, though one thing I'm unsure is if the test boostrap properly triggers the app loading in terms of that the Application register/boot methods are called. Maybe try to set an xdebug breakpoint or dd in the Application class when running the tests to see if that one actually gets registered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem was storage ID vs numeric storage ID 🙈