|
41 | 41 | use Sabre\DAV\Exception\BadRequest; |
42 | 42 | use Sabre\DAV\Exception\Forbidden; |
43 | 43 | use Sabre\DAV\Exception\NotFound; |
44 | | -use Sabre\DAV\Exception\NotImplemented; |
45 | 44 | use Sabre\DAV\Exception\ServiceUnavailable; |
46 | 45 | use Sabre\DAV\IFile; |
47 | 46 |
|
@@ -118,16 +117,6 @@ public function put($data) { |
118 | 117 | // verify path of the target |
119 | 118 | $this->verifyPath(); |
120 | 119 |
|
121 | | - // chunked handling |
122 | | - $chunkedHeader = $this->request->getHeader('oc-chunked'); |
123 | | - if ($chunkedHeader) { |
124 | | - try { |
125 | | - return $this->createFileChunked($data); |
126 | | - } catch (\Exception $e) { |
127 | | - $this->convertToSabreException($e); |
128 | | - } |
129 | | - } |
130 | | - |
131 | 120 | /** @var Storage $partStorage */ |
132 | 121 | [$partStorage] = $this->fileView->resolvePath($this->path); |
133 | 122 | $needsPartFile = $partStorage->needsPartFile() && (strlen($this->path) > 1); |
@@ -555,135 +544,6 @@ public function getDirectDownload() { |
555 | 544 | return $storage->getDirectDownload($internalPath); |
556 | 545 | } |
557 | 546 |
|
558 | | - /** |
559 | | - * @param resource $data |
560 | | - * @return null|string |
561 | | - * @throws Exception |
562 | | - * @throws BadRequest |
563 | | - * @throws NotImplemented |
564 | | - * @throws ServiceUnavailable |
565 | | - */ |
566 | | - private function createFileChunked($data) { |
567 | | - [$path, $name] = \Sabre\Uri\split($this->path); |
568 | | - |
569 | | - $info = \OC_FileChunking::decodeName($name); |
570 | | - if (empty($info)) { |
571 | | - throw new NotImplemented($this->l10n->t('Invalid chunk name')); |
572 | | - } |
573 | | - |
574 | | - $chunk_handler = new \OC_FileChunking($info); |
575 | | - $bytesWritten = $chunk_handler->store($info['index'], $data); |
576 | | - |
577 | | - //detect aborted upload |
578 | | - if ($this->request->getMethod() === 'PUT') { |
579 | | - $lengthHeader = $this->request->getHeader('content-length'); |
580 | | - if ($lengthHeader) { |
581 | | - $expected = (int)$lengthHeader; |
582 | | - if ($bytesWritten !== $expected) { |
583 | | - $chunk_handler->remove($info['index']); |
584 | | - throw new BadRequest( |
585 | | - $this->l10n->t( |
586 | | - 'Expected filesize of %1$s but read (from Nextcloud client) and wrote (to Nextcloud storage) %2$s. Could either be a network problem on the sending side or a problem writing to the storage on the server side.', |
587 | | - [ |
588 | | - $this->l10n->n('%n byte', '%n bytes', $expected), |
589 | | - $this->l10n->n('%n byte', '%n bytes', $bytesWritten), |
590 | | - ], |
591 | | - ) |
592 | | - ); |
593 | | - } |
594 | | - } |
595 | | - } |
596 | | - |
597 | | - if ($chunk_handler->isComplete()) { |
598 | | - /** @var Storage $storage */ |
599 | | - [$storage,] = $this->fileView->resolvePath($path); |
600 | | - $needsPartFile = $storage->needsPartFile(); |
601 | | - $partFile = null; |
602 | | - |
603 | | - $targetPath = $path . '/' . $info['name']; |
604 | | - /** @var \OC\Files\Storage\Storage $targetStorage */ |
605 | | - [$targetStorage, $targetInternalPath] = $this->fileView->resolvePath($targetPath); |
606 | | - |
607 | | - $exists = $this->fileView->file_exists($targetPath); |
608 | | - |
609 | | - try { |
610 | | - $this->fileView->lockFile($targetPath, ILockingProvider::LOCK_SHARED); |
611 | | - |
612 | | - $this->emitPreHooks($exists, $targetPath); |
613 | | - $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_EXCLUSIVE); |
614 | | - /** @var \OC\Files\Storage\Storage $targetStorage */ |
615 | | - [$targetStorage, $targetInternalPath] = $this->fileView->resolvePath($targetPath); |
616 | | - |
617 | | - if ($needsPartFile) { |
618 | | - // we first assembly the target file as a part file |
619 | | - $partFile = $this->getPartFileBasePath($path . '/' . $info['name']) . '.ocTransferId' . $info['transferid'] . '.part'; |
620 | | - /** @var \OC\Files\Storage\Storage $targetStorage */ |
621 | | - [$partStorage, $partInternalPath] = $this->fileView->resolvePath($partFile); |
622 | | - |
623 | | - |
624 | | - $chunk_handler->file_assemble($partStorage, $partInternalPath); |
625 | | - |
626 | | - // here is the final atomic rename |
627 | | - $renameOkay = $targetStorage->moveFromStorage($partStorage, $partInternalPath, $targetInternalPath); |
628 | | - $fileExists = $targetStorage->file_exists($targetInternalPath); |
629 | | - if ($renameOkay === false || $fileExists === false) { |
630 | | - \OC::$server->get(LoggerInterface::class)->error('\OC\Files\Filesystem::rename() failed', ['app' => 'webdav']); |
631 | | - // only delete if an error occurred and the target file was already created |
632 | | - if ($fileExists) { |
633 | | - // set to null to avoid double-deletion when handling exception |
634 | | - // stray part file |
635 | | - $partFile = null; |
636 | | - $targetStorage->unlink($targetInternalPath); |
637 | | - } |
638 | | - $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); |
639 | | - throw new Exception($this->l10n->t('Could not rename part file assembled from chunks')); |
640 | | - } |
641 | | - } else { |
642 | | - // assemble directly into the final file |
643 | | - $chunk_handler->file_assemble($targetStorage, $targetInternalPath); |
644 | | - } |
645 | | - |
646 | | - // allow sync clients to send the mtime along in a header |
647 | | - $mtimeHeader = $this->request->getHeader('x-oc-mtime'); |
648 | | - if ($mtimeHeader !== '') { |
649 | | - $mtime = $this->sanitizeMtime($mtimeHeader); |
650 | | - if ($targetStorage->touch($targetInternalPath, $mtime)) { |
651 | | - $this->header('X-OC-MTime: accepted'); |
652 | | - } |
653 | | - } |
654 | | - |
655 | | - // since we skipped the view we need to scan and emit the hooks ourselves |
656 | | - $targetStorage->getUpdater()->update($targetInternalPath); |
657 | | - |
658 | | - $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); |
659 | | - |
660 | | - $this->emitPostHooks($exists, $targetPath); |
661 | | - |
662 | | - // FIXME: should call refreshInfo but can't because $this->path is not the of the final file |
663 | | - $info = $this->fileView->getFileInfo($targetPath); |
664 | | - |
665 | | - $checksumHeader = $this->request->getHeader('oc-checksum'); |
666 | | - if ($checksumHeader) { |
667 | | - $checksum = trim($checksumHeader); |
668 | | - $this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]); |
669 | | - } elseif ($info->getChecksum() !== null && $info->getChecksum() !== '') { |
670 | | - $this->fileView->putFileInfo($this->path, ['checksum' => '']); |
671 | | - } |
672 | | - |
673 | | - $this->fileView->unlockFile($targetPath, ILockingProvider::LOCK_SHARED); |
674 | | - |
675 | | - return $info->getEtag(); |
676 | | - } catch (\Exception $e) { |
677 | | - if ($partFile !== null) { |
678 | | - $targetStorage->unlink($targetInternalPath); |
679 | | - } |
680 | | - $this->convertToSabreException($e); |
681 | | - } |
682 | | - } |
683 | | - |
684 | | - return null; |
685 | | - } |
686 | | - |
687 | 547 | /** |
688 | 548 | * Convert the given exception to a SabreException instance |
689 | 549 | * |
|
0 commit comments