EncodingDirectoryWrapper.php 753 B

12345678910111213141516171819202122232425262728293031323334
  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. public function dir_readdir(): string|false {
  14. $file = readdir($this->source);
  15. if ($file !== false && $file !== '.' && $file !== '..') {
  16. $file = trim(Filesystem::normalizePath($file), '/');
  17. }
  18. return $file;
  19. }
  20. /**
  21. * @param resource $source
  22. * @return resource|false
  23. */
  24. public static function wrap($source) {
  25. return self::wrapSource($source, [
  26. 'source' => $source,
  27. ]);
  28. }
  29. }