Skip to content

Commit f0b242e

Browse files
committed
chore: remove chunking-v1
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 441dfd6 commit f0b242e

17 files changed

Lines changed: 5 additions & 939 deletions

File tree

apps/dav/lib/Connector/Sabre/Directory.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,8 @@ public function __construct(View $view, FileInfo $info, ?CachingTree $tree = nul
8686
*/
8787
public function createFile($name, $data = null) {
8888
try {
89-
// for chunked upload also updating a existing file is a "createFile"
90-
// because we create all the chunks before re-assemble them to the existing file.
91-
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
92-
// exit if we can't create a new file and we don't updatable existing file
93-
$chunkInfo = \OC_FileChunking::decodeName($name);
94-
if (!$this->fileView->isCreatable($this->path) &&
95-
!$this->fileView->isUpdatable($this->path . '/' . $chunkInfo['name'])
96-
) {
97-
throw new \Sabre\DAV\Exception\Forbidden();
98-
}
99-
} else {
100-
// For non-chunked upload it is enough to check if we can create a new file
101-
if (!$this->fileView->isCreatable($this->path)) {
102-
throw new \Sabre\DAV\Exception\Forbidden();
103-
}
89+
if (!$this->fileView->isCreatable($this->path)) {
90+
throw new \Sabre\DAV\Exception\Forbidden();
10491
}
10592

10693
$this->fileView->verifyPath($this->path, $name);

apps/dav/lib/Connector/Sabre/File.php

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
use Sabre\DAV\Exception\BadRequest;
4242
use Sabre\DAV\Exception\Forbidden;
4343
use Sabre\DAV\Exception\NotFound;
44-
use Sabre\DAV\Exception\NotImplemented;
4544
use Sabre\DAV\Exception\ServiceUnavailable;
4645
use Sabre\DAV\IFile;
4746

@@ -118,16 +117,6 @@ public function put($data) {
118117
// verify path of the target
119118
$this->verifyPath();
120119

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-
131120
/** @var Storage $partStorage */
132121
[$partStorage] = $this->fileView->resolvePath($this->path);
133122
$needsPartFile = $partStorage->needsPartFile() && (strlen($this->path) > 1);
@@ -555,135 +544,6 @@ public function getDirectDownload() {
555544
return $storage->getDirectDownload($internalPath);
556545
}
557546

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-
687547
/**
688548
* Convert the given exception to a SabreException instance
689549
*

apps/dav/lib/Connector/Sabre/FilesPlugin.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -642,15 +642,6 @@ private function getMetadataFileAccessRight(Node $node, string $userId): int {
642642
* @throws \Sabre\DAV\Exception\BadRequest
643643
*/
644644
public function sendFileIdHeader($filePath, ?\Sabre\DAV\INode $node = null) {
645-
// chunked upload handling
646-
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
647-
[$path, $name] = \Sabre\Uri\split($filePath);
648-
$info = \OC_FileChunking::decodeName($name);
649-
if (!empty($info)) {
650-
$filePath = $path . '/' . $info['name'];
651-
}
652-
}
653-
654645
// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
655646
if (!$this->server->tree->nodeExists($filePath)) {
656647
return;

apps/dav/lib/Connector/Sabre/LockPlugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function initialize(\Sabre\DAV\Server $server) {
4242
public function getLock(RequestInterface $request) {
4343
// we can't listen on 'beforeMethod:PUT' due to order of operations with setting up the tree
4444
// so instead we limit ourselves to the PUT method manually
45-
if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
45+
if ($request->getMethod() !== 'PUT') {
4646
return;
4747
}
4848
try {
@@ -65,7 +65,7 @@ public function releaseLock(RequestInterface $request) {
6565
if ($this->isLocked === false) {
6666
return;
6767
}
68-
if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
68+
if ($request->getMethod() !== 'PUT') {
6969
return;
7070
}
7171
try {

apps/dav/lib/Connector/Sabre/ObjectTree.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,35 +46,6 @@ public function init(\Sabre\DAV\INode $rootNode, \OC\Files\View $view, \OCP\File
4646
$this->mountManager = $mountManager;
4747
}
4848

49-
/**
50-
* If the given path is a chunked file name, converts it
51-
* to the real file name. Only applies if the OC-CHUNKED header
52-
* is present.
53-
*
54-
* @param string $path chunk file path to convert
55-
*
56-
* @return string path to real file
57-
*/
58-
private function resolveChunkFile($path) {
59-
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
60-
// resolve to real file name to find the proper node
61-
[$dir, $name] = \Sabre\Uri\split($path);
62-
if ($dir === '/' || $dir === '.') {
63-
$dir = '';
64-
}
65-
66-
$info = \OC_FileChunking::decodeName($name);
67-
// only replace path if it was really the chunked file
68-
if (isset($info['transferid'])) {
69-
// getNodePath is called for multiple nodes within a chunk
70-
// upload call
71-
$path = $dir . '/' . $info['name'];
72-
$path = ltrim($path, '/');
73-
}
74-
}
75-
return $path;
76-
}
77-
7849
/**
7950
* Returns the INode object for the requested path
8051
*
@@ -126,9 +97,6 @@ public function getNodeForPath($path) {
12697
$info = null;
12798
}
12899
} else {
129-
// resolve chunk file name to real name, if applicable
130-
$path = $this->resolveChunkFile($path);
131-
132100
// read from cache
133101
try {
134102
$info = $this->fileView->getFileInfo($path);

apps/dav/lib/Connector/Sabre/QuotaPlugin.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -187,38 +187,18 @@ public function checkQuota(string $path, $length = null) {
187187
}
188188
$req = $this->server->httpRequest;
189189

190-
// If LEGACY chunked upload
191-
if ($req->getHeader('OC-Chunked')) {
192-
$info = \OC_FileChunking::decodeName($newName);
193-
$chunkHandler = $this->getFileChunking($info);
194-
// subtract the already uploaded size to see whether
195-
// there is still enough space for the remaining chunks
196-
$length -= $chunkHandler->getCurrentSize();
197-
// use target file name for free space check in case of shared files
198-
$path = rtrim($parentPath, '/') . '/' . $info['name'];
199-
}
200-
201190
// Strip any duplicate slashes
202191
$path = str_replace('//', '/', $path);
203192

204193
$freeSpace = $this->getFreeSpace($path);
205194
if ($freeSpace >= 0 && $length > $freeSpace) {
206-
// If LEGACY chunked upload, clean up
207-
if (isset($chunkHandler)) {
208-
$chunkHandler->cleanup();
209-
}
210195
throw new InsufficientStorage("Insufficient space in $path, $length required, $freeSpace available");
211196
}
212197
}
213198

214199
return true;
215200
}
216201

217-
public function getFileChunking($info) {
218-
// FIXME: need a factory for better mocking support
219-
return new \OC_FileChunking($info);
220-
}
221-
222202
public function getLength() {
223203
$req = $this->server->httpRequest;
224204
$length = $req->getHeader('X-Expected-Entity-Length');

0 commit comments

Comments
 (0)