|
|
|
|
@ -33,10 +33,15 @@ use Icewind\Streams\CallbackWrapper;
|
|
|
|
|
use Icewind\Streams\CountWrapper;
|
|
|
|
|
use Icewind\Streams\IteratorDirectory;
|
|
|
|
|
use OC\Files\Cache\CacheEntry;
|
|
|
|
|
use OC\Files\Storage\PolyFill\CopyDirectory;
|
|
|
|
|
use OCP\Files\Cache\ICacheEntry;
|
|
|
|
|
use OCP\Files\FileInfo;
|
|
|
|
|
use OCP\Files\NotFoundException;
|
|
|
|
|
use OCP\Files\ObjectStore\IObjectStore;
|
|
|
|
|
|
|
|
|
|
class ObjectStoreStorage extends \OC\Files\Storage\Common {
|
|
|
|
|
use CopyDirectory;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var \OCP\Files\ObjectStore\IObjectStore $objectStore
|
|
|
|
|
*/
|
|
|
|
|
@ -319,7 +324,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// no break
|
|
|
|
|
// no break
|
|
|
|
|
case 'w':
|
|
|
|
|
case 'wb':
|
|
|
|
|
case 'w+':
|
|
|
|
|
@ -474,7 +479,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
|
|
|
|
|
if ($size === null) {
|
|
|
|
|
$countStream = CountWrapper::wrap($stream, function ($writtenSize) use ($fileId, &$size) {
|
|
|
|
|
$this->getCache()->update($fileId, [
|
|
|
|
|
'size' => $writtenSize
|
|
|
|
|
'size' => $writtenSize,
|
|
|
|
|
]);
|
|
|
|
|
$size = $writtenSize;
|
|
|
|
|
});
|
|
|
|
|
@ -523,4 +528,59 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
|
|
|
|
|
public function getObjectStore(): IObjectStore {
|
|
|
|
|
return $this->objectStore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function copy($path1, $path2) {
|
|
|
|
|
$path1 = $this->normalizePath($path1);
|
|
|
|
|
$path2 = $this->normalizePath($path2);
|
|
|
|
|
|
|
|
|
|
$cache = $this->getCache();
|
|
|
|
|
$sourceEntry = $cache->get($path1);
|
|
|
|
|
if (!$sourceEntry) {
|
|
|
|
|
throw new NotFoundException('Source object not found');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->copyInner($sourceEntry, $path2);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function copyInner(ICacheEntry $sourceEntry, string $to) {
|
|
|
|
|
$cache = $this->getCache();
|
|
|
|
|
|
|
|
|
|
if ($sourceEntry->getMimeType() === FileInfo::MIMETYPE_FOLDER) {
|
|
|
|
|
if ($cache->inCache($to)) {
|
|
|
|
|
$cache->remove($to);
|
|
|
|
|
}
|
|
|
|
|
$this->mkdir($to);
|
|
|
|
|
|
|
|
|
|
foreach ($cache->getFolderContentsById($sourceEntry->getId()) as $child) {
|
|
|
|
|
$this->copyInner($child, $to . '/' . $child->getName());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->copyFile($sourceEntry, $to);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function copyFile(ICacheEntry $sourceEntry, string $to) {
|
|
|
|
|
$cache = $this->getCache();
|
|
|
|
|
|
|
|
|
|
$sourceUrn = $this->getURN($sourceEntry->getId());
|
|
|
|
|
|
|
|
|
|
$cache->copyFromCache($cache, $sourceEntry, $to);
|
|
|
|
|
$targetEntry = $cache->get($to);
|
|
|
|
|
|
|
|
|
|
if (!$targetEntry) {
|
|
|
|
|
throw new \Exception('Target not in cache after copy');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$targetUrn = $this->getURN($targetEntry->getId());
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$this->objectStore->copyObject($sourceUrn, $targetUrn);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$cache->remove($to);
|
|
|
|
|
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|