From 67ebe75d0ee02977b95e43a31516d936d18514a2 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 10 Nov 2021 15:09:25 +0100 Subject: Move storage encoding compatibility warning logic The encoding check for file names is now happening the Scanner, and an event will be emitted only if the storage doesn't contain the encoding compatibility wrapper. The event is listened to by the occ scan command to be able to display a warning in case of file name mismatches when they have NFD encoding. Signed-off-by: Vincent Petry --- lib/private/Files/Cache/Scanner.php | 10 ++++++++-- lib/private/Files/Utils/Scanner.php | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php index a88d49d32c2..f31885d54a6 100644 --- a/lib/private/Files/Cache/Scanner.php +++ b/lib/private/Files/Cache/Scanner.php @@ -37,6 +37,7 @@ namespace OC\Files\Cache; use Doctrine\DBAL\Exception; use OC\Files\Filesystem; +use OC\Files\Storage\Wrapper\Encoding; use OC\Hooks\BasicEmitter; use OCP\Files\Cache\IScanner; use OCP\Files\ForbiddenException; @@ -419,8 +420,13 @@ class Scanner extends BasicEmitter implements IScanner { if ($permissions === 0) { continue; } - $file = $fileMeta['name']; - $file = trim(\OC\Files\Filesystem::normalizePath($file), '/'); + $originalFile = $fileMeta['name']; + $file = trim(\OC\Files\Filesystem::normalizePath($originalFile), '/'); + if (trim($originalFile, '/') !== $file && !$this->storage->instanceOfStorage(Encoding::class)) { + // encoding mismatch, might require compatibility wrapper + $this->emit('\OC\Files\Cache\Scanner', 'normalizedNameMismatch', [$path ? $path . '/' . $originalFile : $originalFile]); + } + $newChildNames[] = $file; $child = $path ? $path . '/' . $file : $file; try { diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php index 72a7084f40d..faeb31db8cc 100644 --- a/lib/private/Files/Utils/Scanner.php +++ b/lib/private/Files/Utils/Scanner.php @@ -145,6 +145,9 @@ class Scanner extends PublicEmitter { $this->emit('\OC\Files\Utils\Scanner', 'postScanFolder', [$mount->getMountPoint() . $path]); $this->dispatcher->dispatchTyped(new FolderScannedEvent($mount->getMountPoint() . $path)); }); + $scanner->listen('\OC\Files\Cache\Scanner', 'normalizedNameMismatch', function ($path) use ($mount) { + $this->emit('\OC\Files\Utils\Scanner', 'normalizedNameMismatch', [$path]); + }); } /** -- cgit v1.2.3