DavUtil.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2022 Côme Chilliet <come.chilliet@nextcloud.com>
  4. *
  5. * @author Arthur Schiwon <blizzz@owncloud.com>
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Jakob Sack <mail@jakobsack.de>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Klaas Freitag <freitag@owncloud.com>
  10. * @author Markus Goetz <markus@woboq.com>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Robin Appelman <icewind@owncloud.com>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. * @author Vincent Petry <pvince81@owncloud.com>
  15. * @author Côme Chilliet <come.chilliet@nextcloud.com>
  16. *
  17. * @license AGPL-3.0
  18. *
  19. * This code is free software: you can redistribute it and/or modify
  20. * it under the terms of the GNU Affero General Public License, version 3,
  21. * as published by the Free Software Foundation.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License, version 3,
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>
  30. *
  31. */
  32. namespace OCP\Files;
  33. /**
  34. * This class provides different helper functions related to WebDAV protocol
  35. *
  36. * @since 25.0.0
  37. */
  38. class DavUtil {
  39. /**
  40. * Compute the fileId to use for dav responses
  41. *
  42. * @param int $id Id of the file returned by FileInfo::getId
  43. * @since 25.0.0
  44. */
  45. public static function getDavFileId(int $id): string {
  46. $instanceId = \OC_Util::getInstanceId();
  47. $id = sprintf('%08d', $id);
  48. return $id . $instanceId;
  49. }
  50. /**
  51. * Compute the format needed for returning permissions for dav
  52. *
  53. * @since 25.0.0
  54. */
  55. public static function getDavPermissions(FileInfo $info): string {
  56. $p = '';
  57. if ($info->isShared()) {
  58. $p .= 'S';
  59. }
  60. if ($info->isShareable()) {
  61. $p .= 'R';
  62. }
  63. if ($info->isMounted()) {
  64. $p .= 'M';
  65. }
  66. if ($info->isReadable()) {
  67. $p .= 'G';
  68. }
  69. if ($info->isDeletable()) {
  70. $p .= 'D';
  71. }
  72. if ($info->isUpdateable()) {
  73. $p .= 'NV'; // Renameable, Moveable
  74. }
  75. if ($info->getType() === FileInfo::TYPE_FILE) {
  76. if ($info->isUpdateable()) {
  77. $p .= 'W';
  78. }
  79. } else {
  80. if ($info->isCreatable()) {
  81. $p .= 'CK';
  82. }
  83. }
  84. return $p;
  85. }
  86. }