Passed
Push — master ( 03746e...9268c0 )
by Joas
10:14
created
apps/files_sharing/lib/Cache.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -40,141 +40,141 @@
 block discarded – undo
40 40
  * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead
41 41
  */
42 42
 class Cache extends CacheJail {
43
-	/**
44
-	 * @var \OCA\Files_Sharing\SharedStorage
45
-	 */
46
-	private $storage;
47
-
48
-	/**
49
-	 * @var ICacheEntry
50
-	 */
51
-	private $sourceRootInfo;
52
-
53
-	private $rootUnchanged = true;
54
-
55
-	private $ownerDisplayName;
56
-
57
-	private $numericId;
58
-
59
-	/**
60
-	 * @param \OCA\Files_Sharing\SharedStorage $storage
61
-	 * @param ICacheEntry $sourceRootInfo
62
-	 */
63
-	public function __construct($storage, ICacheEntry $sourceRootInfo) {
64
-		$this->storage = $storage;
65
-		$this->sourceRootInfo = $sourceRootInfo;
66
-		$this->numericId = $sourceRootInfo->getStorageId();
67
-
68
-		parent::__construct(
69
-			null,
70
-			''
71
-		);
72
-	}
73
-
74
-	protected function getRoot() {
75
-		if ($this->root === '') {
76
-			$absoluteRoot = $this->sourceRootInfo->getPath();
77
-
78
-			// the sourceRootInfo path is the absolute path of the folder in the "real" storage
79
-			// in the case where a folder is shared from a Jail we need to ensure that the share Jail
80
-			// has it's root set relative to the source Jail
81
-			$currentStorage = $this->storage->getSourceStorage();
82
-			if ($currentStorage->instanceOfStorage(Jail::class)) {
83
-				/** @var Jail $currentStorage */
84
-				$absoluteRoot = $currentStorage->getJailedPath($absoluteRoot);
85
-			}
86
-			$this->root = $absoluteRoot;
87
-		}
88
-		return $this->root;
89
-	}
90
-
91
-	public function getCache() {
92
-		if (is_null($this->cache)) {
93
-			$sourceStorage = $this->storage->getSourceStorage();
94
-			if ($sourceStorage) {
95
-				$this->cache = $sourceStorage->getCache();
96
-			} else {
97
-				// don't set $this->cache here since sourceStorage will be set later
98
-				return new FailedCache();
99
-			}
100
-		}
101
-		return $this->cache;
102
-	}
103
-
104
-	public function getNumericStorageId() {
105
-		if (isset($this->numericId)) {
106
-			return $this->numericId;
107
-		} else {
108
-			return false;
109
-		}
110
-	}
111
-
112
-	public function get($file) {
113
-		if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) {
114
-			return $this->formatCacheEntry(clone $this->sourceRootInfo, '');
115
-		}
116
-		return parent::get($file);
117
-	}
118
-
119
-	public function update($id, array $data) {
120
-		$this->rootUnchanged = false;
121
-		parent::update($id, $data);
122
-	}
123
-
124
-	public function insert($file, array $data) {
125
-		$this->rootUnchanged = false;
126
-		return parent::insert($file, $data);
127
-	}
128
-
129
-	public function remove($file) {
130
-		$this->rootUnchanged = false;
131
-		parent::remove($file);
132
-	}
133
-
134
-	public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
135
-		$this->rootUnchanged = false;
136
-		return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
137
-	}
138
-
139
-	protected function formatCacheEntry($entry, $path = null) {
140
-		if (is_null($path)) {
141
-			$path = $entry['path'] ?? '';
142
-			$entry['path'] = $this->getJailedPath($path);
143
-		} else {
144
-			$entry['path'] = $path;
145
-		}
146
-
147
-		try {
148
-			$sharePermissions = $this->storage->getPermissions($entry['path']);
149
-		} catch (StorageNotAvailableException $e) {
150
-			// thrown by FailedStorage e.g. when the sharer does not exist anymore
151
-			// (IDE may say the exception is never thrown – false negative)
152
-			$sharePermissions = 0;
153
-		}
154
-		if (isset($entry['permissions'])) {
155
-			$entry['permissions'] &= $sharePermissions;
156
-		} else {
157
-			$entry['permissions'] = $sharePermissions;
158
-		}
159
-		$entry['uid_owner'] = $this->storage->getOwner('');
160
-		$entry['displayname_owner'] = $this->getOwnerDisplayName();
161
-		if ($path === '') {
162
-			$entry['is_share_mount_point'] = true;
163
-		}
164
-		return $entry;
165
-	}
166
-
167
-	private function getOwnerDisplayName() {
168
-		if (!$this->ownerDisplayName) {
169
-			$this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner(''));
170
-		}
171
-		return $this->ownerDisplayName;
172
-	}
173
-
174
-	/**
175
-	 * remove all entries for files that are stored on the storage from the cache
176
-	 */
177
-	public function clear() {
178
-		// Not a valid action for Shared Cache
179
-	}
43
+    /**
44
+     * @var \OCA\Files_Sharing\SharedStorage
45
+     */
46
+    private $storage;
47
+
48
+    /**
49
+     * @var ICacheEntry
50
+     */
51
+    private $sourceRootInfo;
52
+
53
+    private $rootUnchanged = true;
54
+
55
+    private $ownerDisplayName;
56
+
57
+    private $numericId;
58
+
59
+    /**
60
+     * @param \OCA\Files_Sharing\SharedStorage $storage
61
+     * @param ICacheEntry $sourceRootInfo
62
+     */
63
+    public function __construct($storage, ICacheEntry $sourceRootInfo) {
64
+        $this->storage = $storage;
65
+        $this->sourceRootInfo = $sourceRootInfo;
66
+        $this->numericId = $sourceRootInfo->getStorageId();
67
+
68
+        parent::__construct(
69
+            null,
70
+            ''
71
+        );
72
+    }
73
+
74
+    protected function getRoot() {
75
+        if ($this->root === '') {
76
+            $absoluteRoot = $this->sourceRootInfo->getPath();
77
+
78
+            // the sourceRootInfo path is the absolute path of the folder in the "real" storage
79
+            // in the case where a folder is shared from a Jail we need to ensure that the share Jail
80
+            // has it's root set relative to the source Jail
81
+            $currentStorage = $this->storage->getSourceStorage();
82
+            if ($currentStorage->instanceOfStorage(Jail::class)) {
83
+                /** @var Jail $currentStorage */
84
+                $absoluteRoot = $currentStorage->getJailedPath($absoluteRoot);
85
+            }
86
+            $this->root = $absoluteRoot;
87
+        }
88
+        return $this->root;
89
+    }
90
+
91
+    public function getCache() {
92
+        if (is_null($this->cache)) {
93
+            $sourceStorage = $this->storage->getSourceStorage();
94
+            if ($sourceStorage) {
95
+                $this->cache = $sourceStorage->getCache();
96
+            } else {
97
+                // don't set $this->cache here since sourceStorage will be set later
98
+                return new FailedCache();
99
+            }
100
+        }
101
+        return $this->cache;
102
+    }
103
+
104
+    public function getNumericStorageId() {
105
+        if (isset($this->numericId)) {
106
+            return $this->numericId;
107
+        } else {
108
+            return false;
109
+        }
110
+    }
111
+
112
+    public function get($file) {
113
+        if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) {
114
+            return $this->formatCacheEntry(clone $this->sourceRootInfo, '');
115
+        }
116
+        return parent::get($file);
117
+    }
118
+
119
+    public function update($id, array $data) {
120
+        $this->rootUnchanged = false;
121
+        parent::update($id, $data);
122
+    }
123
+
124
+    public function insert($file, array $data) {
125
+        $this->rootUnchanged = false;
126
+        return parent::insert($file, $data);
127
+    }
128
+
129
+    public function remove($file) {
130
+        $this->rootUnchanged = false;
131
+        parent::remove($file);
132
+    }
133
+
134
+    public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
135
+        $this->rootUnchanged = false;
136
+        return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
137
+    }
138
+
139
+    protected function formatCacheEntry($entry, $path = null) {
140
+        if (is_null($path)) {
141
+            $path = $entry['path'] ?? '';
142
+            $entry['path'] = $this->getJailedPath($path);
143
+        } else {
144
+            $entry['path'] = $path;
145
+        }
146
+
147
+        try {
148
+            $sharePermissions = $this->storage->getPermissions($entry['path']);
149
+        } catch (StorageNotAvailableException $e) {
150
+            // thrown by FailedStorage e.g. when the sharer does not exist anymore
151
+            // (IDE may say the exception is never thrown – false negative)
152
+            $sharePermissions = 0;
153
+        }
154
+        if (isset($entry['permissions'])) {
155
+            $entry['permissions'] &= $sharePermissions;
156
+        } else {
157
+            $entry['permissions'] = $sharePermissions;
158
+        }
159
+        $entry['uid_owner'] = $this->storage->getOwner('');
160
+        $entry['displayname_owner'] = $this->getOwnerDisplayName();
161
+        if ($path === '') {
162
+            $entry['is_share_mount_point'] = true;
163
+        }
164
+        return $entry;
165
+    }
166
+
167
+    private function getOwnerDisplayName() {
168
+        if (!$this->ownerDisplayName) {
169
+            $this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner(''));
170
+        }
171
+        return $this->ownerDisplayName;
172
+    }
173
+
174
+    /**
175
+     * remove all entries for files that are stored on the storage from the cache
176
+     */
177
+    public function clear() {
178
+        // Not a valid action for Shared Cache
179
+    }
180 180
 }
Please login to merge, or discard this patch.