@@ -37,112 +37,112 @@ |
||
| 37 | 37 | * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead |
| 38 | 38 | */ |
| 39 | 39 | class Cache extends CacheJail { |
| 40 | - /** |
|
| 41 | - * @var \OCA\Files_Sharing\SharedStorage |
|
| 42 | - */ |
|
| 43 | - private $storage; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var ICacheEntry |
|
| 47 | - */ |
|
| 48 | - private $sourceRootInfo; |
|
| 49 | - |
|
| 50 | - private $rootUnchanged = true; |
|
| 51 | - |
|
| 52 | - private $ownerDisplayName; |
|
| 53 | - |
|
| 54 | - private $numericId; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @param \OCA\Files_Sharing\SharedStorage $storage |
|
| 58 | - * @param ICacheEntry $sourceRootInfo |
|
| 59 | - */ |
|
| 60 | - public function __construct($storage, ICacheEntry $sourceRootInfo) { |
|
| 61 | - $this->storage = $storage; |
|
| 62 | - $this->sourceRootInfo = $sourceRootInfo; |
|
| 63 | - $this->numericId = $sourceRootInfo->getStorageId(); |
|
| 64 | - parent::__construct( |
|
| 65 | - null, |
|
| 66 | - $this->sourceRootInfo->getPath() |
|
| 67 | - ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function getCache() { |
|
| 71 | - if (is_null($this->cache)) { |
|
| 72 | - $sourceStorage = $this->storage->getSourceStorage(); |
|
| 73 | - if ($sourceStorage) { |
|
| 74 | - $this->cache = $sourceStorage->getCache(); |
|
| 75 | - } else { |
|
| 76 | - // don't set $this->cache here since sourceStorage will be set later |
|
| 77 | - return new FailedCache(); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - return $this->cache; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function getNumericStorageId() { |
|
| 84 | - if (isset($this->numericId)) { |
|
| 85 | - return $this->numericId; |
|
| 86 | - } else { |
|
| 87 | - return false; |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function get($file) { |
|
| 92 | - if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) { |
|
| 93 | - return $this->formatCacheEntry(clone $this->sourceRootInfo); |
|
| 94 | - } |
|
| 95 | - return parent::get($file); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - public function update($id, array $data) { |
|
| 99 | - $this->rootUnchanged = false; |
|
| 100 | - parent::update($id, $data); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - public function insert($file, array $data) { |
|
| 104 | - $this->rootUnchanged = false; |
|
| 105 | - return parent::insert($file, $data); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function remove($file) { |
|
| 109 | - $this->rootUnchanged = false; |
|
| 110 | - parent::remove($file); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 114 | - $this->rootUnchanged = false; |
|
| 115 | - return parent::moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - protected function formatCacheEntry($entry) { |
|
| 119 | - $path = isset($entry['path']) ? $entry['path'] : ''; |
|
| 120 | - $entry = parent::formatCacheEntry($entry); |
|
| 121 | - $sharePermissions = $this->storage->getPermissions($path); |
|
| 122 | - if (isset($entry['permissions'])) { |
|
| 123 | - $entry['permissions'] &= $sharePermissions; |
|
| 124 | - } else { |
|
| 125 | - $entry['permissions'] = $sharePermissions; |
|
| 126 | - } |
|
| 127 | - $entry['uid_owner'] = $this->storage->getOwner($path); |
|
| 128 | - $entry['displayname_owner'] = $this->getOwnerDisplayName(); |
|
| 129 | - if ($path === '') { |
|
| 130 | - $entry['is_share_mount_point'] = true; |
|
| 131 | - } |
|
| 132 | - return $entry; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - private function getOwnerDisplayName() { |
|
| 136 | - if (!$this->ownerDisplayName) { |
|
| 137 | - $this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner('')); |
|
| 138 | - } |
|
| 139 | - return $this->ownerDisplayName; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * remove all entries for files that are stored on the storage from the cache |
|
| 144 | - */ |
|
| 145 | - public function clear() { |
|
| 146 | - // Not a valid action for Shared Cache |
|
| 147 | - } |
|
| 40 | + /** |
|
| 41 | + * @var \OCA\Files_Sharing\SharedStorage |
|
| 42 | + */ |
|
| 43 | + private $storage; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var ICacheEntry |
|
| 47 | + */ |
|
| 48 | + private $sourceRootInfo; |
|
| 49 | + |
|
| 50 | + private $rootUnchanged = true; |
|
| 51 | + |
|
| 52 | + private $ownerDisplayName; |
|
| 53 | + |
|
| 54 | + private $numericId; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @param \OCA\Files_Sharing\SharedStorage $storage |
|
| 58 | + * @param ICacheEntry $sourceRootInfo |
|
| 59 | + */ |
|
| 60 | + public function __construct($storage, ICacheEntry $sourceRootInfo) { |
|
| 61 | + $this->storage = $storage; |
|
| 62 | + $this->sourceRootInfo = $sourceRootInfo; |
|
| 63 | + $this->numericId = $sourceRootInfo->getStorageId(); |
|
| 64 | + parent::__construct( |
|
| 65 | + null, |
|
| 66 | + $this->sourceRootInfo->getPath() |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function getCache() { |
|
| 71 | + if (is_null($this->cache)) { |
|
| 72 | + $sourceStorage = $this->storage->getSourceStorage(); |
|
| 73 | + if ($sourceStorage) { |
|
| 74 | + $this->cache = $sourceStorage->getCache(); |
|
| 75 | + } else { |
|
| 76 | + // don't set $this->cache here since sourceStorage will be set later |
|
| 77 | + return new FailedCache(); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + return $this->cache; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function getNumericStorageId() { |
|
| 84 | + if (isset($this->numericId)) { |
|
| 85 | + return $this->numericId; |
|
| 86 | + } else { |
|
| 87 | + return false; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function get($file) { |
|
| 92 | + if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) { |
|
| 93 | + return $this->formatCacheEntry(clone $this->sourceRootInfo); |
|
| 94 | + } |
|
| 95 | + return parent::get($file); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + public function update($id, array $data) { |
|
| 99 | + $this->rootUnchanged = false; |
|
| 100 | + parent::update($id, $data); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + public function insert($file, array $data) { |
|
| 104 | + $this->rootUnchanged = false; |
|
| 105 | + return parent::insert($file, $data); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function remove($file) { |
|
| 109 | + $this->rootUnchanged = false; |
|
| 110 | + parent::remove($file); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 114 | + $this->rootUnchanged = false; |
|
| 115 | + return parent::moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + protected function formatCacheEntry($entry) { |
|
| 119 | + $path = isset($entry['path']) ? $entry['path'] : ''; |
|
| 120 | + $entry = parent::formatCacheEntry($entry); |
|
| 121 | + $sharePermissions = $this->storage->getPermissions($path); |
|
| 122 | + if (isset($entry['permissions'])) { |
|
| 123 | + $entry['permissions'] &= $sharePermissions; |
|
| 124 | + } else { |
|
| 125 | + $entry['permissions'] = $sharePermissions; |
|
| 126 | + } |
|
| 127 | + $entry['uid_owner'] = $this->storage->getOwner($path); |
|
| 128 | + $entry['displayname_owner'] = $this->getOwnerDisplayName(); |
|
| 129 | + if ($path === '') { |
|
| 130 | + $entry['is_share_mount_point'] = true; |
|
| 131 | + } |
|
| 132 | + return $entry; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + private function getOwnerDisplayName() { |
|
| 136 | + if (!$this->ownerDisplayName) { |
|
| 137 | + $this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner('')); |
|
| 138 | + } |
|
| 139 | + return $this->ownerDisplayName; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * remove all entries for files that are stored on the storage from the cache |
|
| 144 | + */ |
|
| 145 | + public function clear() { |
|
| 146 | + // Not a valid action for Shared Cache |
|
| 147 | + } |
|
| 148 | 148 | } |