Completed
Pull Request — master (#9018)
by Björn
17:11
created
lib/private/Files/Storage/Wrapper/Encryption.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
 		// check if the file is stored in the array cache, this means that we
369 369
 		// copy a file over to the versions folder, in this case we don't want to
370 370
 		// decrypt it
371
-		if ($this->arrayCache->hasKey('encryption_copy_version_' . $path)) {
372
-			$this->arrayCache->remove('encryption_copy_version_' . $path);
371
+		if ($this->arrayCache->hasKey('encryption_copy_version_'.$path)) {
372
+			$this->arrayCache->remove('encryption_copy_version_'.$path);
373 373
 			return $this->storage->fopen($path, $mode);
374 374
 		}
375 375
 
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 				}
441 441
 			} catch (ModuleDoesNotExistsException $e) {
442 442
 				$this->logger->logException($e, [
443
-					'message' => 'Encryption module "' . $encryptionModuleId . '" not found, file will be stored unencrypted',
443
+					'message' => 'Encryption module "'.$encryptionModuleId.'" not found, file will be stored unencrypted',
444 444
 					'level' => \OCP\Util::WARN,
445 445
 					'app' => 'core',
446 446
 				]);
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 				try {
496 496
 					$result = $this->fixUnencryptedSize($path, $size, $unencryptedSize);
497 497
 				} catch (\Exception $e) {
498
-					$this->logger->error('Couldn\'t re-calculate unencrypted size for '. $path);
498
+					$this->logger->error('Couldn\'t re-calculate unencrypted size for '.$path);
499 499
 					$this->logger->logException($e);
500 500
 				}
501 501
 				unset($this->fixUnencryptedSizeOf[$this->getFullPath($path)]);
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
 
525 525
 		// if we couldn't open the file we return the old unencrypted size
526 526
 		if (!is_resource($stream)) {
527
-			$this->logger->error('Could not open ' . $path . '. Recalculation of unencrypted size aborted.');
527
+			$this->logger->error('Could not open '.$path.'. Recalculation of unencrypted size aborted.');
528 528
 			return $unencryptedSize;
529 529
 		}
530 530
 
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 		// next highest is end of chunks, one subtracted is last one
550 550
 		// we have to read the last chunk, we can't just calculate it (because of padding etc)
551 551
 
552
-		$lastChunkNr = ceil($size/ $blockSize)-1;
552
+		$lastChunkNr = ceil($size / $blockSize) - 1;
553 553
 		// calculate last chunk position
554 554
 		$lastChunkPos = ($lastChunkNr * $blockSize);
555 555
 		// try to fseek to the last chunk, if it fails we have to read the whole file
@@ -557,16 +557,16 @@  discard block
 block discarded – undo
557 557
 			$newUnencryptedSize += $lastChunkNr * $unencryptedBlockSize;
558 558
 		}
559 559
 
560
-		$lastChunkContentEncrypted='';
560
+		$lastChunkContentEncrypted = '';
561 561
 		$count = $blockSize;
562 562
 
563 563
 		while ($count > 0) {
564
-			$data=fread($stream, $blockSize);
565
-			$count=strlen($data);
564
+			$data = fread($stream, $blockSize);
565
+			$count = strlen($data);
566 566
 			$lastChunkContentEncrypted .= $data;
567
-			if(strlen($lastChunkContentEncrypted) > $blockSize) {
567
+			if (strlen($lastChunkContentEncrypted) > $blockSize) {
568 568
 				$newUnencryptedSize += $unencryptedBlockSize;
569
-				$lastChunkContentEncrypted=substr($lastChunkContentEncrypted, $blockSize);
569
+				$lastChunkContentEncrypted = substr($lastChunkContentEncrypted, $blockSize);
570 570
 			}
571 571
 		}
572 572
 
@@ -574,8 +574,8 @@  discard block
 block discarded – undo
574 574
 
575 575
 		// we have to decrypt the last chunk to get it actual size
576 576
 		$encryptionModule->begin($this->getFullPath($path), $this->uid, 'r', $header, []);
577
-		$decryptedLastChunk = $encryptionModule->decrypt($lastChunkContentEncrypted, $lastChunkNr . 'end');
578
-		$decryptedLastChunk .= $encryptionModule->end($this->getFullPath($path), $lastChunkNr . 'end');
577
+		$decryptedLastChunk = $encryptionModule->decrypt($lastChunkContentEncrypted, $lastChunkNr.'end');
578
+		$decryptedLastChunk .= $encryptionModule->end($this->getFullPath($path), $lastChunkNr.'end');
579 579
 
580 580
 		// calc the real file size with the size of the last chunk
581 581
 		$newUnencryptedSize += strlen($decryptedLastChunk);
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
 		$cacheInformation = [
660 660
 			'encrypted' => $isEncrypted,
661 661
 		];
662
-		if($isEncrypted) {
662
+		if ($isEncrypted) {
663 663
 			$encryptedVersion = $sourceStorage->getCache()->get($sourceInternalPath)['encryptedVersion'];
664 664
 
665 665
 			// In case of a move operation from an unencrypted to an encrypted
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
 			// correct value would be "1". Thus we manually set the value to "1"
668 668
 			// for those cases.
669 669
 			// See also https://github.com/owncloud/core/issues/23078
670
-			if($encryptedVersion === 0 || !$keepEncryptionVersion) {
670
+			if ($encryptedVersion === 0 || !$keepEncryptionVersion) {
671 671
 				$encryptedVersion = 1;
672 672
 			}
673 673
 
@@ -703,9 +703,9 @@  discard block
 block discarded – undo
703 703
 			// remember that we try to create a version so that we can detect it during
704 704
 			// fopen($sourceInternalPath) and by-pass the encryption in order to
705 705
 			// create a 1:1 copy of the file
706
-			$this->arrayCache->set('encryption_copy_version_' . $sourceInternalPath, true);
706
+			$this->arrayCache->set('encryption_copy_version_'.$sourceInternalPath, true);
707 707
 			$result = $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
708
-			$this->arrayCache->remove('encryption_copy_version_' . $sourceInternalPath);
708
+			$this->arrayCache->remove('encryption_copy_version_'.$sourceInternalPath);
709 709
 			if ($result) {
710 710
 				$info = $this->getCache('', $sourceStorage)->get($sourceInternalPath);
711 711
 				// make sure that we update the unencrypted size for the version
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 		$mount = $this->mountManager->findByStorageId($sourceStorage->getId());
726 726
 		if (count($mount) === 1) {
727 727
 			$mountPoint = $mount[0]->getMountPoint();
728
-			$source = $mountPoint . '/' . $sourceInternalPath;
728
+			$source = $mountPoint.'/'.$sourceInternalPath;
729 729
 			$target = $this->getFullPath($targetInternalPath);
730 730
 			$this->copyKeys($source, $target);
731 731
 		} else {
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 			if (is_resource($dh)) {
739 739
 				while ($result and ($file = readdir($dh)) !== false) {
740 740
 					if (!Filesystem::isIgnoredDir($file)) {
741
-						$result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file, false, $isRename);
741
+						$result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath.'/'.$file, $targetInternalPath.'/'.$file, false, $isRename);
742 742
 					}
743 743
 				}
744 744
 			}
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 				fclose($target);
755 755
 				throw $e;
756 756
 			}
757
-			if($result) {
757
+			if ($result) {
758 758
 				if ($preserveMtime) {
759 759
 					$this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
760 760
 				}
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
 				$this->getCache()->remove($targetInternalPath);
767 767
 			}
768 768
 		}
769
-		return (bool)$result;
769
+		return (bool) $result;
770 770
 
771 771
 	}
772 772
 
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
 	 * @return string full path including mount point
838 838
 	 */
839 839
 	protected function getFullPath($path) {
840
-		return Filesystem::normalizePath($this->mountPoint . '/' . $path);
840
+		return Filesystem::normalizePath($this->mountPoint.'/'.$path);
841 841
 	}
842 842
 
843 843
 	/**
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 				$header = substr($header, 0, $endAt + strlen(Util::HEADER_END));
894 894
 
895 895
 				// +1 to not start with an ':' which would result in empty element at the beginning
896
-				$exploded = explode(':', substr($header, strlen(Util::HEADER_START)+1));
896
+				$exploded = explode(':', substr($header, strlen(Util::HEADER_START) + 1));
897 897
 
898 898
 				$element = array_shift($exploded);
899 899
 				while ($element !== Util::HEADER_END) {
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
 			try {
957 957
 				$encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId);
958 958
 			} catch (ModuleDoesNotExistsException $e) {
959
-				$this->logger->critical('Encryption module defined in "' . $path . '" not loaded!');
959
+				$this->logger->critical('Encryption module defined in "'.$path.'" not loaded!');
960 960
 				throw $e;
961 961
 			}
962 962
 		}
Please login to merge, or discard this patch.