summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2021-03-08 18:49:08 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2021-03-16 16:18:06 +0000
commit603ec9be0c32279ee7f82de96362cda9e378c32d (patch)
tree7d57d49b2bad6f8a16cb4a2ab5c7b36cee60b83e /lib/private
parentf9c9e27e46303c85c2d55fa7d1da09329e819555 (diff)
downloadnextcloud-server-603ec9be0c32279ee7f82de96362cda9e378c32d.tar.gz
nextcloud-server-603ec9be0c32279ee7f82de96362cda9e378c32d.zip
add ICopyFromCache trait to expose existing implementation
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Files/Cache/Cache.php42
-rw-r--r--lib/private/Files/Cache/MoveFromCacheTrait.php36
2 files changed, 43 insertions, 35 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index de807421d26..b7f39df25f7 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -598,7 +598,7 @@ class Cache implements ICache {
/**
* Move a file or folder in the cache
*
- * @param \OCP\Files\Cache\ICache $sourceCache
+ * @param ICache $sourceCache
* @param string $sourcePath
* @param string $targetPath
* @throws \OC\DatabaseException
@@ -992,4 +992,44 @@ class Cache implements ICache {
public function normalize($path) {
return trim(\OC_Util::normalizeUnicode($path), '/');
}
+
+ /**
+ * Copy a file or folder in the cache
+ *
+ * @param ICache $sourceCache
+ * @param ICacheEntry $sourceEntry
+ * @param string $targetPath
+ * @return int fileid of copied entry
+ */
+ public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int {
+ $data = $this->cacheEntryToArray($sourceEntry);
+ $fileId = $this->put($targetPath, $data);
+ if ($fileId <= 0) {
+ throw new \RuntimeException("Failed to copy to " . $targetPath . " from cache with source data " . json_encode($data) . " ");
+ }
+ if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
+ $folderContent = $sourceCache->getFolderContentsById($sourceEntry->getId());
+ foreach ($folderContent as $subEntry) {
+ $subTargetPath = $targetPath . '/' . $subEntry->getName();
+ $this->copyFromCache($sourceCache, $subEntry, $subTargetPath);
+ }
+ }
+ return $fileId;
+ }
+
+ private function cacheEntryToArray(ICacheEntry $entry): array {
+ return [
+ 'size' => $entry->getSize(),
+ 'mtime' => $entry->getMTime(),
+ 'storage_mtime' => $entry->getStorageMTime(),
+ 'mimetype' => $entry->getMimeType(),
+ 'mimepart' => $entry->getMimePart(),
+ 'etag' => $entry->getEtag(),
+ 'permissions' => $entry->getPermissions(),
+ 'encrypted' => $entry->isEncrypted(),
+ 'creation_time' => $entry->getCreationTime(),
+ 'upload_time' => $entry->getUploadTime(),
+ 'metadata_etag' => $entry->getMetadataEtag(),
+ ];
+ }
}
diff --git a/lib/private/Files/Cache/MoveFromCacheTrait.php b/lib/private/Files/Cache/MoveFromCacheTrait.php
index 0f42b00df1c..2f5bbfb7eea 100644
--- a/lib/private/Files/Cache/MoveFromCacheTrait.php
+++ b/lib/private/Files/Cache/MoveFromCacheTrait.php
@@ -41,6 +41,8 @@ trait MoveFromCacheTrait {
*/
abstract public function put($file, array $data);
+ abstract public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int;
+
/**
* Move a file or folder in the cache
*
@@ -55,38 +57,4 @@ trait MoveFromCacheTrait {
$sourceCache->remove($sourcePath);
}
-
- /**
- * Copy a file or folder in the cache
- *
- * @param \OCP\Files\Cache\ICache $sourceCache
- * @param ICacheEntry $sourceEntry
- * @param string $targetPath
- */
- public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, $targetPath) {
- $this->put($targetPath, $this->cacheEntryToArray($sourceEntry));
- if ($sourceEntry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
- $folderContent = $sourceCache->getFolderContentsById($sourceEntry->getId());
- foreach ($folderContent as $subEntry) {
- $subTargetPath = $targetPath . '/' . $subEntry->getName();
- $this->copyFromCache($sourceCache, $subEntry, $subTargetPath);
- }
- }
- }
-
- private function cacheEntryToArray(ICacheEntry $entry) {
- return [
- 'size' => $entry->getSize(),
- 'mtime' => $entry->getMTime(),
- 'storage_mtime' => $entry->getStorageMTime(),
- 'mimetype' => $entry->getMimeType(),
- 'mimepart' => $entry->getMimePart(),
- 'etag' => $entry->getEtag(),
- 'permissions' => $entry->getPermissions(),
- 'encrypted' => $entry->isEncrypted(),
- 'creation_time' => $entry->getCreationTime(),
- 'upload_time' => $entry->getUploadTime(),
- 'metadata_etag' => $entry->getMetadataEtag(),
- ];
- }
}