From c8e90ebda5645ba041c523071400f5fcd6a92250 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Mon, 31 May 2021 18:45:07 +0200 Subject: [PATCH] debug patch for checksum states Signed-off-by: Arthur Schiwon --- apps/dav/lib/Connector/Sabre/File.php | 33 ++++++++++++++++++++ apps/dav/lib/Connector/Sabre/FilesPlugin.php | 13 ++++++++ lib/private/Files/Cache/Cache.php | 21 +++++++++++++ 3 files changed, 67 insertions(+) diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 6a2bf6fe3a..1704c12901 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -64,6 +64,7 @@ use OCP\ILogger; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; use OCP\Share\IManager; +use Psr\Log\LoggerInterface; use Sabre\DAV\Exception; use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\Forbidden; @@ -342,13 +343,29 @@ class File extends Node implements IFile { $this->refreshInfo(); + /** @var LoggerInterface $logger */ + $logger = \OC::$server->get(LoggerInterface::class); if (isset($this->request->server['HTTP_OC_CHECKSUM'])) { $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']); + $logger->debug('Received checksum in header: "{checksum}", path {target}', [ + 'app' => 'debug_checksum', + 'checksum' => $checksum, + 'target' => $this->path, + ]); $this->fileView->putFileInfo($this->path, ['checksum' => $checksum]); $this->refreshInfo(); } elseif ($this->getChecksum() !== null && $this->getChecksum() !== '') { + $logger->debug('No checksum received in header, resetting existing value, path {target}', [ + 'app' => 'debug_checksum', + 'target' => $this->path, + ]); $this->fileView->putFileInfo($this->path, ['checksum' => '']); $this->refreshInfo(); + } else { + $logger->debug('No checksum received in header, none was set either. path {target}', [ + 'app' => 'debug_checksum', + 'target' => $this->path, + ]); } } catch (StorageNotAvailableException $e) { throw new ServiceUnavailable("Failed to check file size: " . $e->getMessage(), 0, $e); @@ -606,11 +623,27 @@ class File extends Node implements IFile { // FIXME: should call refreshInfo but can't because $this->path is not the of the final file $info = $this->fileView->getFileInfo($targetPath); + /** @var LoggerInterface $logger */ + $logger = \OC::$server->get(LoggerInterface::class); if (isset($this->request->server['HTTP_OC_CHECKSUM'])) { $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']); + $logger->debug('(Chunk) Received checksum in header: "{checksum}", path {target}', [ + 'app' => 'debug_checksum', + 'checksum' => $checksum, + 'target' => $targetPath, + ]); $this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]); } elseif ($info->getChecksum() !== null && $info->getChecksum() !== '') { + $logger->debug('(Chunk) No checksum received in header, resetting existing value, path {target}', [ + 'app' => 'debug_checksum', + 'target' => $targetPath, + ]); $this->fileView->putFileInfo($this->path, ['checksum' => '']); + } else { + $logger->debug('(Chunk) No checksum received in header, none was set either. path {target}', [ + 'app' => 'debug_checksum', + 'target' => $targetPath, + ]); } $this->fileView->unlockFile($targetPath, ILockingProvider::LOCK_SHARED); diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index c831ab86dc..f58ba92856 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -41,6 +41,7 @@ use OCP\Files\StorageNotAvailableException; use OCP\IConfig; use OCP\IPreview; use OCP\IRequest; +use Psr\Log\LoggerInterface; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\NotFound; use Sabre\DAV\IFile; @@ -277,8 +278,20 @@ class FilesPlugin extends ServerPlugin { if ($node instanceof \OCA\DAV\Connector\Sabre\File) { //Add OC-Checksum header $checksum = $node->getChecksum(); + /** @var LoggerInterface $logger */ + $logger = \OC::$server->get(LoggerInterface::class); if ($checksum !== null && $checksum !== '') { + $logger->debug('Sending checksum response: "{checksum}" for path {path}', [ + 'app' => 'debug_checksum', + 'checksum' => $checksum, + 'path' => $node->getPath(), + ]); $response->addHeader('OC-Checksum', $checksum); + } else { + $logger->debug('Sending no checksum header, as no value is set for path {path}', [ + 'app' => 'debug_checksum', + 'path' => $node->getPath(), + ]); } } } diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index be2862cc0f..26b767ca5d 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -50,6 +50,7 @@ use OCP\Files\IMimeTypeLoader; use OCP\Files\Search\ISearchQuery; use OCP\Files\Storage\IStorage; use OCP\IDBConnection; +use Psr\Log\LoggerInterface; /** * Metadata cache for a storage @@ -286,6 +287,16 @@ class Cache implements ICache { [$values, $extensionValues] = $this->normalizeData($data); $values['storage'] = $this->getNumericStorageId(); + if (isset($values['checksum'])) { + /** @var LoggerInterface $logger */ + $logger = \OC::$server->get(LoggerInterface::class); + $logger->debug('Inserting checksum to: "{checksum}" for path {path}', [ + 'app' => 'debug_checksum', + 'checksum' => $values['checksum'], + 'path' => $values['path'], + ]); + } + try { $builder = $this->connection->getQueryBuilder(); $builder->insert('filecache'); @@ -347,6 +358,16 @@ class Cache implements ICache { [$values, $extensionValues] = $this->normalizeData($data); + if (isset($values['checksum'])) { + /** @var LoggerInterface $logger */ + $logger = \OC::$server->get(LoggerInterface::class); + $logger->debug('Updating stored checksum to: "{checksum}" for path {file}', [ + 'app' => 'debug_checksum', + 'checksum' => $values['checksum'], + 'file' => $values['path'] ?? $this->getPathById($id), + ]); + } + if (count($values)) { $query = $this->getQueryBuilder();