Passed
Push — master ( 568762...700449 )
by Morris
27:38 queued 15:10
created
apps/files_sharing/lib/Cache.php 2 patches
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -41,156 +41,156 @@
 block discarded – undo
41 41
  * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead
42 42
  */
43 43
 class Cache extends CacheJail {
44
-	/**
45
-	 * @var \OCA\Files_Sharing\SharedStorage
46
-	 */
47
-	private $storage;
48
-
49
-	/**
50
-	 * @var ICacheEntry
51
-	 */
52
-	private $sourceRootInfo;
53
-
54
-	private $rootUnchanged = true;
55
-
56
-	private $ownerDisplayName;
57
-
58
-	private $numericId;
59
-
60
-	/**
61
-	 * @param \OCA\Files_Sharing\SharedStorage $storage
62
-	 * @param ICacheEntry $sourceRootInfo
63
-	 */
64
-	public function __construct($storage, ICacheEntry $sourceRootInfo) {
65
-		$this->storage = $storage;
66
-		$this->sourceRootInfo = $sourceRootInfo;
67
-		$this->numericId = $sourceRootInfo->getStorageId();
68
-
69
-		parent::__construct(
70
-			null,
71
-			''
72
-		);
73
-	}
74
-
75
-	protected function getRoot() {
76
-		if ($this->root === '') {
77
-			$absoluteRoot = $this->sourceRootInfo->getPath();
78
-
79
-			// the sourceRootInfo path is the absolute path of the folder in the "real" storage
80
-			// in the case where a folder is shared from a Jail we need to ensure that the share Jail
81
-			// has it's root set relative to the source Jail
82
-			$currentStorage = $this->storage->getSourceStorage();
83
-			if ($currentStorage->instanceOfStorage(Jail::class)) {
84
-				/** @var Jail $currentStorage */
85
-				$absoluteRoot = $currentStorage->getJailedPath($absoluteRoot);
86
-			}
87
-			$this->root = $absoluteRoot;
88
-		}
89
-		return $this->root;
90
-	}
91
-
92
-	public function getCache() {
93
-		if (is_null($this->cache)) {
94
-			$sourceStorage = $this->storage->getSourceStorage();
95
-			if ($sourceStorage) {
96
-				$this->cache = $sourceStorage->getCache();
97
-			} else {
98
-				// don't set $this->cache here since sourceStorage will be set later
99
-				return new FailedCache();
100
-			}
101
-		}
102
-		return $this->cache;
103
-	}
104
-
105
-	public function getNumericStorageId() {
106
-		if (isset($this->numericId)) {
107
-			return $this->numericId;
108
-		} else {
109
-			return false;
110
-		}
111
-	}
112
-
113
-	public function get($file) {
114
-		if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) {
115
-			return $this->formatCacheEntry(clone $this->sourceRootInfo, '');
116
-		}
117
-		return parent::get($file);
118
-	}
119
-
120
-	public function update($id, array $data) {
121
-		$this->rootUnchanged = false;
122
-		parent::update($id, $data);
123
-	}
124
-
125
-	public function insert($file, array $data) {
126
-		$this->rootUnchanged = false;
127
-		return parent::insert($file, $data);
128
-	}
129
-
130
-	public function remove($file) {
131
-		$this->rootUnchanged = false;
132
-		parent::remove($file);
133
-	}
134
-
135
-	public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
136
-		$this->rootUnchanged = false;
137
-		return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
138
-	}
139
-
140
-	protected function formatCacheEntry($entry, $path = null) {
141
-		if (is_null($path)) {
142
-			$path = $entry['path'] ?? '';
143
-			$entry['path'] = $this->getJailedPath($path);
144
-		} else {
145
-			$entry['path'] = $path;
146
-		}
147
-
148
-		try {
149
-			if (isset($entry['permissions'])) {
150
-				$entry['permissions'] &= $this->storage->getShare()->getPermissions();
151
-			} else {
152
-				$entry['permissions'] = $this->storage->getPermissions($entry['path']);
153
-			}
154
-		} catch (StorageNotAvailableException $e) {
155
-			// thrown by FailedStorage e.g. when the sharer does not exist anymore
156
-			// (IDE may say the exception is never thrown – false negative)
157
-			$sharePermissions = 0;
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
-
181
-	public function search($pattern) {
182
-		// Do the normal search on the whole storage for non files
183
-		if ($this->storage->getItemType() !== 'file') {
184
-			return parent::search($pattern);
185
-		}
186
-
187
-		$regex = '/' . str_replace('%', '.*', $pattern) . '/i';
188
-
189
-		$data = $this->get('');
190
-		if (preg_match($regex, $data->getName()) === 1) {
191
-			return [$data];
192
-		}
193
-
194
-		return [];
195
-	}
44
+    /**
45
+     * @var \OCA\Files_Sharing\SharedStorage
46
+     */
47
+    private $storage;
48
+
49
+    /**
50
+     * @var ICacheEntry
51
+     */
52
+    private $sourceRootInfo;
53
+
54
+    private $rootUnchanged = true;
55
+
56
+    private $ownerDisplayName;
57
+
58
+    private $numericId;
59
+
60
+    /**
61
+     * @param \OCA\Files_Sharing\SharedStorage $storage
62
+     * @param ICacheEntry $sourceRootInfo
63
+     */
64
+    public function __construct($storage, ICacheEntry $sourceRootInfo) {
65
+        $this->storage = $storage;
66
+        $this->sourceRootInfo = $sourceRootInfo;
67
+        $this->numericId = $sourceRootInfo->getStorageId();
68
+
69
+        parent::__construct(
70
+            null,
71
+            ''
72
+        );
73
+    }
74
+
75
+    protected function getRoot() {
76
+        if ($this->root === '') {
77
+            $absoluteRoot = $this->sourceRootInfo->getPath();
78
+
79
+            // the sourceRootInfo path is the absolute path of the folder in the "real" storage
80
+            // in the case where a folder is shared from a Jail we need to ensure that the share Jail
81
+            // has it's root set relative to the source Jail
82
+            $currentStorage = $this->storage->getSourceStorage();
83
+            if ($currentStorage->instanceOfStorage(Jail::class)) {
84
+                /** @var Jail $currentStorage */
85
+                $absoluteRoot = $currentStorage->getJailedPath($absoluteRoot);
86
+            }
87
+            $this->root = $absoluteRoot;
88
+        }
89
+        return $this->root;
90
+    }
91
+
92
+    public function getCache() {
93
+        if (is_null($this->cache)) {
94
+            $sourceStorage = $this->storage->getSourceStorage();
95
+            if ($sourceStorage) {
96
+                $this->cache = $sourceStorage->getCache();
97
+            } else {
98
+                // don't set $this->cache here since sourceStorage will be set later
99
+                return new FailedCache();
100
+            }
101
+        }
102
+        return $this->cache;
103
+    }
104
+
105
+    public function getNumericStorageId() {
106
+        if (isset($this->numericId)) {
107
+            return $this->numericId;
108
+        } else {
109
+            return false;
110
+        }
111
+    }
112
+
113
+    public function get($file) {
114
+        if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) {
115
+            return $this->formatCacheEntry(clone $this->sourceRootInfo, '');
116
+        }
117
+        return parent::get($file);
118
+    }
119
+
120
+    public function update($id, array $data) {
121
+        $this->rootUnchanged = false;
122
+        parent::update($id, $data);
123
+    }
124
+
125
+    public function insert($file, array $data) {
126
+        $this->rootUnchanged = false;
127
+        return parent::insert($file, $data);
128
+    }
129
+
130
+    public function remove($file) {
131
+        $this->rootUnchanged = false;
132
+        parent::remove($file);
133
+    }
134
+
135
+    public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
136
+        $this->rootUnchanged = false;
137
+        return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
138
+    }
139
+
140
+    protected function formatCacheEntry($entry, $path = null) {
141
+        if (is_null($path)) {
142
+            $path = $entry['path'] ?? '';
143
+            $entry['path'] = $this->getJailedPath($path);
144
+        } else {
145
+            $entry['path'] = $path;
146
+        }
147
+
148
+        try {
149
+            if (isset($entry['permissions'])) {
150
+                $entry['permissions'] &= $this->storage->getShare()->getPermissions();
151
+            } else {
152
+                $entry['permissions'] = $this->storage->getPermissions($entry['path']);
153
+            }
154
+        } catch (StorageNotAvailableException $e) {
155
+            // thrown by FailedStorage e.g. when the sharer does not exist anymore
156
+            // (IDE may say the exception is never thrown – false negative)
157
+            $sharePermissions = 0;
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
+
181
+    public function search($pattern) {
182
+        // Do the normal search on the whole storage for non files
183
+        if ($this->storage->getItemType() !== 'file') {
184
+            return parent::search($pattern);
185
+        }
186
+
187
+        $regex = '/' . str_replace('%', '.*', $pattern) . '/i';
188
+
189
+        $data = $this->get('');
190
+        if (preg_match($regex, $data->getName()) === 1) {
191
+            return [$data];
192
+        }
193
+
194
+        return [];
195
+    }
196 196
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -184,7 +184,7 @@
 block discarded – undo
184 184
 			return parent::search($pattern);
185 185
 		}
186 186
 
187
-		$regex = '/' . str_replace('%', '.*', $pattern) . '/i';
187
+		$regex = '/'.str_replace('%', '.*', $pattern).'/i';
188 188
 
189 189
 		$data = $this->get('');
190 190
 		if (preg_match($regex, $data->getName()) === 1) {
Please login to merge, or discard this patch.