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