Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for naming conflicts before returning the user mounts #523

Merged
merged 2 commits into from
Aug 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/Mount/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Folder;
use OCP\Files\IHomeStorage;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageFactory;
Expand Down Expand Up @@ -85,7 +86,22 @@ public function getFoldersForUser(IUser $user) {
public function getMountsForUser(IUser $user, IStorageFactory $loader) {
$folders = $this->getFoldersForUser($user);

return array_map(function ($folder) use ($user, $loader) {
/** @var Folder $folder */
$userHome = \OC::$server->getRootFolder()->getUserFolder($user->getUID());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this trigger cyclic things?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't seem so when testing, but indeed this seems like it could cause issues. I'll dig a bit deeper tomorrow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, as the mountpoints are only setup once for the user. So when getRootFolder is called, initMountPoints will not execute again.

https://github.com/nextcloud/server/blob/1b85ef4bf2a18f7ee7bca7bcd3d7702362125d2e/lib/private/Files/Filesystem.php#L403

The issue I see would be that mount providers that are registered after the group folder provider don't have their mountpoints added to the user root at that point. For sharing mounts this is handled by manually forcing that mount provider to be the last mounted. https://github.com/nextcloud/server/blob/3ad6084891b88b3b7ef784bbf297b0a57b282d77/lib/private/Files/Config/MountProviderCollection.php#L93-L101

But I assume we should only rename regular users files anyway, so that shouldn't be an issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok lets just try it then...

return array_map(function ($folder) use ($user, $loader, $userHome) {
// check for existing files in the user home and rename them if needed
$folderName = $folder['mount_point'];
$i = 1;
while($userHome->nodeExists($folderName)) {
$folderName = $folder['mount_point'] . ' (' . $i++ . ')';
}
if ($folderName !== $folder['mount_point']) {
$node = $userHome->get($folder['mount_point']);
if ($node->getStorage()->instanceOfStorage('\OCP\Files\IHomeStorage')) {
$node->move($userHome->getPath() . '/' . $folderName);
}
}

return $this->getMount(
$folder['folder_id'],
'/' . $user->getUID() . '/files/' . $folder['mount_point'],
Expand Down