debug patch for checksum states

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2021-05-31 18:45:07 +02:00
parent 7f5e9ff7fc
commit c8e90ebda5
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
3 changed files with 67 additions and 0 deletions

View File

@ -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);

View File

@ -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(),
]);
}
}
}

View File

@ -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();