Completed
Push — master ( 844c74...ddebdb )
by Morris
38:20 queued 18:21
created
apps/dav/lib/Connector/Sabre/Node.php 2 patches
Indentation   +324 added lines, -324 removed lines patch added patch discarded remove patch
@@ -45,334 +45,334 @@
 block discarded – undo
45 45
 
46 46
 abstract class Node implements \Sabre\DAV\INode {
47 47
 
48
-	/**
49
-	 * @var \OC\Files\View
50
-	 */
51
-	protected $fileView;
52
-
53
-	/**
54
-	 * The path to the current node
55
-	 *
56
-	 * @var string
57
-	 */
58
-	protected $path;
59
-
60
-	/**
61
-	 * node properties cache
62
-	 *
63
-	 * @var array
64
-	 */
65
-	protected $property_cache = null;
66
-
67
-	/**
68
-	 * @var \OCP\Files\FileInfo
69
-	 */
70
-	protected $info;
71
-
72
-	/**
73
-	 * @var IManager
74
-	 */
75
-	protected $shareManager;
76
-
77
-	/**
78
-	 * Sets up the node, expects a full path name
79
-	 *
80
-	 * @param \OC\Files\View $view
81
-	 * @param \OCP\Files\FileInfo $info
82
-	 * @param IManager $shareManager
83
-	 */
84
-	public function __construct(View $view, FileInfo $info, IManager $shareManager = null) {
85
-		$this->fileView = $view;
86
-		$this->path = $this->fileView->getRelativePath($info->getPath());
87
-		$this->info = $info;
88
-		if ($shareManager) {
89
-			$this->shareManager = $shareManager;
90
-		} else {
91
-			$this->shareManager = \OC::$server->getShareManager();
92
-		}
93
-	}
94
-
95
-	protected function refreshInfo() {
96
-		$this->info = $this->fileView->getFileInfo($this->path);
97
-	}
98
-
99
-	/**
100
-	 *  Returns the name of the node
101
-	 *
102
-	 * @return string
103
-	 */
104
-	public function getName() {
105
-		return $this->info->getName();
106
-	}
107
-
108
-	/**
109
-	 * Returns the full path
110
-	 *
111
-	 * @return string
112
-	 */
113
-	public function getPath() {
114
-		return $this->path;
115
-	}
116
-
117
-	/**
118
-	 * Renames the node
119
-	 *
120
-	 * @param string $name The new name
121
-	 * @throws \Sabre\DAV\Exception\BadRequest
122
-	 * @throws \Sabre\DAV\Exception\Forbidden
123
-	 */
124
-	public function setName($name) {
125
-
126
-		// rename is only allowed if the update privilege is granted
127
-		if (!$this->info->isUpdateable()) {
128
-			throw new \Sabre\DAV\Exception\Forbidden();
129
-		}
130
-
131
-		list($parentPath,) = \Sabre\Uri\split($this->path);
132
-		list(, $newName) = \Sabre\Uri\split($name);
133
-
134
-		// verify path of the target
135
-		$this->verifyPath();
136
-
137
-		$newPath = $parentPath . '/' . $newName;
138
-
139
-		$this->fileView->rename($this->path, $newPath);
140
-
141
-		$this->path = $newPath;
142
-
143
-		$this->refreshInfo();
144
-	}
145
-
146
-	public function setPropertyCache($property_cache) {
147
-		$this->property_cache = $property_cache;
148
-	}
149
-
150
-	/**
151
-	 * Returns the last modification time, as a unix timestamp
152
-	 *
153
-	 * @return int timestamp as integer
154
-	 */
155
-	public function getLastModified() {
156
-		$timestamp = $this->info->getMtime();
157
-		if (!empty($timestamp)) {
158
-			return (int)$timestamp;
159
-		}
160
-		return $timestamp;
161
-	}
162
-
163
-	/**
164
-	 *  sets the last modification time of the file (mtime) to the value given
165
-	 *  in the second parameter or to now if the second param is empty.
166
-	 *  Even if the modification time is set to a custom value the access time is set to now.
167
-	 */
168
-	public function touch($mtime) {
169
-		$mtime = $this->sanitizeMtime($mtime);
170
-		$this->fileView->touch($this->path, $mtime);
171
-		$this->refreshInfo();
172
-	}
173
-
174
-	/**
175
-	 * Returns the ETag for a file
176
-	 *
177
-	 * An ETag is a unique identifier representing the current version of the
178
-	 * file. If the file changes, the ETag MUST change.  The ETag is an
179
-	 * arbitrary string, but MUST be surrounded by double-quotes.
180
-	 *
181
-	 * Return null if the ETag can not effectively be determined
182
-	 *
183
-	 * @return string
184
-	 */
185
-	public function getETag() {
186
-		return '"' . $this->info->getEtag() . '"';
187
-	}
188
-
189
-	/**
190
-	 * Sets the ETag
191
-	 *
192
-	 * @param string $etag
193
-	 *
194
-	 * @return int file id of updated file or -1 on failure
195
-	 */
196
-	public function setETag($etag) {
197
-		return $this->fileView->putFileInfo($this->path, array('etag' => $etag));
198
-	}
199
-
200
-	/**
201
-	 * Returns the size of the node, in bytes
202
-	 *
203
-	 * @return integer
204
-	 */
205
-	public function getSize() {
206
-		return $this->info->getSize();
207
-	}
208
-
209
-	/**
210
-	 * Returns the cache's file id
211
-	 *
212
-	 * @return int
213
-	 */
214
-	public function getId() {
215
-		return $this->info->getId();
216
-	}
217
-
218
-	/**
219
-	 * @return string|null
220
-	 */
221
-	public function getFileId() {
222
-		if ($this->info->getId()) {
223
-			$instanceId = \OC_Util::getInstanceId();
224
-			$id = sprintf('%08d', $this->info->getId());
225
-			return $id . $instanceId;
226
-		}
227
-
228
-		return null;
229
-	}
230
-
231
-	/**
232
-	 * @return integer
233
-	 */
234
-	public function getInternalFileId() {
235
-		return $this->info->getId();
236
-	}
237
-
238
-	/**
239
-	 * @param string $user
240
-	 * @return int
241
-	 */
242
-	public function getSharePermissions($user) {
243
-
244
-		// check of we access a federated share
245
-		if ($user !== null) {
246
-			try {
247
-				$share = $this->shareManager->getShareByToken($user);
248
-				return $share->getPermissions();
249
-			} catch (ShareNotFound $e) {
250
-				// ignore
251
-			}
252
-		}
253
-
254
-		try {
255
-			$storage = $this->info->getStorage();
256
-		} catch (StorageNotAvailableException $e) {
257
-			$storage = null;
258
-		}
259
-
260
-		if ($storage && $storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
261
-			/** @var \OCA\Files_Sharing\SharedStorage $storage */
262
-			$permissions = (int)$storage->getShare()->getPermissions();
263
-		} else {
264
-			$permissions = $this->info->getPermissions();
265
-		}
266
-
267
-		/*
48
+    /**
49
+     * @var \OC\Files\View
50
+     */
51
+    protected $fileView;
52
+
53
+    /**
54
+     * The path to the current node
55
+     *
56
+     * @var string
57
+     */
58
+    protected $path;
59
+
60
+    /**
61
+     * node properties cache
62
+     *
63
+     * @var array
64
+     */
65
+    protected $property_cache = null;
66
+
67
+    /**
68
+     * @var \OCP\Files\FileInfo
69
+     */
70
+    protected $info;
71
+
72
+    /**
73
+     * @var IManager
74
+     */
75
+    protected $shareManager;
76
+
77
+    /**
78
+     * Sets up the node, expects a full path name
79
+     *
80
+     * @param \OC\Files\View $view
81
+     * @param \OCP\Files\FileInfo $info
82
+     * @param IManager $shareManager
83
+     */
84
+    public function __construct(View $view, FileInfo $info, IManager $shareManager = null) {
85
+        $this->fileView = $view;
86
+        $this->path = $this->fileView->getRelativePath($info->getPath());
87
+        $this->info = $info;
88
+        if ($shareManager) {
89
+            $this->shareManager = $shareManager;
90
+        } else {
91
+            $this->shareManager = \OC::$server->getShareManager();
92
+        }
93
+    }
94
+
95
+    protected function refreshInfo() {
96
+        $this->info = $this->fileView->getFileInfo($this->path);
97
+    }
98
+
99
+    /**
100
+     *  Returns the name of the node
101
+     *
102
+     * @return string
103
+     */
104
+    public function getName() {
105
+        return $this->info->getName();
106
+    }
107
+
108
+    /**
109
+     * Returns the full path
110
+     *
111
+     * @return string
112
+     */
113
+    public function getPath() {
114
+        return $this->path;
115
+    }
116
+
117
+    /**
118
+     * Renames the node
119
+     *
120
+     * @param string $name The new name
121
+     * @throws \Sabre\DAV\Exception\BadRequest
122
+     * @throws \Sabre\DAV\Exception\Forbidden
123
+     */
124
+    public function setName($name) {
125
+
126
+        // rename is only allowed if the update privilege is granted
127
+        if (!$this->info->isUpdateable()) {
128
+            throw new \Sabre\DAV\Exception\Forbidden();
129
+        }
130
+
131
+        list($parentPath,) = \Sabre\Uri\split($this->path);
132
+        list(, $newName) = \Sabre\Uri\split($name);
133
+
134
+        // verify path of the target
135
+        $this->verifyPath();
136
+
137
+        $newPath = $parentPath . '/' . $newName;
138
+
139
+        $this->fileView->rename($this->path, $newPath);
140
+
141
+        $this->path = $newPath;
142
+
143
+        $this->refreshInfo();
144
+    }
145
+
146
+    public function setPropertyCache($property_cache) {
147
+        $this->property_cache = $property_cache;
148
+    }
149
+
150
+    /**
151
+     * Returns the last modification time, as a unix timestamp
152
+     *
153
+     * @return int timestamp as integer
154
+     */
155
+    public function getLastModified() {
156
+        $timestamp = $this->info->getMtime();
157
+        if (!empty($timestamp)) {
158
+            return (int)$timestamp;
159
+        }
160
+        return $timestamp;
161
+    }
162
+
163
+    /**
164
+     *  sets the last modification time of the file (mtime) to the value given
165
+     *  in the second parameter or to now if the second param is empty.
166
+     *  Even if the modification time is set to a custom value the access time is set to now.
167
+     */
168
+    public function touch($mtime) {
169
+        $mtime = $this->sanitizeMtime($mtime);
170
+        $this->fileView->touch($this->path, $mtime);
171
+        $this->refreshInfo();
172
+    }
173
+
174
+    /**
175
+     * Returns the ETag for a file
176
+     *
177
+     * An ETag is a unique identifier representing the current version of the
178
+     * file. If the file changes, the ETag MUST change.  The ETag is an
179
+     * arbitrary string, but MUST be surrounded by double-quotes.
180
+     *
181
+     * Return null if the ETag can not effectively be determined
182
+     *
183
+     * @return string
184
+     */
185
+    public function getETag() {
186
+        return '"' . $this->info->getEtag() . '"';
187
+    }
188
+
189
+    /**
190
+     * Sets the ETag
191
+     *
192
+     * @param string $etag
193
+     *
194
+     * @return int file id of updated file or -1 on failure
195
+     */
196
+    public function setETag($etag) {
197
+        return $this->fileView->putFileInfo($this->path, array('etag' => $etag));
198
+    }
199
+
200
+    /**
201
+     * Returns the size of the node, in bytes
202
+     *
203
+     * @return integer
204
+     */
205
+    public function getSize() {
206
+        return $this->info->getSize();
207
+    }
208
+
209
+    /**
210
+     * Returns the cache's file id
211
+     *
212
+     * @return int
213
+     */
214
+    public function getId() {
215
+        return $this->info->getId();
216
+    }
217
+
218
+    /**
219
+     * @return string|null
220
+     */
221
+    public function getFileId() {
222
+        if ($this->info->getId()) {
223
+            $instanceId = \OC_Util::getInstanceId();
224
+            $id = sprintf('%08d', $this->info->getId());
225
+            return $id . $instanceId;
226
+        }
227
+
228
+        return null;
229
+    }
230
+
231
+    /**
232
+     * @return integer
233
+     */
234
+    public function getInternalFileId() {
235
+        return $this->info->getId();
236
+    }
237
+
238
+    /**
239
+     * @param string $user
240
+     * @return int
241
+     */
242
+    public function getSharePermissions($user) {
243
+
244
+        // check of we access a federated share
245
+        if ($user !== null) {
246
+            try {
247
+                $share = $this->shareManager->getShareByToken($user);
248
+                return $share->getPermissions();
249
+            } catch (ShareNotFound $e) {
250
+                // ignore
251
+            }
252
+        }
253
+
254
+        try {
255
+            $storage = $this->info->getStorage();
256
+        } catch (StorageNotAvailableException $e) {
257
+            $storage = null;
258
+        }
259
+
260
+        if ($storage && $storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
261
+            /** @var \OCA\Files_Sharing\SharedStorage $storage */
262
+            $permissions = (int)$storage->getShare()->getPermissions();
263
+        } else {
264
+            $permissions = $this->info->getPermissions();
265
+        }
266
+
267
+        /*
268 268
 		 * We can always share non moveable mount points with DELETE and UPDATE
269 269
 		 * Eventually we need to do this properly
270 270
 		 */
271
-		$mountpoint = $this->info->getMountPoint();
272
-		if (!($mountpoint instanceof MoveableMount)) {
273
-			$mountpointpath = $mountpoint->getMountPoint();
274
-			if (substr($mountpointpath, -1) === '/') {
275
-				$mountpointpath = substr($mountpointpath, 0, -1);
276
-			}
277
-
278
-			if (!$mountpoint->getOption('readonly', false) && $mountpointpath === $this->info->getPath()) {
279
-				$permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
280
-			}
281
-		}
282
-
283
-		/*
271
+        $mountpoint = $this->info->getMountPoint();
272
+        if (!($mountpoint instanceof MoveableMount)) {
273
+            $mountpointpath = $mountpoint->getMountPoint();
274
+            if (substr($mountpointpath, -1) === '/') {
275
+                $mountpointpath = substr($mountpointpath, 0, -1);
276
+            }
277
+
278
+            if (!$mountpoint->getOption('readonly', false) && $mountpointpath === $this->info->getPath()) {
279
+                $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
280
+            }
281
+        }
282
+
283
+        /*
284 284
 		 * Files can't have create or delete permissions
285 285
 		 */
286
-		if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
287
-			$permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE);
288
-		}
289
-
290
-		return $permissions;
291
-	}
292
-
293
-	/**
294
-	 * @return string
295
-	 */
296
-	public function getDavPermissions() {
297
-		$p = '';
298
-		if ($this->info->isShared()) {
299
-			$p .= 'S';
300
-		}
301
-		if ($this->info->isShareable()) {
302
-			$p .= 'R';
303
-		}
304
-		if ($this->info->isMounted()) {
305
-			$p .= 'M';
306
-		}
307
-		if ($this->info->isReadable()) {
308
-			$p .= 'G';
309
-		}
310
-		if ($this->info->isDeletable()) {
311
-			$p .= 'D';
312
-		}
313
-		if ($this->info->isUpdateable()) {
314
-			$p .= 'NV'; // Renameable, Moveable
315
-		}
316
-		if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
317
-			if ($this->info->isUpdateable()) {
318
-				$p .= 'W';
319
-			}
320
-		} else {
321
-			if ($this->info->isCreatable()) {
322
-				$p .= 'CK';
323
-			}
324
-		}
325
-		return $p;
326
-	}
327
-
328
-	public function getOwner() {
329
-		return $this->info->getOwner();
330
-	}
331
-
332
-	protected function verifyPath() {
333
-		try {
334
-			$fileName = basename($this->info->getPath());
335
-			$this->fileView->verifyPath($this->path, $fileName);
336
-		} catch (\OCP\Files\InvalidPathException $ex) {
337
-			throw new InvalidPath($ex->getMessage());
338
-		}
339
-	}
340
-
341
-	/**
342
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
343
-	 */
344
-	public function acquireLock($type) {
345
-		$this->fileView->lockFile($this->path, $type);
346
-	}
347
-
348
-	/**
349
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
350
-	 */
351
-	public function releaseLock($type) {
352
-		$this->fileView->unlockFile($this->path, $type);
353
-	}
354
-
355
-	/**
356
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
357
-	 */
358
-	public function changeLock($type) {
359
-		$this->fileView->changeLock($this->path, $type);
360
-	}
361
-
362
-	public function getFileInfo() {
363
-		return $this->info;
364
-	}
365
-
366
-	protected function sanitizeMtime($mtimeFromRequest) {
367
-		// In PHP 5.X "is_numeric" returns true for strings in hexadecimal
368
-		// notation. This is no longer the case in PHP 7.X, so this check
369
-		// ensures that strings with hexadecimal notations fail too in PHP 5.X.
370
-		$isHexadecimal = is_string($mtimeFromRequest) && preg_match('/^\s*0[xX]/', $mtimeFromRequest);
371
-		if ($isHexadecimal || !is_numeric($mtimeFromRequest)) {
372
-			throw new \InvalidArgumentException('X-OC-MTime header must be an integer (unix timestamp).');
373
-		}
374
-
375
-		return (int)$mtimeFromRequest;
376
-	}
286
+        if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
287
+            $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE);
288
+        }
289
+
290
+        return $permissions;
291
+    }
292
+
293
+    /**
294
+     * @return string
295
+     */
296
+    public function getDavPermissions() {
297
+        $p = '';
298
+        if ($this->info->isShared()) {
299
+            $p .= 'S';
300
+        }
301
+        if ($this->info->isShareable()) {
302
+            $p .= 'R';
303
+        }
304
+        if ($this->info->isMounted()) {
305
+            $p .= 'M';
306
+        }
307
+        if ($this->info->isReadable()) {
308
+            $p .= 'G';
309
+        }
310
+        if ($this->info->isDeletable()) {
311
+            $p .= 'D';
312
+        }
313
+        if ($this->info->isUpdateable()) {
314
+            $p .= 'NV'; // Renameable, Moveable
315
+        }
316
+        if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
317
+            if ($this->info->isUpdateable()) {
318
+                $p .= 'W';
319
+            }
320
+        } else {
321
+            if ($this->info->isCreatable()) {
322
+                $p .= 'CK';
323
+            }
324
+        }
325
+        return $p;
326
+    }
327
+
328
+    public function getOwner() {
329
+        return $this->info->getOwner();
330
+    }
331
+
332
+    protected function verifyPath() {
333
+        try {
334
+            $fileName = basename($this->info->getPath());
335
+            $this->fileView->verifyPath($this->path, $fileName);
336
+        } catch (\OCP\Files\InvalidPathException $ex) {
337
+            throw new InvalidPath($ex->getMessage());
338
+        }
339
+    }
340
+
341
+    /**
342
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
343
+     */
344
+    public function acquireLock($type) {
345
+        $this->fileView->lockFile($this->path, $type);
346
+    }
347
+
348
+    /**
349
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
350
+     */
351
+    public function releaseLock($type) {
352
+        $this->fileView->unlockFile($this->path, $type);
353
+    }
354
+
355
+    /**
356
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
357
+     */
358
+    public function changeLock($type) {
359
+        $this->fileView->changeLock($this->path, $type);
360
+    }
361
+
362
+    public function getFileInfo() {
363
+        return $this->info;
364
+    }
365
+
366
+    protected function sanitizeMtime($mtimeFromRequest) {
367
+        // In PHP 5.X "is_numeric" returns true for strings in hexadecimal
368
+        // notation. This is no longer the case in PHP 7.X, so this check
369
+        // ensures that strings with hexadecimal notations fail too in PHP 5.X.
370
+        $isHexadecimal = is_string($mtimeFromRequest) && preg_match('/^\s*0[xX]/', $mtimeFromRequest);
371
+        if ($isHexadecimal || !is_numeric($mtimeFromRequest)) {
372
+            throw new \InvalidArgumentException('X-OC-MTime header must be an integer (unix timestamp).');
373
+        }
374
+
375
+        return (int)$mtimeFromRequest;
376
+    }
377 377
 
378 378
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 		// verify path of the target
135 135
 		$this->verifyPath();
136 136
 
137
-		$newPath = $parentPath . '/' . $newName;
137
+		$newPath = $parentPath.'/'.$newName;
138 138
 
139 139
 		$this->fileView->rename($this->path, $newPath);
140 140
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	public function getLastModified() {
156 156
 		$timestamp = $this->info->getMtime();
157 157
 		if (!empty($timestamp)) {
158
-			return (int)$timestamp;
158
+			return (int) $timestamp;
159 159
 		}
160 160
 		return $timestamp;
161 161
 	}
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 * @return string
184 184
 	 */
185 185
 	public function getETag() {
186
-		return '"' . $this->info->getEtag() . '"';
186
+		return '"'.$this->info->getEtag().'"';
187 187
 	}
188 188
 
189 189
 	/**
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 		if ($this->info->getId()) {
223 223
 			$instanceId = \OC_Util::getInstanceId();
224 224
 			$id = sprintf('%08d', $this->info->getId());
225
-			return $id . $instanceId;
225
+			return $id.$instanceId;
226 226
 		}
227 227
 
228 228
 		return null;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 
260 260
 		if ($storage && $storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
261 261
 			/** @var \OCA\Files_Sharing\SharedStorage $storage */
262
-			$permissions = (int)$storage->getShare()->getPermissions();
262
+			$permissions = (int) $storage->getShare()->getPermissions();
263 263
 		} else {
264 264
 			$permissions = $this->info->getPermissions();
265 265
 		}
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 			throw new \InvalidArgumentException('X-OC-MTime header must be an integer (unix timestamp).');
373 373
 		}
374 374
 
375
-		return (int)$mtimeFromRequest;
375
+		return (int) $mtimeFromRequest;
376 376
 	}
377 377
 
378 378
 }
Please login to merge, or discard this patch.