Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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 <[email protected]>
  • Loading branch information
PVince81 committed Nov 17, 2021
commit 67ebe75d0ee02977b95e43a31516d936d18514a2
17 changes: 2 additions & 15 deletions apps/files/lib/Command/Scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,6 @@ protected function configure() {
);
}

public function checkScanWarning($fullPath, OutputInterface $output) {
$normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath));
$path = basename($fullPath);

if ($normalizedPath !== $path) {
$output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>');
}
}

protected function scanFiles($user, $path, OutputInterface $output, $backgroundScan = false, $recursive = true, $homeOnly = false) {
$connection = $this->reconnectToDatabase($output);
$scanner = new \OC\Files\Utils\Scanner(
Expand Down Expand Up @@ -141,12 +132,8 @@ protected function scanFiles($user, $path, OutputInterface $output, $backgroundS
$output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')', OutputInterface::VERBOSITY_VERBOSE);
});

$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
$this->checkScanWarning($path, $output);
});

$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) {
$this->checkScanWarning($path, $output);
$scanner->listen('\OC\Files\Utils\Scanner', 'normalizedNameMismatch', function ($fullPath) use ($output) {
$output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>');
});

try {
Expand Down
17 changes: 2 additions & 15 deletions apps/files/lib/Command/ScanAppData.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ protected function configure() {
$this->addArgument('folder', InputArgument::OPTIONAL, 'The appdata subfolder to scan', '');
}

public function checkScanWarning($fullPath, OutputInterface $output) {
$normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath));
$path = basename($fullPath);

if ($normalizedPath !== $path) {
$output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>');
}
}

protected function scanFiles(OutputInterface $output, string $folder): int {
try {
$appData = $this->getAppDataFolder();
Expand Down Expand Up @@ -124,12 +115,8 @@ protected function scanFiles(OutputInterface $output, string $folder): int {
$output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')', OutputInterface::VERBOSITY_VERBOSE);
});

$scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) {
$this->checkScanWarning($path, $output);
});

$scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) {
$this->checkScanWarning($path, $output);
$scanner->listen('\OC\Files\Utils\Scanner', 'normalizedNameMismatch', function ($fullPath) use ($output) {
$output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>');
});

try {
Expand Down
10 changes: 8 additions & 2 deletions lib/private/Files/Cache/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

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;
Expand Down Expand Up @@ -419,8 +420,13 @@ private function handleChildren($path, $recursive, $reuse, $folderId, $lock, &$s
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 {
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Files/Utils/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ protected function attachListener($mount) {
$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]);
});
}

/**
Expand Down