Code Duplication    Length = 40-40 lines in 2 locations

apps/files_encryption/lib/util.php 2 locations

@@ 603-642 (lines=40) @@
600
	 * @param array $filelist list of encrypted files, relative to data/user/files
601
	 * @return boolean
602
	 */
603
	private function encryptVersions($filelist) {
604
605
		$successful = true;
606
607
		if (\OCP\App::isEnabled('files_versions')) {
608
609
			foreach ($filelist as $filename) {
610
611
				$versions = \OCA\Files_Versions\Storage::getVersions($this->userId, $filename);
612
				foreach ($versions as $version) {
613
614
					$path = '/' . $this->userId . '/files_versions/' . $version['path'] . '.v' . $version['version'];
615
616
					$encHandle = fopen('crypt://' . $path . '.part', 'wb');
617
618
					if ($encHandle === false) {
619
						\OCP\Util::writeLog('Encryption library', 'couldn\'t open "' . $path . '", decryption failed!', \OCP\Util::FATAL);
620
						$successful = false;
621
						continue;
622
					}
623
624
					$plainHandle = $this->view->fopen($path, 'rb');
625
					if ($plainHandle === false) {
626
						\OCP\Util::writeLog('Encryption library', 'couldn\'t open "' . $path . '.part", decryption failed!', \OCP\Util::FATAL);
627
						$successful = false;
628
						continue;
629
					}
630
631
					stream_copy_to_stream($plainHandle, $encHandle);
632
633
					fclose($encHandle);
634
					fclose($plainHandle);
635
636
					$this->view->rename($path . '.part', $path);
637
				}
638
			}
639
		}
640
641
		return $successful;
642
	}
643
644
	/**
645
	 * decrypt versions from given file
@@ 649-688 (lines=40) @@
646
	 * @param string $filelist list of decrypted files, relative to data/user/files
647
	 * @return boolean
648
	 */
649
	private function decryptVersions($filelist) {
650
651
		$successful = true;
652
653
		if (\OCP\App::isEnabled('files_versions')) {
654
655
			foreach ($filelist as $filename) {
656
657
				$versions = \OCA\Files_Versions\Storage::getVersions($this->userId, $filename);
658
				foreach ($versions as $version) {
659
660
					$path = '/' . $this->userId . '/files_versions/' . $version['path'] . '.v' . $version['version'];
661
662
					$encHandle = fopen('crypt://' . $path, 'rb');
663
664
					if ($encHandle === false) {
665
						\OCP\Util::writeLog('Encryption library', 'couldn\'t open "' . $path . '", decryption failed!', \OCP\Util::FATAL);
666
						$successful = false;
667
						continue;
668
					}
669
670
					$plainHandle = $this->view->fopen($path . '.part', 'wb');
671
					if ($plainHandle === false) {
672
						\OCP\Util::writeLog('Encryption library', 'couldn\'t open "' . $path . '.part", decryption failed!', \OCP\Util::FATAL);
673
						$successful = false;
674
						continue;
675
					}
676
677
					stream_copy_to_stream($encHandle, $plainHandle);
678
679
					fclose($encHandle);
680
					fclose($plainHandle);
681
682
					$this->view->rename($path . '.part', $path);
683
				}
684
			}
685
		}
686
687
		return $successful;
688
	}
689
690
	/**
691
	 * Decrypt all files