You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.3 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\Files\SimpleFS;
  26. use OCP\Files\File;
  27. use OCP\Files\Folder;
  28. use OCP\Files\Node;
  29. use OCP\Files\NotFoundException;
  30. use OCP\Files\SimpleFS\ISimpleFolder;
  31. class SimpleFolder implements ISimpleFolder {
  32. /** @var Folder */
  33. private $folder;
  34. /**
  35. * Folder constructor.
  36. *
  37. * @param Folder $folder
  38. */
  39. public function __construct(Folder $folder) {
  40. $this->folder = $folder;
  41. }
  42. public function getName() {
  43. return $this->folder->getName();
  44. }
  45. public function getDirectoryListing() {
  46. $listing = $this->folder->getDirectoryListing();
  47. $fileListing = array_map(function (Node $file) {
  48. if ($file instanceof File) {
  49. return new SimpleFile($file);
  50. }
  51. return null;
  52. }, $listing);
  53. $fileListing = array_filter($fileListing);
  54. return array_values($fileListing);
  55. }
  56. public function delete() {
  57. $this->folder->delete();
  58. }
  59. public function fileExists($name) {
  60. return $this->folder->nodeExists($name);
  61. }
  62. public function getFile($name) {
  63. $file = $this->folder->get($name);
  64. if (!($file instanceof File)) {
  65. throw new NotFoundException();
  66. }
  67. return new SimpleFile($file);
  68. }
  69. public function newFile($name, $content = null) {
  70. if ($content === null) {
  71. // delay creating the file until it's written to
  72. return new NewSimpleFile($this->folder, $name);
  73. } else {
  74. $file = $this->folder->newFile($name, $content);
  75. return new SimpleFile($file);
  76. }
  77. }
  78. }