aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/lib')
-rw-r--r--apps/files/lib/BackgroundJob/ScanFiles.php6
-rw-r--r--apps/files/lib/Command/TransferOwnership.php24
-rw-r--r--apps/files/lib/Controller/ViewController.php2
-rw-r--r--apps/files/lib/Listener/SyncLivePhotosListener.php10
-rw-r--r--apps/files/lib/Service/OwnershipTransferService.php77
5 files changed, 55 insertions, 64 deletions
diff --git a/apps/files/lib/BackgroundJob/ScanFiles.php b/apps/files/lib/BackgroundJob/ScanFiles.php
index b7e6e8db10e..cb2d8e218f7 100644
--- a/apps/files/lib/BackgroundJob/ScanFiles.php
+++ b/apps/files/lib/BackgroundJob/ScanFiles.php
@@ -79,7 +79,7 @@ class ScanFiles extends TimedJob {
$query->select('m.user_id')
->from('filecache', 'f')
->leftJoin('f', 'mounts', 'm', $query->expr()->eq('m.storage_id', 'f.storage'))
- ->where($query->expr()->lt('f.size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
+ ->where($query->expr()->eq('f.size', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->gt('f.parent', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->setMaxResults(10)
->groupBy('f.storage')
@@ -100,7 +100,7 @@ class ScanFiles extends TimedJob {
$query->select('m.user_id')
->from('filecache', 'f')
->leftJoin('f', 'mounts', 'm', $query->expr()->eq('m.storage_id', 'f.storage'))
- ->where($query->expr()->lt('f.size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
+ ->where($query->expr()->eq('f.size', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->gt('f.parent', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->in('f.storage', $query->createNamedParameter($storages, IQueryBuilder::PARAM_INT_ARRAY)))
->setMaxResults(1)
@@ -111,7 +111,7 @@ class ScanFiles extends TimedJob {
$query->select('m.user_id')
->from('filecache', 'f')
->innerJoin('f', 'mounts', 'm', $query->expr()->eq('m.storage_id', 'f.storage'))
- ->where($query->expr()->lt('f.size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
+ ->where($query->expr()->eq('f.size', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->gt('f.parent', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->setMaxResults(1)
->runAcrossAllShards();
diff --git a/apps/files/lib/Command/TransferOwnership.php b/apps/files/lib/Command/TransferOwnership.php
index edc73e62c38..c235fc88960 100644
--- a/apps/files/lib/Command/TransferOwnership.php
+++ b/apps/files/lib/Command/TransferOwnership.php
@@ -58,7 +58,7 @@ class TransferOwnership extends Command {
'transfer-incoming-shares',
null,
InputOption::VALUE_OPTIONAL,
- 'transfer incoming user file shares to destination user. Usage: --transfer-incoming-shares=1 (value required)',
+ 'Incoming shares are always transferred now, so this option does not affect the ownership transfer anymore',
'2'
);
}
@@ -88,27 +88,6 @@ class TransferOwnership extends Command {
}
try {
- $includeIncomingArgument = $input->getOption('transfer-incoming-shares');
-
- switch ($includeIncomingArgument) {
- case '0':
- $includeIncoming = false;
- break;
- case '1':
- $includeIncoming = true;
- break;
- case '2':
- $includeIncoming = $this->config->getSystemValue('transferIncomingShares', false);
- if (gettype($includeIncoming) !== 'boolean') {
- $output->writeln("<error> config.php: 'transfer-incoming-shares': wrong usage. Transfer aborted.</error>");
- return self::FAILURE;
- }
- break;
- default:
- $output->writeln('<error>Option --transfer-incoming-shares: wrong usage. Transfer aborted.</error>');
- return self::FAILURE;
- }
-
$this->transferService->transfer(
$sourceUserObject,
$destinationUserObject,
@@ -116,7 +95,6 @@ class TransferOwnership extends Command {
$output,
$input->getOption('move') === true,
false,
- $includeIncoming
);
} catch (TransferOwnershipException $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php
index 70ead0a5fe2..8ecb6825bf5 100644
--- a/apps/files/lib/Controller/ViewController.php
+++ b/apps/files/lib/Controller/ViewController.php
@@ -191,7 +191,7 @@ class ViewController extends Controller {
$this->eventDispatcher->dispatchTyped(new LoadViewer());
}
- $this->initialState->provideInitialState('templates_enabled', ($this->config->getSystemValueString('skeletondirectory', '') !== '') || ($this->config->getSystemValueString('templatedirectory', '') !== ''));
+ $this->initialState->provideInitialState('templates_enabled', ($this->config->getSystemValueString('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton') !== '') || ($this->config->getSystemValueString('templatedirectory', \OC::$SERVERROOT . '/core/skeleton/Templates') !== ''));
$this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false);
$this->initialState->provideInitialState('templates', $this->templateManager->listCreators());
diff --git a/apps/files/lib/Listener/SyncLivePhotosListener.php b/apps/files/lib/Listener/SyncLivePhotosListener.php
index 17242d448a9..bae99d9fc65 100644
--- a/apps/files/lib/Listener/SyncLivePhotosListener.php
+++ b/apps/files/lib/Listener/SyncLivePhotosListener.php
@@ -37,6 +37,8 @@ class SyncLivePhotosListener implements IEventListener {
private array $pendingRenames = [];
/** @var Array<int, bool> */
private array $pendingDeletion = [];
+ /** @var Array<int> */
+ private array $pendingCopies = [];
public function __construct(
private ?Folder $userFolder,
@@ -153,7 +155,6 @@ class SyncLivePhotosListener implements IEventListener {
$targetName = $targetFile->getName();
$peerTargetName = substr($targetName, 0, -strlen($sourceExtension)) . $peerFileExtension;
-
if ($targetParent->nodeExists($peerTargetName)) {
// If the copy was a folder copy, then the peer file already exists.
$targetPeerFile = $targetParent->get($peerTargetName);
@@ -225,6 +226,11 @@ class SyncLivePhotosListener implements IEventListener {
$this->handleCopyRecursive($event, $sourceChild, $targetChild);
}
} elseif ($sourceNode instanceof File && $targetNode instanceof File) {
+ // in case the copy was initiated from this listener, we stop right now
+ if (in_array($sourceNode->getId(), $this->pendingCopies)) {
+ return;
+ }
+
$peerFileId = $this->livePhotosService->getLivePhotoPeerId($sourceNode->getId());
if ($peerFileId === null) {
return;
@@ -234,11 +240,13 @@ class SyncLivePhotosListener implements IEventListener {
return;
}
+ $this->pendingCopies[] = $peerFileId;
if ($event instanceof BeforeNodeCopiedEvent) {
$this->runMoveOrCopyChecks($sourceNode, $targetNode, $peerFile);
} elseif ($event instanceof NodeCopiedEvent) {
$this->handleCopy($sourceNode, $targetNode, $peerFile);
}
+ $this->pendingCopies = array_diff($this->pendingCopies, [$peerFileId]);
} else {
throw new Exception('Source and target type are not matching');
}
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php
index 055b3233bc0..a299c15c639 100644
--- a/apps/files/lib/Service/OwnershipTransferService.php
+++ b/apps/files/lib/Service/OwnershipTransferService.php
@@ -10,12 +10,14 @@ declare(strict_types=1);
namespace OCA\Files\Service;
use Closure;
+use Exception;
use OC\Encryption\Manager as EncryptionManager;
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\File;
use OCP\Files\FileInfo;
use OCP\Files\IHomeStorage;
use OCP\Files\InvalidPathException;
@@ -70,7 +72,6 @@ class OwnershipTransferService {
?OutputInterface $output = null,
bool $move = false,
bool $firstLogin = false,
- bool $transferIncomingShares = false,
): void {
$output = $output ?? new NullOutput();
$sourceUid = $sourceUser->getUID();
@@ -155,29 +156,26 @@ class OwnershipTransferService {
$sizeDifference = $sourceSize - $view->getFileInfo($finalTarget)->getSize();
// transfer the incoming shares
- if ($transferIncomingShares === true) {
- $sourceShares = $this->collectIncomingShares(
- $sourceUid,
- $output,
- $view
- );
- $destinationShares = $this->collectIncomingShares(
- $destinationUid,
- $output,
- $view,
- true
- );
- $this->transferIncomingShares(
- $sourceUid,
- $destinationUid,
- $sourceShares,
- $destinationShares,
- $output,
- $path,
- $finalTarget,
- $move
- );
- }
+ $sourceShares = $this->collectIncomingShares(
+ $sourceUid,
+ $output,
+ $sourcePath,
+ );
+ $destinationShares = $this->collectIncomingShares(
+ $destinationUid,
+ $output,
+ null,
+ );
+ $this->transferIncomingShares(
+ $sourceUid,
+ $destinationUid,
+ $sourceShares,
+ $destinationShares,
+ $output,
+ $path,
+ $finalTarget,
+ $move
+ );
$destinationPath = $finalTarget . '/' . $path;
// restore the shares
@@ -334,7 +332,7 @@ class OwnershipTransferService {
return mb_strpos(
Filesystem::normalizePath($relativePath . '/', false),
$normalizedPath . '/') === 0;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
return false;
}
});
@@ -362,14 +360,16 @@ class OwnershipTransferService {
}, $shares)));
}
- private function collectIncomingShares(string $sourceUid,
+ private function collectIncomingShares(
+ string $sourceUid,
OutputInterface $output,
- View $view,
- bool $addKeys = false): array {
+ ?string $path,
+ ): array {
$output->writeln("Collecting all incoming share information for files and folders of $sourceUid ...");
$shares = [];
$progress = new ProgressBar($output);
+ $normalizedPath = Filesystem::normalizePath($path);
$offset = 0;
while (true) {
@@ -378,14 +378,19 @@ class OwnershipTransferService {
if (empty($sharePage)) {
break;
}
- if ($addKeys) {
- foreach ($sharePage as $singleShare) {
- $shares[$singleShare->getNodeId()] = $singleShare;
- }
- } else {
- foreach ($sharePage as $singleShare) {
- $shares[] = $singleShare;
- }
+
+ if ($path !== null && $path !== "$sourceUid/files") {
+ $sharePage = array_filter($sharePage, static function (IShare $share) use ($sourceUid, $normalizedPath) {
+ try {
+ return str_starts_with(Filesystem::normalizePath($sourceUid . '/files' . $share->getTarget() . '/', false), $normalizedPath . '/');
+ } catch (Exception) {
+ return false;
+ }
+ });
+ }
+
+ foreach ($sharePage as $share) {
+ $shares[$share->getNodeId()] = $share;
}
$offset += 50;