|
|
|
|
@ -9,6 +9,8 @@ namespace OC\Files\Cache; |
|
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Exception\DeadlockException; |
|
|
|
|
use OC\Files\FileInfo; |
|
|
|
|
use OC\Files\ObjectStore\ObjectStoreStorage; |
|
|
|
|
use OCP\Files\Cache\ICache; |
|
|
|
|
use OCP\Files\Cache\ICacheEntry; |
|
|
|
|
use OCP\Files\Cache\IUpdater; |
|
|
|
|
use OCP\Files\Storage\IStorage; |
|
|
|
|
@ -157,13 +159,40 @@ class Updater implements IUpdater { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Rename a file or folder in the cache and update the size, etag and mtime of the parent folders |
|
|
|
|
* Rename a file or folder in the cache. |
|
|
|
|
* |
|
|
|
|
* @param IStorage $sourceStorage |
|
|
|
|
* @param string $source |
|
|
|
|
* @param string $target |
|
|
|
|
*/ |
|
|
|
|
public function renameFromStorage(IStorage $sourceStorage, $source, $target) { |
|
|
|
|
$this->copyOrRenameFromStorage($sourceStorage, $source, $target, function (ICache $sourceCache) use ($sourceStorage, $source, $target) { |
|
|
|
|
// Remove existing cache entry to no reuse the fileId. |
|
|
|
|
if ($this->cache->inCache($target)) { |
|
|
|
|
$this->cache->remove($target); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($sourceStorage === $this->storage) { |
|
|
|
|
$this->cache->move($source, $target); |
|
|
|
|
} else { |
|
|
|
|
$this->cache->moveFromCache($sourceCache, $source, $target); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Copy a file or folder in the cache. |
|
|
|
|
*/ |
|
|
|
|
public function copyFromStorage(IStorage $sourceStorage, string $source, string $target): void { |
|
|
|
|
$this->copyOrRenameFromStorage($sourceStorage, $source, $target, function (ICache $sourceCache, ICacheEntry $sourceInfo) use ($target) { |
|
|
|
|
$this->cache->copyFromCache($sourceCache, $sourceInfo, $target); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Utility to copy or rename a file or folder in the cache and update the size, etag and mtime of the parent folders |
|
|
|
|
*/ |
|
|
|
|
private function copyOrRenameFromStorage(IStorage $sourceStorage, string $source, string $target, callable $operation): void { |
|
|
|
|
if (!$this->enabled or Scanner::isPartialFile($source) or Scanner::isPartialFile($target)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
@ -177,14 +206,8 @@ class Updater implements IUpdater { |
|
|
|
|
$sourceInfo = $sourceCache->get($source); |
|
|
|
|
|
|
|
|
|
if ($sourceInfo !== false) { |
|
|
|
|
if ($this->cache->inCache($target)) { |
|
|
|
|
$this->cache->remove($target); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($sourceStorage === $this->storage) { |
|
|
|
|
$this->cache->move($source, $target); |
|
|
|
|
} else { |
|
|
|
|
$this->cache->moveFromCache($sourceCache, $source, $target); |
|
|
|
|
if (!$this->storage->instanceOfStorage(ObjectStoreStorage::class)) { |
|
|
|
|
$operation($sourceCache, $sourceInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$sourceExtension = pathinfo($source, PATHINFO_EXTENSION); |
|
|
|
|
|