@@ -37,118 +37,118 @@ |
||
| 37 | 37 | * Note that the read permissions can't be masked |
| 38 | 38 | */ |
| 39 | 39 | class PermissionsMask extends Wrapper { |
| 40 | - /** |
|
| 41 | - * @var int the permissions bits we want to keep |
|
| 42 | - */ |
|
| 43 | - private $mask; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param array $arguments ['storage' => $storage, 'mask' => $mask] |
|
| 47 | - * |
|
| 48 | - * $storage: The storage the permissions mask should be applied on |
|
| 49 | - * $mask: The permission bits that should be kept, a combination of the \OCP\Constant::PERMISSION_ constants |
|
| 50 | - */ |
|
| 51 | - public function __construct($arguments) { |
|
| 52 | - parent::__construct($arguments); |
|
| 53 | - $this->mask = $arguments['mask']; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - private function checkMask($permissions) { |
|
| 57 | - return ($this->mask & $permissions) === $permissions; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - public function isUpdatable($path) { |
|
| 61 | - return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - public function isCreatable($path) { |
|
| 65 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function isDeletable($path) { |
|
| 69 | - return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - public function isSharable($path) { |
|
| 73 | - return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function getPermissions($path) { |
|
| 77 | - return $this->storage->getPermissions($path) & $this->mask; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - public function rename($path1, $path2) { |
|
| 81 | - $p = strpos($path1, $path2); |
|
| 82 | - if ($p === 0) { |
|
| 83 | - $part = substr($path1, strlen($path2)); |
|
| 84 | - //This is a rename of the transfer file to the original file |
|
| 85 | - if (strpos($part, '.ocTransferId') === 0) { |
|
| 86 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($path1, $path2); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($path1, $path2); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - public function copy($path1, $path2) { |
|
| 93 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($path1, $path2); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - public function touch($path, $mtime = null) { |
|
| 97 | - $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
| 98 | - return $this->checkMask($permissions) and parent::touch($path, $mtime); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public function mkdir($path) { |
|
| 102 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::mkdir($path); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function rmdir($path) { |
|
| 106 | - return $this->checkMask(Constants::PERMISSION_DELETE) and parent::rmdir($path); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - public function unlink($path) { |
|
| 110 | - return $this->checkMask(Constants::PERMISSION_DELETE) and parent::unlink($path); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - public function file_put_contents($path, $data) { |
|
| 114 | - $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
| 115 | - return $this->checkMask($permissions) ? parent::file_put_contents($path, $data) : false; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - public function fopen($path, $mode) { |
|
| 119 | - if ($mode === 'r' or $mode === 'rb') { |
|
| 120 | - return parent::fopen($path, $mode); |
|
| 121 | - } else { |
|
| 122 | - $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
| 123 | - return $this->checkMask($permissions) ? parent::fopen($path, $mode) : false; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * get a cache instance for the storage |
|
| 129 | - * |
|
| 130 | - * @param string $path |
|
| 131 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache |
|
| 132 | - * @return \OC\Files\Cache\Cache |
|
| 133 | - */ |
|
| 134 | - public function getCache($path = '', $storage = null) { |
|
| 135 | - if (!$storage) { |
|
| 136 | - $storage = $this; |
|
| 137 | - } |
|
| 138 | - $sourceCache = parent::getCache($path, $storage); |
|
| 139 | - return new CachePermissionsMask($sourceCache, $this->mask); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - public function getMetaData($path) { |
|
| 143 | - $data = parent::getMetaData($path); |
|
| 144 | - |
|
| 145 | - if ($data && isset($data['permissions'])) { |
|
| 146 | - $data['permissions'] = $data['permissions'] & $this->mask; |
|
| 147 | - } |
|
| 148 | - return $data; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - public function getScanner($path = '', $storage = null) { |
|
| 152 | - return parent::getScanner($path, $this->storage); |
|
| 153 | - } |
|
| 40 | + /** |
|
| 41 | + * @var int the permissions bits we want to keep |
|
| 42 | + */ |
|
| 43 | + private $mask; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param array $arguments ['storage' => $storage, 'mask' => $mask] |
|
| 47 | + * |
|
| 48 | + * $storage: The storage the permissions mask should be applied on |
|
| 49 | + * $mask: The permission bits that should be kept, a combination of the \OCP\Constant::PERMISSION_ constants |
|
| 50 | + */ |
|
| 51 | + public function __construct($arguments) { |
|
| 52 | + parent::__construct($arguments); |
|
| 53 | + $this->mask = $arguments['mask']; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + private function checkMask($permissions) { |
|
| 57 | + return ($this->mask & $permissions) === $permissions; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public function isUpdatable($path) { |
|
| 61 | + return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + public function isCreatable($path) { |
|
| 65 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function isDeletable($path) { |
|
| 69 | + return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + public function isSharable($path) { |
|
| 73 | + return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function getPermissions($path) { |
|
| 77 | + return $this->storage->getPermissions($path) & $this->mask; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + public function rename($path1, $path2) { |
|
| 81 | + $p = strpos($path1, $path2); |
|
| 82 | + if ($p === 0) { |
|
| 83 | + $part = substr($path1, strlen($path2)); |
|
| 84 | + //This is a rename of the transfer file to the original file |
|
| 85 | + if (strpos($part, '.ocTransferId') === 0) { |
|
| 86 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($path1, $path2); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($path1, $path2); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + public function copy($path1, $path2) { |
|
| 93 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($path1, $path2); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + public function touch($path, $mtime = null) { |
|
| 97 | + $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
| 98 | + return $this->checkMask($permissions) and parent::touch($path, $mtime); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public function mkdir($path) { |
|
| 102 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::mkdir($path); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function rmdir($path) { |
|
| 106 | + return $this->checkMask(Constants::PERMISSION_DELETE) and parent::rmdir($path); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + public function unlink($path) { |
|
| 110 | + return $this->checkMask(Constants::PERMISSION_DELETE) and parent::unlink($path); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + public function file_put_contents($path, $data) { |
|
| 114 | + $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
| 115 | + return $this->checkMask($permissions) ? parent::file_put_contents($path, $data) : false; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + public function fopen($path, $mode) { |
|
| 119 | + if ($mode === 'r' or $mode === 'rb') { |
|
| 120 | + return parent::fopen($path, $mode); |
|
| 121 | + } else { |
|
| 122 | + $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
| 123 | + return $this->checkMask($permissions) ? parent::fopen($path, $mode) : false; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * get a cache instance for the storage |
|
| 129 | + * |
|
| 130 | + * @param string $path |
|
| 131 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache |
|
| 132 | + * @return \OC\Files\Cache\Cache |
|
| 133 | + */ |
|
| 134 | + public function getCache($path = '', $storage = null) { |
|
| 135 | + if (!$storage) { |
|
| 136 | + $storage = $this; |
|
| 137 | + } |
|
| 138 | + $sourceCache = parent::getCache($path, $storage); |
|
| 139 | + return new CachePermissionsMask($sourceCache, $this->mask); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + public function getMetaData($path) { |
|
| 143 | + $data = parent::getMetaData($path); |
|
| 144 | + |
|
| 145 | + if ($data && isset($data['permissions'])) { |
|
| 146 | + $data['permissions'] = $data['permissions'] & $this->mask; |
|
| 147 | + } |
|
| 148 | + return $data; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + public function getScanner($path = '', $storage = null) { |
|
| 152 | + return parent::getScanner($path, $this->storage); |
|
| 153 | + } |
|
| 154 | 154 | } |