From 3e88a5067f3ef6fd81068f85a00ee2a49a8f9b79 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sun, 28 Feb 2016 19:41:46 +0100 Subject: Remove checksum on upload of non checksumed file When we overwrite a checksumed file with a file without a checksum we should remove the checksum from the server. This is done by setting the column to empty. --- apps/dav/lib/connector/sabre/file.php | 2 ++ apps/dav/lib/connector/sabre/filesplugin.php | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'apps/dav/lib') diff --git a/apps/dav/lib/connector/sabre/file.php b/apps/dav/lib/connector/sabre/file.php index 38a1ee5f4e2..b7e2108db3b 100644 --- a/apps/dav/lib/connector/sabre/file.php +++ b/apps/dav/lib/connector/sabre/file.php @@ -218,6 +218,8 @@ class File extends Node implements IFile { if (isset($request->server['HTTP_OC_CHECKSUM'])) { $checksum = trim($request->server['HTTP_OC_CHECKSUM']); $this->fileView->putFileInfo($this->path, ['checksum' => $checksum]); + } else if ($this->getChecksum() !== NULL && $this->getChecksum() !== '') { + $this->fileView->putFileInfo($this->path, ['checksum' => '']); } $this->refreshInfo(); diff --git a/apps/dav/lib/connector/sabre/filesplugin.php b/apps/dav/lib/connector/sabre/filesplugin.php index eb9116d219b..4b05922adfd 100644 --- a/apps/dav/lib/connector/sabre/filesplugin.php +++ b/apps/dav/lib/connector/sabre/filesplugin.php @@ -27,6 +27,7 @@ namespace OCA\DAV\Connector\Sabre; +use Sabre\DAV\Exception\NotFound; use Sabre\DAV\IFile; use \Sabre\DAV\PropFind; use \Sabre\DAV\PropPatch; @@ -197,7 +198,7 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin { //Add OC-Checksum header /** @var $node File */ $checksum = $node->getChecksum(); - if ($checksum !== null) { + if ($checksum !== null && $checksum !== '') { $response->addHeader('OC-Checksum', $checksum); } } @@ -252,6 +253,10 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin { $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { $checksum = $node->getChecksum(); + if ($checksum === NULL || $checksum === '') { + return null; + } + return new ChecksumList($checksum); }); -- cgit v1.2.3 From ec140fa2ec2aaf489bae728971ec18e58719a38a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sun, 28 Feb 2016 20:21:43 +0100 Subject: Checksums on chunked files We should also store checksums on chunked files. We do not checksum individual chunks but only the final file. --- apps/dav/lib/connector/sabre/file.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'apps/dav/lib') diff --git a/apps/dav/lib/connector/sabre/file.php b/apps/dav/lib/connector/sabre/file.php index b7e2108db3b..b71c4ccc621 100644 --- a/apps/dav/lib/connector/sabre/file.php +++ b/apps/dav/lib/connector/sabre/file.php @@ -457,6 +457,14 @@ class File extends Node implements IFile { $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); + if (isset($request->server['HTTP_OC_CHECKSUM'])) { + $checksum = trim($request->server['HTTP_OC_CHECKSUM']); + $this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]); + } else if ($this->getChecksum() !== NULL && $this->getChecksum() !== '') { + $this->fileView->putFileInfo($this->path, ['checksum' => '']); + } + $this->refreshInfo(); + $this->emitPostHooks($exists, $targetPath); $info = $this->fileView->getFileInfo($targetPath); -- cgit v1.2.3 From ac392457f24aed34dc2c5635d9ffd64ec256b061 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 29 Feb 2016 10:29:48 +0100 Subject: Fix unit tests --- apps/dav/lib/connector/sabre/file.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'apps/dav/lib') diff --git a/apps/dav/lib/connector/sabre/file.php b/apps/dav/lib/connector/sabre/file.php index b71c4ccc621..0bf7d9cf2bc 100644 --- a/apps/dav/lib/connector/sabre/file.php +++ b/apps/dav/lib/connector/sabre/file.php @@ -215,6 +215,8 @@ class File extends Node implements IFile { } } + $this->refreshInfo(); + if (isset($request->server['HTTP_OC_CHECKSUM'])) { $checksum = trim($request->server['HTTP_OC_CHECKSUM']); $this->fileView->putFileInfo($this->path, ['checksum' => $checksum]); @@ -457,17 +459,17 @@ class File extends Node implements IFile { $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); + $this->emitPostHooks($exists, $targetPath); + + $info = $this->fileView->getFileInfo($targetPath); + if (isset($request->server['HTTP_OC_CHECKSUM'])) { $checksum = trim($request->server['HTTP_OC_CHECKSUM']); $this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]); - } else if ($this->getChecksum() !== NULL && $this->getChecksum() !== '') { + } else if ($info->getChecksum() !== NULL && $info->getChecksum() !== '') { $this->fileView->putFileInfo($this->path, ['checksum' => '']); } - $this->refreshInfo(); - - $this->emitPostHooks($exists, $targetPath); - $info = $this->fileView->getFileInfo($targetPath); $this->fileView->unlockFile($targetPath, ILockingProvider::LOCK_SHARED); -- cgit v1.2.3 From 57babe032b1c3abcf4e4208bb19488151a934470 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 1 Mar 2016 11:24:10 +0100 Subject: Save some calls to refreshInfo during upload --- apps/dav/lib/connector/sabre/file.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'apps/dav/lib') diff --git a/apps/dav/lib/connector/sabre/file.php b/apps/dav/lib/connector/sabre/file.php index 0bf7d9cf2bc..9c8344bc5db 100644 --- a/apps/dav/lib/connector/sabre/file.php +++ b/apps/dav/lib/connector/sabre/file.php @@ -220,10 +220,11 @@ class File extends Node implements IFile { if (isset($request->server['HTTP_OC_CHECKSUM'])) { $checksum = trim($request->server['HTTP_OC_CHECKSUM']); $this->fileView->putFileInfo($this->path, ['checksum' => $checksum]); - } else if ($this->getChecksum() !== NULL && $this->getChecksum() !== '') { + $this->refreshInfo(); + } else if ($this->getChecksum() !== null && $this->getChecksum() !== '') { $this->fileView->putFileInfo($this->path, ['checksum' => '']); + $this->refreshInfo(); } - $this->refreshInfo(); } catch (StorageNotAvailableException $e) { throw new ServiceUnavailable("Failed to check file size: " . $e->getMessage()); @@ -461,16 +462,16 @@ class File extends Node implements IFile { $this->emitPostHooks($exists, $targetPath); + // FIXME: should call refreshInfo but can't because $this->path is not the of the final file $info = $this->fileView->getFileInfo($targetPath); if (isset($request->server['HTTP_OC_CHECKSUM'])) { $checksum = trim($request->server['HTTP_OC_CHECKSUM']); $this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]); - } else if ($info->getChecksum() !== NULL && $info->getChecksum() !== '') { + } else if ($info->getChecksum() !== null && $info->getChecksum() !== '') { $this->fileView->putFileInfo($this->path, ['checksum' => '']); } - $this->fileView->unlockFile($targetPath, ILockingProvider::LOCK_SHARED); return $info->getEtag(); -- cgit v1.2.3