summaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-10-01 08:44:51 +0200
committerGitHub <noreply@github.com>2020-10-01 08:44:51 +0200
commit7b3510491ef719650bd72e3919c4f6c5c7c42c88 (patch)
treebc89459287d3f048ab81c3722f31a19adc06fba6 /apps/files
parente359760228eaa60720c631142c612f975a9c725e (diff)
parent7954356d4e64c6b4eb61eac05f5babfc44401dbb (diff)
downloadnextcloud-server-7b3510491ef719650bd72e3919c4f6c5c7c42c88.tar.gz
nextcloud-server-7b3510491ef719650bd72e3919c4f6c5c7c42c88.zip
Merge pull request #22802 from nextcloud/backport/stable18/22116-22648-22761
[stable18] Fix share transfer of single files and on the transfered node
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/lib/Service/OwnershipTransferService.php40
1 files changed, 37 insertions, 3 deletions
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php
index f47128a8d9f..8eb031df554 100644
--- a/apps/files/lib/Service/OwnershipTransferService.php
+++ b/apps/files/lib/Service/OwnershipTransferService.php
@@ -32,12 +32,14 @@ use OC\Files\Filesystem;
use OC\Files\View;
use OCA\Files\Exception\TransferOwnershipException;
use OCP\Encryption\IManager as IEncryptionManager;
+use OCP\Files\Config\IUserMountCache;
use OCP\Files\FileInfo;
use OCP\Files\IHomeStorage;
use OCP\Files\InvalidPathException;
use OCP\Files\Mount\IMountManager;
use OCP\IUser;
use OCP\Share\IManager as IShareManager;
+use OCP\Share\IShare;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
@@ -59,12 +61,17 @@ class OwnershipTransferService {
/** @var IMountManager */
private $mountManager;
+ /** @var IUserMountCache */
+ private $userMountCache;
+
public function __construct(IEncryptionManager $manager,
IShareManager $shareManager,
- IMountManager $mountManager) {
+ IMountManager $mountManager,
+ IUserMountCache $userMountCache) {
$this->encryptionManager = $manager;
$this->shareManager = $shareManager;
$this->mountManager = $mountManager;
+ $this->userMountCache = $userMountCache;
}
/**
@@ -145,7 +152,9 @@ class OwnershipTransferService {
// collect all the shares
$shares = $this->collectUsersShares(
$sourceUid,
- $output
+ $output,
+ $view,
+ $sourcePath
);
// transfer the files
@@ -230,7 +239,9 @@ class OwnershipTransferService {
}
private function collectUsersShares(string $sourceUid,
- OutputInterface $output): array {
+ OutputInterface $output,
+ View $view,
+ string $path): array {
$output->writeln("Collecting all share information for files and folders of $sourceUid ...");
$shares = [];
@@ -243,6 +254,23 @@ class OwnershipTransferService {
if (empty($sharePage)) {
break;
}
+ if ($path !== "$sourceUid/files") {
+ $sharePage = array_filter($sharePage, function (IShare $share) use ($view, $path) {
+ try {
+ $relativePath = $view->getPath($share->getNodeId());
+ $singleFileTranfer = $view->is_file($path);
+ if ($singleFileTranfer) {
+ return Filesystem::normalizePath($relativePath) === Filesystem::normalizePath($path);
+ }
+
+ return mb_strpos(
+ Filesystem::normalizePath($relativePath . '/', false),
+ Filesystem::normalizePath($path . '/', false)) === 0;
+ } catch (\Exception $e) {
+ return false;
+ }
+ });
+ }
$shares = array_merge($shares, $sharePage);
$offset += 50;
}
@@ -303,6 +331,12 @@ class OwnershipTransferService {
$share->setSharedBy($destinationUid);
}
+
+ // trigger refetching of the node so that the new owner and mountpoint are taken into account
+ // otherwise the checks on the share update will fail due to the original node not being available in the new user scope
+ $this->userMountCache->clear();
+ $share->setNodeId($share->getNode()->getId());
+
$this->shareManager->updateShare($share);
}
} catch (\OCP\Files\NotFoundException $e) {