EncodingDirectoryWrapper.php 888 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-only
  5. */
  6. namespace OC\Files\Storage\Wrapper;
  7. use Icewind\Streams\DirectoryWrapper;
  8. use OC\Files\Filesystem;
  9. /**
  10. * Normalize file names while reading directory entries
  11. */
  12. class EncodingDirectoryWrapper extends DirectoryWrapper {
  13. /**
  14. * @psalm-suppress ImplementedReturnTypeMismatch Until return type is fixed upstream
  15. * @return string|false
  16. */
  17. public function dir_readdir() {
  18. $file = readdir($this->source);
  19. if ($file !== false && $file !== '.' && $file !== '..') {
  20. $file = trim(Filesystem::normalizePath($file), '/');
  21. }
  22. return $file;
  23. }
  24. /**
  25. * @param resource $source
  26. * @param callable $filter
  27. * @return resource|false
  28. */
  29. public static function wrap($source) {
  30. return self::wrapSource($source, [
  31. 'source' => $source,
  32. ]);
  33. }
  34. }