|
| 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 | + |
| 33 | +namespace OCP\Files; |
| 34 | + |
| 35 | +/** |
| 36 | + * This class provides different helper functions related to WebDAV protocol |
| 37 | + * |
| 38 | + * @since 25.0.0 |
| 39 | + */ |
| 40 | +class DavUtil { |
| 41 | + /** |
| 42 | + * Compute the fileId to use for dav responses |
| 43 | + * |
| 44 | + * @param int $id Id of the file returned by FileInfo::getId |
| 45 | + * @since 25.0.0 |
| 46 | + */ |
| 47 | + public static function getDavFileId(int $id): string { |
| 48 | + $instanceId = \OC_Util::getInstanceId(); |
| 49 | + $id = sprintf('%08d', $id); |
| 50 | + return $id . $instanceId; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Compute the format needed for returning permissions for dav |
| 55 | + * |
| 56 | + * @since 25.0.0 |
| 57 | + */ |
| 58 | + public static function getDavPermissions(FileInfo $info): string { |
| 59 | + $p = ''; |
| 60 | + if ($info->isShared()) { |
| 61 | + $p .= 'S'; |
| 62 | + } |
| 63 | + if ($info->isShareable()) { |
| 64 | + $p .= 'R'; |
| 65 | + } |
| 66 | + if ($info->isMounted()) { |
| 67 | + $p .= 'M'; |
| 68 | + } |
| 69 | + if ($info->isReadable()) { |
| 70 | + $p .= 'G'; |
| 71 | + } |
| 72 | + if ($info->isDeletable()) { |
| 73 | + $p .= 'D'; |
| 74 | + } |
| 75 | + if ($info->isUpdateable()) { |
| 76 | + $p .= 'NV'; // Renameable, Moveable |
| 77 | + } |
| 78 | + if ($info->getType() === FileInfo::TYPE_FILE) { |
| 79 | + if ($info->isUpdateable()) { |
| 80 | + $p .= 'W'; |
| 81 | + } |
| 82 | + } else { |
| 83 | + if ($info->isCreatable()) { |
| 84 | + $p .= 'CK'; |
| 85 | + } |
| 86 | + } |
| 87 | + return $p; |
| 88 | + } |
| 89 | +} |
0 commit comments