diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 75cc5779100a..b6f0d1d32215 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -256,18 +256,6 @@ public function put($data) { } $this->refreshInfo(); - - $meta = $partStorage->getMetaData($internalPartPath); - - if (isset($meta['checksum'])) { - $this->fileView->putFileInfo( - $this->path, - ['checksum' => $meta['checksum']] - ); - } - - $this->refreshInfo(); - } catch (StorageNotAvailableException $e) { throw new ServiceUnavailable("Failed to check file size: " . $e->getMessage()); } diff --git a/lib/private/Files/Stream/Checksum.php b/lib/private/Files/Stream/Checksum.php index 43bc454a7d2c..9be7e8eb3b2a 100644 --- a/lib/private/Files/Stream/Checksum.php +++ b/lib/private/Files/Stream/Checksum.php @@ -133,11 +133,47 @@ private function updateHashingContexts($data) { } /** + * Remove .part extension from a file path + * @param string $path Path that may identify a .part file + * @return string File path without .part extension + */ + private function stripPartialFileExtension($path) { + $extension = pathinfo($path, PATHINFO_EXTENSION); + + if ( $extension === 'part') { + + $newLength = strlen($path) - 5; // 5 = strlen(".part") + $fPath = substr($path, 0, $newLength); + + // if path also contains a transaction id, we remove it too + $extension = pathinfo($fPath, PATHINFO_EXTENSION); + if(substr($extension, 0, 12) === 'ocTransferId') { // 12 = strlen("ocTransferId") + $newLength = strlen($fPath) - strlen($extension) -1; + $fPath = substr($fPath, 0, $newLength); + } + return $fPath; + + } else { + return $path; + } + } + + /** + * Make checksums available for part files and the original file for which part file has been created * @return bool */ public function stream_close() { $currentPath = $this->getPathFromStreamContext(); - self::$checksums[$currentPath] = $this->finalizeHashingContexts(); + $checksum = $this->finalizeHashingContexts(); + self::$checksums[$currentPath] = $checksum; + + // If current path belongs to part file, save checksum for original file + // As a result, call to getChecksums for original file (of this part file) will + // fetch checksum from cache + $originalFilePath = $this->stripPartialFileExtension($currentPath); + if ($originalFilePath !== $currentPath){ + self::$checksums[$originalFilePath] = $checksum; + } return parent::stream_close(); }