Passed
Push — master ( e280c0...f0b46e )
by Joas
14:20 queued 11s
created
apps/files/lib/Service/OwnershipTransferService.php 2 patches
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -58,301 +58,301 @@
 block discarded – undo
58 58
 
59 59
 class OwnershipTransferService {
60 60
 
61
-	/** @var IEncryptionManager */
62
-	private $encryptionManager;
63
-
64
-	/** @var IShareManager */
65
-	private $shareManager;
66
-
67
-	/** @var IMountManager */
68
-	private $mountManager;
69
-
70
-	/** @var IUserMountCache */
71
-	private $userMountCache;
72
-
73
-	public function __construct(IEncryptionManager $manager,
74
-								IShareManager $shareManager,
75
-								IMountManager $mountManager,
76
-								IUserMountCache $userMountCache) {
77
-		$this->encryptionManager = $manager;
78
-		$this->shareManager = $shareManager;
79
-		$this->mountManager = $mountManager;
80
-		$this->userMountCache = $userMountCache;
81
-	}
82
-
83
-	/**
84
-	 * @param IUser $sourceUser
85
-	 * @param IUser $destinationUser
86
-	 * @param string $path
87
-	 *
88
-	 * @param OutputInterface|null $output
89
-	 * @param bool $move
90
-	 * @throws TransferOwnershipException
91
-	 * @throws \OC\User\NoUserException
92
-	 */
93
-	public function transfer(IUser $sourceUser,
94
-							 IUser $destinationUser,
95
-							 string $path,
96
-							 ?OutputInterface $output = null,
97
-							 bool $move = false,
98
-							 bool $firstLogin = false): void {
99
-		$output = $output ?? new NullOutput();
100
-		$sourceUid = $sourceUser->getUID();
101
-		$destinationUid = $destinationUser->getUID();
102
-		$sourcePath = rtrim($sourceUid . '/files/' . $path, '/');
103
-
104
-		// target user has to be ready
105
-		if ($destinationUser->getLastLogin() === 0 || !$this->encryptionManager->isReadyForUser($destinationUid)) {
106
-			throw new TransferOwnershipException("The target user is not ready to accept files. The user has at least to have logged in once.", 2);
107
-		}
108
-
109
-		// setup filesystem
110
-		Filesystem::initMountPoints($sourceUid);
111
-		Filesystem::initMountPoints($destinationUid);
112
-
113
-		$view = new View();
114
-
115
-		if ($move) {
116
-			$finalTarget = "$destinationUid/files/";
117
-		} else {
118
-			$date = date('Y-m-d H-i-s');
119
-
120
-			// Remove some characters which are prone to cause errors
121
-			$cleanUserName = str_replace(['\\', '/', ':', '.', '?', '#', '\'', '"'], '-', $sourceUser->getDisplayName());
122
-			// Replace multiple dashes with one dash
123
-			$cleanUserName = preg_replace('/-{2,}/s', '-', $cleanUserName);
124
-			$cleanUserName = $cleanUserName ?: $sourceUid;
125
-
126
-			$finalTarget = "$destinationUid/files/transferred from $cleanUserName on $date";
127
-			try {
128
-				$view->verifyPath(dirname($finalTarget), basename($finalTarget));
129
-			} catch (InvalidPathException $e) {
130
-				$finalTarget = "$destinationUid/files/transferred from $sourceUid on $date";
131
-			}
132
-		}
133
-
134
-		if (!($view->is_dir($sourcePath) || $view->is_file($sourcePath))) {
135
-			throw new TransferOwnershipException("Unknown path provided: $path", 1);
136
-		}
137
-
138
-		if ($move && (
139
-				!$view->is_dir($finalTarget) || (
140
-					!$firstLogin &&
141
-					count($view->getDirectoryContent($finalTarget)) > 0
142
-				)
143
-			)
144
-		) {
145
-			throw new TransferOwnershipException("Destination path does not exists or is not empty", 1);
146
-		}
147
-
148
-
149
-		// analyse source folder
150
-		$this->analyse(
151
-			$sourceUid,
152
-			$destinationUid,
153
-			$sourcePath,
154
-			$view,
155
-			$output
156
-		);
157
-
158
-		// collect all the shares
159
-		$shares = $this->collectUsersShares(
160
-			$sourceUid,
161
-			$output,
162
-			$view,
163
-			$sourcePath
164
-		);
165
-
166
-		// transfer the files
167
-		$this->transferFiles(
168
-			$sourceUid,
169
-			$sourcePath,
170
-			$finalTarget,
171
-			$view,
172
-			$output
173
-		);
174
-
175
-		// restore the shares
176
-		$this->restoreShares(
177
-			$sourceUid,
178
-			$destinationUid,
179
-			$shares,
180
-			$output
181
-		);
182
-	}
183
-
184
-	private function walkFiles(View $view, $path, Closure $callBack) {
185
-		foreach ($view->getDirectoryContent($path) as $fileInfo) {
186
-			if (!$callBack($fileInfo)) {
187
-				return;
188
-			}
189
-			if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
190
-				$this->walkFiles($view, $fileInfo->getPath(), $callBack);
191
-			}
192
-		}
193
-	}
194
-
195
-	/**
196
-	 * @param OutputInterface $output
197
-	 *
198
-	 * @throws \Exception
199
-	 */
200
-	protected function analyse(string $sourceUid,
201
-							   string $destinationUid,
202
-							   string $sourcePath,
203
-							   View $view,
204
-							   OutputInterface $output): void {
205
-		$output->writeln('Validating quota');
206
-		$size = $view->getFileInfo($sourcePath, false)->getSize(false);
207
-		$freeSpace = $view->free_space($destinationUid . '/files/');
208
-		if ($size > $freeSpace && $freeSpace !== FileInfo::SPACE_UNKNOWN) {
209
-			$output->writeln('<error>Target user does not have enough free space available.</error>');
210
-			throw new \Exception('Execution terminated.');
211
-		}
212
-
213
-		$output->writeln("Analysing files of $sourceUid ...");
214
-		$progress = new ProgressBar($output);
215
-		$progress->start();
216
-
217
-		$encryptedFiles = [];
218
-		$this->walkFiles($view, $sourcePath,
219
-			function (FileInfo $fileInfo) use ($progress) {
220
-				if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
221
-					// only analyze into folders from main storage,
222
-					if (!$fileInfo->getStorage()->instanceOfStorage(IHomeStorage::class)) {
223
-						return false;
224
-					}
225
-					return true;
226
-				}
227
-				$progress->advance();
228
-				if ($fileInfo->isEncrypted()) {
229
-					$encryptedFiles[] = $fileInfo;
230
-				}
231
-				return true;
232
-			});
233
-		$progress->finish();
234
-		$output->writeln('');
235
-
236
-		// no file is allowed to be encrypted
237
-		if (!empty($encryptedFiles)) {
238
-			$output->writeln("<error>Some files are encrypted - please decrypt them first.</error>");
239
-			foreach ($encryptedFiles as $encryptedFile) {
240
-				/** @var FileInfo $encryptedFile */
241
-				$output->writeln("  " . $encryptedFile->getPath());
242
-			}
243
-			throw new \Exception('Execution terminated.');
244
-		}
245
-	}
246
-
247
-	private function collectUsersShares(string $sourceUid,
248
-										OutputInterface $output,
249
-										View $view,
250
-										string $path): array {
251
-		$output->writeln("Collecting all share information for files and folders of $sourceUid ...");
252
-
253
-		$shares = [];
254
-		$progress = new ProgressBar($output);
255
-		foreach ([IShare::TYPE_GROUP, IShare::TYPE_USER, IShare::TYPE_LINK, IShare::TYPE_REMOTE, IShare::TYPE_ROOM, IShare::TYPE_EMAIL, IShare::TYPE_CIRCLE] as $shareType) {
256
-			$offset = 0;
257
-			while (true) {
258
-				$sharePage = $this->shareManager->getSharesBy($sourceUid, $shareType, null, true, 50, $offset);
259
-				$progress->advance(count($sharePage));
260
-				if (empty($sharePage)) {
261
-					break;
262
-				}
263
-				if ($path !== "$sourceUid/files") {
264
-					$sharePage = array_filter($sharePage, function (IShare $share) use ($view, $path) {
265
-						try {
266
-							$relativePath = $view->getPath($share->getNodeId());
267
-							$singleFileTranfer = $view->is_file($path);
268
-							if ($singleFileTranfer) {
269
-								return Filesystem::normalizePath($relativePath) === Filesystem::normalizePath($path);
270
-							}
271
-
272
-							return mb_strpos(
273
-								Filesystem::normalizePath($relativePath . '/', false),
274
-								Filesystem::normalizePath($path . '/', false)) === 0;
275
-						} catch (\Exception $e) {
276
-							return false;
277
-						}
278
-					});
279
-				}
280
-				$shares = array_merge($shares, $sharePage);
281
-				$offset += 50;
282
-			}
283
-		}
284
-
285
-		$progress->finish();
286
-		$output->writeln('');
287
-		return $shares;
288
-	}
289
-
290
-	/**
291
-	 * @throws TransferOwnershipException
292
-	 */
293
-	protected function transferFiles(string $sourceUid,
294
-									 string $sourcePath,
295
-									 string $finalTarget,
296
-									 View $view,
297
-									 OutputInterface $output): void {
298
-		$output->writeln("Transferring files to $finalTarget ...");
299
-
300
-		// This change will help user to transfer the folder specified using --path option.
301
-		// Else only the content inside folder is transferred which is not correct.
302
-		if ($sourcePath !== "$sourceUid/files") {
303
-			$view->mkdir($finalTarget);
304
-			$finalTarget = $finalTarget . '/' . basename($sourcePath);
305
-		}
306
-		if ($view->rename($sourcePath, $finalTarget) === false) {
307
-			throw new TransferOwnershipException("Could not transfer files.", 1);
308
-		}
309
-		if (!is_dir("$sourceUid/files")) {
310
-			// because the files folder is moved away we need to recreate it
311
-			$view->mkdir("$sourceUid/files");
312
-		}
313
-	}
314
-
315
-	private function restoreShares(string $sourceUid,
316
-								   string $destinationUid,
317
-								   array $shares,
318
-								   OutputInterface $output) {
319
-		$output->writeln("Restoring shares ...");
320
-		$progress = new ProgressBar($output, count($shares));
321
-
322
-		foreach ($shares as $share) {
323
-			try {
324
-				if ($share->getShareType() === IShare::TYPE_USER &&
325
-					$share->getSharedWith() === $destinationUid) {
326
-					// Unmount the shares before deleting, so we don't try to get the storage later on.
327
-					$shareMountPoint = $this->mountManager->find('/' . $destinationUid . '/files' . $share->getTarget());
328
-					if ($shareMountPoint) {
329
-						$this->mountManager->removeMount($shareMountPoint->getMountPoint());
330
-					}
331
-					$this->shareManager->deleteShare($share);
332
-				} else {
333
-					if ($share->getShareOwner() === $sourceUid) {
334
-						$share->setShareOwner($destinationUid);
335
-					}
336
-					if ($share->getSharedBy() === $sourceUid) {
337
-						$share->setSharedBy($destinationUid);
338
-					}
339
-
340
-
341
-					// trigger refetching of the node so that the new owner and mountpoint are taken into account
342
-					// otherwise the checks on the share update will fail due to the original node not being available in the new user scope
343
-					$this->userMountCache->clear();
344
-					$share->setNodeId($share->getNode()->getId());
345
-
346
-					$this->shareManager->updateShare($share);
347
-				}
348
-			} catch (\OCP\Files\NotFoundException $e) {
349
-				$output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');
350
-			} catch (\Throwable $e) {
351
-				$output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>');
352
-			}
353
-			$progress->advance();
354
-		}
355
-		$progress->finish();
356
-		$output->writeln('');
357
-	}
61
+    /** @var IEncryptionManager */
62
+    private $encryptionManager;
63
+
64
+    /** @var IShareManager */
65
+    private $shareManager;
66
+
67
+    /** @var IMountManager */
68
+    private $mountManager;
69
+
70
+    /** @var IUserMountCache */
71
+    private $userMountCache;
72
+
73
+    public function __construct(IEncryptionManager $manager,
74
+                                IShareManager $shareManager,
75
+                                IMountManager $mountManager,
76
+                                IUserMountCache $userMountCache) {
77
+        $this->encryptionManager = $manager;
78
+        $this->shareManager = $shareManager;
79
+        $this->mountManager = $mountManager;
80
+        $this->userMountCache = $userMountCache;
81
+    }
82
+
83
+    /**
84
+     * @param IUser $sourceUser
85
+     * @param IUser $destinationUser
86
+     * @param string $path
87
+     *
88
+     * @param OutputInterface|null $output
89
+     * @param bool $move
90
+     * @throws TransferOwnershipException
91
+     * @throws \OC\User\NoUserException
92
+     */
93
+    public function transfer(IUser $sourceUser,
94
+                                IUser $destinationUser,
95
+                                string $path,
96
+                             ?OutputInterface $output = null,
97
+                                bool $move = false,
98
+                                bool $firstLogin = false): void {
99
+        $output = $output ?? new NullOutput();
100
+        $sourceUid = $sourceUser->getUID();
101
+        $destinationUid = $destinationUser->getUID();
102
+        $sourcePath = rtrim($sourceUid . '/files/' . $path, '/');
103
+
104
+        // target user has to be ready
105
+        if ($destinationUser->getLastLogin() === 0 || !$this->encryptionManager->isReadyForUser($destinationUid)) {
106
+            throw new TransferOwnershipException("The target user is not ready to accept files. The user has at least to have logged in once.", 2);
107
+        }
108
+
109
+        // setup filesystem
110
+        Filesystem::initMountPoints($sourceUid);
111
+        Filesystem::initMountPoints($destinationUid);
112
+
113
+        $view = new View();
114
+
115
+        if ($move) {
116
+            $finalTarget = "$destinationUid/files/";
117
+        } else {
118
+            $date = date('Y-m-d H-i-s');
119
+
120
+            // Remove some characters which are prone to cause errors
121
+            $cleanUserName = str_replace(['\\', '/', ':', '.', '?', '#', '\'', '"'], '-', $sourceUser->getDisplayName());
122
+            // Replace multiple dashes with one dash
123
+            $cleanUserName = preg_replace('/-{2,}/s', '-', $cleanUserName);
124
+            $cleanUserName = $cleanUserName ?: $sourceUid;
125
+
126
+            $finalTarget = "$destinationUid/files/transferred from $cleanUserName on $date";
127
+            try {
128
+                $view->verifyPath(dirname($finalTarget), basename($finalTarget));
129
+            } catch (InvalidPathException $e) {
130
+                $finalTarget = "$destinationUid/files/transferred from $sourceUid on $date";
131
+            }
132
+        }
133
+
134
+        if (!($view->is_dir($sourcePath) || $view->is_file($sourcePath))) {
135
+            throw new TransferOwnershipException("Unknown path provided: $path", 1);
136
+        }
137
+
138
+        if ($move && (
139
+                !$view->is_dir($finalTarget) || (
140
+                    !$firstLogin &&
141
+                    count($view->getDirectoryContent($finalTarget)) > 0
142
+                )
143
+            )
144
+        ) {
145
+            throw new TransferOwnershipException("Destination path does not exists or is not empty", 1);
146
+        }
147
+
148
+
149
+        // analyse source folder
150
+        $this->analyse(
151
+            $sourceUid,
152
+            $destinationUid,
153
+            $sourcePath,
154
+            $view,
155
+            $output
156
+        );
157
+
158
+        // collect all the shares
159
+        $shares = $this->collectUsersShares(
160
+            $sourceUid,
161
+            $output,
162
+            $view,
163
+            $sourcePath
164
+        );
165
+
166
+        // transfer the files
167
+        $this->transferFiles(
168
+            $sourceUid,
169
+            $sourcePath,
170
+            $finalTarget,
171
+            $view,
172
+            $output
173
+        );
174
+
175
+        // restore the shares
176
+        $this->restoreShares(
177
+            $sourceUid,
178
+            $destinationUid,
179
+            $shares,
180
+            $output
181
+        );
182
+    }
183
+
184
+    private function walkFiles(View $view, $path, Closure $callBack) {
185
+        foreach ($view->getDirectoryContent($path) as $fileInfo) {
186
+            if (!$callBack($fileInfo)) {
187
+                return;
188
+            }
189
+            if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
190
+                $this->walkFiles($view, $fileInfo->getPath(), $callBack);
191
+            }
192
+        }
193
+    }
194
+
195
+    /**
196
+     * @param OutputInterface $output
197
+     *
198
+     * @throws \Exception
199
+     */
200
+    protected function analyse(string $sourceUid,
201
+                                string $destinationUid,
202
+                                string $sourcePath,
203
+                                View $view,
204
+                                OutputInterface $output): void {
205
+        $output->writeln('Validating quota');
206
+        $size = $view->getFileInfo($sourcePath, false)->getSize(false);
207
+        $freeSpace = $view->free_space($destinationUid . '/files/');
208
+        if ($size > $freeSpace && $freeSpace !== FileInfo::SPACE_UNKNOWN) {
209
+            $output->writeln('<error>Target user does not have enough free space available.</error>');
210
+            throw new \Exception('Execution terminated.');
211
+        }
212
+
213
+        $output->writeln("Analysing files of $sourceUid ...");
214
+        $progress = new ProgressBar($output);
215
+        $progress->start();
216
+
217
+        $encryptedFiles = [];
218
+        $this->walkFiles($view, $sourcePath,
219
+            function (FileInfo $fileInfo) use ($progress) {
220
+                if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
221
+                    // only analyze into folders from main storage,
222
+                    if (!$fileInfo->getStorage()->instanceOfStorage(IHomeStorage::class)) {
223
+                        return false;
224
+                    }
225
+                    return true;
226
+                }
227
+                $progress->advance();
228
+                if ($fileInfo->isEncrypted()) {
229
+                    $encryptedFiles[] = $fileInfo;
230
+                }
231
+                return true;
232
+            });
233
+        $progress->finish();
234
+        $output->writeln('');
235
+
236
+        // no file is allowed to be encrypted
237
+        if (!empty($encryptedFiles)) {
238
+            $output->writeln("<error>Some files are encrypted - please decrypt them first.</error>");
239
+            foreach ($encryptedFiles as $encryptedFile) {
240
+                /** @var FileInfo $encryptedFile */
241
+                $output->writeln("  " . $encryptedFile->getPath());
242
+            }
243
+            throw new \Exception('Execution terminated.');
244
+        }
245
+    }
246
+
247
+    private function collectUsersShares(string $sourceUid,
248
+                                        OutputInterface $output,
249
+                                        View $view,
250
+                                        string $path): array {
251
+        $output->writeln("Collecting all share information for files and folders of $sourceUid ...");
252
+
253
+        $shares = [];
254
+        $progress = new ProgressBar($output);
255
+        foreach ([IShare::TYPE_GROUP, IShare::TYPE_USER, IShare::TYPE_LINK, IShare::TYPE_REMOTE, IShare::TYPE_ROOM, IShare::TYPE_EMAIL, IShare::TYPE_CIRCLE] as $shareType) {
256
+            $offset = 0;
257
+            while (true) {
258
+                $sharePage = $this->shareManager->getSharesBy($sourceUid, $shareType, null, true, 50, $offset);
259
+                $progress->advance(count($sharePage));
260
+                if (empty($sharePage)) {
261
+                    break;
262
+                }
263
+                if ($path !== "$sourceUid/files") {
264
+                    $sharePage = array_filter($sharePage, function (IShare $share) use ($view, $path) {
265
+                        try {
266
+                            $relativePath = $view->getPath($share->getNodeId());
267
+                            $singleFileTranfer = $view->is_file($path);
268
+                            if ($singleFileTranfer) {
269
+                                return Filesystem::normalizePath($relativePath) === Filesystem::normalizePath($path);
270
+                            }
271
+
272
+                            return mb_strpos(
273
+                                Filesystem::normalizePath($relativePath . '/', false),
274
+                                Filesystem::normalizePath($path . '/', false)) === 0;
275
+                        } catch (\Exception $e) {
276
+                            return false;
277
+                        }
278
+                    });
279
+                }
280
+                $shares = array_merge($shares, $sharePage);
281
+                $offset += 50;
282
+            }
283
+        }
284
+
285
+        $progress->finish();
286
+        $output->writeln('');
287
+        return $shares;
288
+    }
289
+
290
+    /**
291
+     * @throws TransferOwnershipException
292
+     */
293
+    protected function transferFiles(string $sourceUid,
294
+                                        string $sourcePath,
295
+                                        string $finalTarget,
296
+                                        View $view,
297
+                                        OutputInterface $output): void {
298
+        $output->writeln("Transferring files to $finalTarget ...");
299
+
300
+        // This change will help user to transfer the folder specified using --path option.
301
+        // Else only the content inside folder is transferred which is not correct.
302
+        if ($sourcePath !== "$sourceUid/files") {
303
+            $view->mkdir($finalTarget);
304
+            $finalTarget = $finalTarget . '/' . basename($sourcePath);
305
+        }
306
+        if ($view->rename($sourcePath, $finalTarget) === false) {
307
+            throw new TransferOwnershipException("Could not transfer files.", 1);
308
+        }
309
+        if (!is_dir("$sourceUid/files")) {
310
+            // because the files folder is moved away we need to recreate it
311
+            $view->mkdir("$sourceUid/files");
312
+        }
313
+    }
314
+
315
+    private function restoreShares(string $sourceUid,
316
+                                    string $destinationUid,
317
+                                    array $shares,
318
+                                    OutputInterface $output) {
319
+        $output->writeln("Restoring shares ...");
320
+        $progress = new ProgressBar($output, count($shares));
321
+
322
+        foreach ($shares as $share) {
323
+            try {
324
+                if ($share->getShareType() === IShare::TYPE_USER &&
325
+                    $share->getSharedWith() === $destinationUid) {
326
+                    // Unmount the shares before deleting, so we don't try to get the storage later on.
327
+                    $shareMountPoint = $this->mountManager->find('/' . $destinationUid . '/files' . $share->getTarget());
328
+                    if ($shareMountPoint) {
329
+                        $this->mountManager->removeMount($shareMountPoint->getMountPoint());
330
+                    }
331
+                    $this->shareManager->deleteShare($share);
332
+                } else {
333
+                    if ($share->getShareOwner() === $sourceUid) {
334
+                        $share->setShareOwner($destinationUid);
335
+                    }
336
+                    if ($share->getSharedBy() === $sourceUid) {
337
+                        $share->setSharedBy($destinationUid);
338
+                    }
339
+
340
+
341
+                    // trigger refetching of the node so that the new owner and mountpoint are taken into account
342
+                    // otherwise the checks on the share update will fail due to the original node not being available in the new user scope
343
+                    $this->userMountCache->clear();
344
+                    $share->setNodeId($share->getNode()->getId());
345
+
346
+                    $this->shareManager->updateShare($share);
347
+                }
348
+            } catch (\OCP\Files\NotFoundException $e) {
349
+                $output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');
350
+            } catch (\Throwable $e) {
351
+                $output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>');
352
+            }
353
+            $progress->advance();
354
+        }
355
+        $progress->finish();
356
+        $output->writeln('');
357
+    }
358 358
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 		$output = $output ?? new NullOutput();
100 100
 		$sourceUid = $sourceUser->getUID();
101 101
 		$destinationUid = $destinationUser->getUID();
102
-		$sourcePath = rtrim($sourceUid . '/files/' . $path, '/');
102
+		$sourcePath = rtrim($sourceUid.'/files/'.$path, '/');
103 103
 
104 104
 		// target user has to be ready
105 105
 		if ($destinationUser->getLastLogin() === 0 || !$this->encryptionManager->isReadyForUser($destinationUid)) {
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 							   OutputInterface $output): void {
205 205
 		$output->writeln('Validating quota');
206 206
 		$size = $view->getFileInfo($sourcePath, false)->getSize(false);
207
-		$freeSpace = $view->free_space($destinationUid . '/files/');
207
+		$freeSpace = $view->free_space($destinationUid.'/files/');
208 208
 		if ($size > $freeSpace && $freeSpace !== FileInfo::SPACE_UNKNOWN) {
209 209
 			$output->writeln('<error>Target user does not have enough free space available.</error>');
210 210
 			throw new \Exception('Execution terminated.');
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 
217 217
 		$encryptedFiles = [];
218 218
 		$this->walkFiles($view, $sourcePath,
219
-			function (FileInfo $fileInfo) use ($progress) {
219
+			function(FileInfo $fileInfo) use ($progress) {
220 220
 				if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
221 221
 					// only analyze into folders from main storage,
222 222
 					if (!$fileInfo->getStorage()->instanceOfStorage(IHomeStorage::class)) {
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 			$output->writeln("<error>Some files are encrypted - please decrypt them first.</error>");
239 239
 			foreach ($encryptedFiles as $encryptedFile) {
240 240
 				/** @var FileInfo $encryptedFile */
241
-				$output->writeln("  " . $encryptedFile->getPath());
241
+				$output->writeln("  ".$encryptedFile->getPath());
242 242
 			}
243 243
 			throw new \Exception('Execution terminated.');
244 244
 		}
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 					break;
262 262
 				}
263 263
 				if ($path !== "$sourceUid/files") {
264
-					$sharePage = array_filter($sharePage, function (IShare $share) use ($view, $path) {
264
+					$sharePage = array_filter($sharePage, function(IShare $share) use ($view, $path) {
265 265
 						try {
266 266
 							$relativePath = $view->getPath($share->getNodeId());
267 267
 							$singleFileTranfer = $view->is_file($path);
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
 							}
271 271
 
272 272
 							return mb_strpos(
273
-								Filesystem::normalizePath($relativePath . '/', false),
274
-								Filesystem::normalizePath($path . '/', false)) === 0;
273
+								Filesystem::normalizePath($relativePath.'/', false),
274
+								Filesystem::normalizePath($path.'/', false)) === 0;
275 275
 						} catch (\Exception $e) {
276 276
 							return false;
277 277
 						}
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 		// Else only the content inside folder is transferred which is not correct.
302 302
 		if ($sourcePath !== "$sourceUid/files") {
303 303
 			$view->mkdir($finalTarget);
304
-			$finalTarget = $finalTarget . '/' . basename($sourcePath);
304
+			$finalTarget = $finalTarget.'/'.basename($sourcePath);
305 305
 		}
306 306
 		if ($view->rename($sourcePath, $finalTarget) === false) {
307 307
 			throw new TransferOwnershipException("Could not transfer files.", 1);
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 				if ($share->getShareType() === IShare::TYPE_USER &&
325 325
 					$share->getSharedWith() === $destinationUid) {
326 326
 					// Unmount the shares before deleting, so we don't try to get the storage later on.
327
-					$shareMountPoint = $this->mountManager->find('/' . $destinationUid . '/files' . $share->getTarget());
327
+					$shareMountPoint = $this->mountManager->find('/'.$destinationUid.'/files'.$share->getTarget());
328 328
 					if ($shareMountPoint) {
329 329
 						$this->mountManager->removeMount($shareMountPoint->getMountPoint());
330 330
 					}
@@ -346,9 +346,9 @@  discard block
 block discarded – undo
346 346
 					$this->shareManager->updateShare($share);
347 347
 				}
348 348
 			} catch (\OCP\Files\NotFoundException $e) {
349
-				$output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');
349
+				$output->writeln('<error>Share with id '.$share->getId().' points at deleted file, skipping</error>');
350 350
 			} catch (\Throwable $e) {
351
-				$output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>');
351
+				$output->writeln('<error>Could not restore share with id '.$share->getId().':'.$e->getTraceAsString().'</error>');
352 352
 			}
353 353
 			$progress->advance();
354 354
 		}
Please login to merge, or discard this patch.