1010namespace OCA \Files \Service ;
1111
1212use Closure ;
13+ use Exception ;
1314use OC \Files \Filesystem ;
1415use OC \Files \View ;
1516use OC \User \NoUserException ;
1617use OCA \Encryption \Util ;
1718use OCA \Files \Exception \TransferOwnershipException ;
1819use OCP \Encryption \IManager as IEncryptionManager ;
1920use OCP \Files \Config \IUserMountCache ;
21+ use OCP \Files \File ;
2022use OCP \Files \FileInfo ;
2123use OCP \Files \IHomeStorage ;
2224use OCP \Files \InvalidPathException ;
@@ -158,13 +160,12 @@ public function transfer(
158160 $ sourceShares = $ this ->collectIncomingShares (
159161 $ sourceUid ,
160162 $ output ,
161- $ view
163+ $ sourcePath ,
162164 );
163165 $ destinationShares = $ this ->collectIncomingShares (
164166 $ destinationUid ,
165167 $ output ,
166- $ view ,
167- true
168+ null ,
168169 );
169170 $ this ->transferIncomingShares (
170171 $ sourceUid ,
@@ -333,7 +334,7 @@ private function collectUsersShares(
333334 return mb_strpos (
334335 Filesystem::normalizePath ($ relativePath . '/ ' , false ),
335336 $ normalizedPath . '/ ' ) === 0 ;
336- } catch (\ Exception $ e ) {
337+ } catch (Exception $ e ) {
337338 return false ;
338339 }
339340 });
@@ -361,14 +362,16 @@ private function collectUsersShares(
361362 }, $ shares )));
362363 }
363364
364- private function collectIncomingShares (string $ sourceUid ,
365+ private function collectIncomingShares (
366+ string $ sourceUid ,
365367 OutputInterface $ output ,
366- View $ view ,
367- bool $ addKeys = false ): array {
368+ ? string $ path ,
369+ ): array {
368370 $ output ->writeln ("Collecting all incoming share information for files and folders of $ sourceUid ... " );
369371
370372 $ shares = [];
371373 $ progress = new ProgressBar ($ output );
374+ $ normalizedPath = Filesystem::normalizePath ($ path );
372375
373376 $ offset = 0 ;
374377 while (true ) {
@@ -377,14 +380,19 @@ private function collectIncomingShares(string $sourceUid,
377380 if (empty ($ sharePage )) {
378381 break ;
379382 }
380- if ($ addKeys ) {
381- foreach ($ sharePage as $ singleShare ) {
382- $ shares [$ singleShare ->getNodeId ()] = $ singleShare ;
383- }
384- } else {
385- foreach ($ sharePage as $ singleShare ) {
386- $ shares [] = $ singleShare ;
387- }
383+
384+ if ($ path !== null && $ path !== "$ sourceUid/files " ) {
385+ $ sharePage = array_filter ($ sharePage , static function (IShare $ share ) use ($ sourceUid , $ normalizedPath ) {
386+ try {
387+ return str_starts_with (Filesystem::normalizePath ($ sourceUid . '/files ' . $ share ->getTarget () . '/ ' , false ), $ normalizedPath . '/ ' );
388+ } catch (Exception ) {
389+ return false ;
390+ }
391+ });
392+ }
393+
394+ foreach ($ sharePage as $ share ) {
395+ $ shares [$ share ->getNodeId ()] = $ share ;
388396 }
389397
390398 $ offset += 50 ;
0 commit comments