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;
/** @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;
}
/**
// collect all the shares
$shares = $this->collectUsersShares(
$sourceUid,
- $output
+ $output,
+ $view,
+ $sourcePath
);
// transfer the files
}
private function collectUsersShares(string $sourceUid,
- OutputInterface $output): array {
+ OutputInterface $output,
+ View $view,
+ ?string $path = null): array {
$output->writeln("Collecting all share information for files and folders of $sourceUid ...");
$shares = [];
if (empty($sharePage)) {
break;
}
+ if ($path !== null) {
+ $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;
}
$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) {