Browse Source

update 'encrypted'-flag in file cache according to the storage settings

remotes/origin/poc-doctrine-migrations
Bjoern Schiessle 11 years ago
committed by Joas Schilling
parent
commit
e4829a2358
  1. 5
      lib/private/files/storage/common.php
  2. 48
      lib/private/files/storage/wrapper/encryption.php

5
lib/private/files/storage/common.php

@ -545,6 +545,11 @@ abstract class Common implements Storage {
}
} else {
$source = $sourceStorage->fopen($sourceInternalPath, 'r');
// TODO: call fopen in a way that we execute again all storage wrappers
// to avoid that we bypass storage wrappers which perform important actions
// for this operation. Same is true for all other operations which
// are not the same as the original one.Once this is fixed we also
// need to adjust the encryption wrapper.
$target = $this->fopen($targetInternalPath, 'w');
list(, $result) = \OC_Helper::streamCopy($source, $target);
if ($result and $preserveMtime) {

48
lib/private/files/storage/wrapper/encryption.php

@ -373,8 +373,14 @@ class Encryption extends Wrapper {
* @param bool $preserveMtime
* @return bool
*/
public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
$result = $this->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, true);
public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = true) {
// TODO clean this up once the underlying moveFromStorage in OC\Files\Storage\Wrapper\Common is fixed:
// - call $this->storage->moveFromStorage() instead of $this->copyBetweenStorage
// - copy the file cache update from $this->copyBetweenStorage to this method
// - remove $this->copyBetweenStorage
$result = $this->copyBetweenStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, true);
if ($result) {
if ($sourceStorage->is_dir($sourceInternalPath)) {
$result &= $sourceStorage->rmdir($sourceInternalPath);
@ -394,6 +400,26 @@ class Encryption extends Wrapper {
* @return bool
*/
public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
// TODO clean this up once the underlying moveFromStorage in OC\Files\Storage\Wrapper\Common is fixed:
// - call $this->storage->moveFromStorage() instead of $this->copyBetweenStorage
// - copy the file cache update from $this->copyBetweenStorage to this method
// - remove $this->copyBetweenStorage
return $this->copyBetweenStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, false);
}
/**
* copy file between two storages
*
* @param \OCP\Files\Storage $sourceStorage
* @param $sourceInternalPath
* @param $targetInternalPath
* @param $preserveMtime
* @param $isRename
* @return bool
*/
private function copyBetweenStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename) {
if ($sourceStorage->is_dir($sourceInternalPath)) {
$dh = $sourceStorage->opendir($sourceInternalPath);
$result = $this->mkdir($targetInternalPath);
@ -408,13 +434,23 @@ class Encryption extends Wrapper {
$source = $sourceStorage->fopen($sourceInternalPath, 'r');
$target = $this->fopen($targetInternalPath, 'w');
list(, $result) = \OC_Helper::streamCopy($source, $target);
if ($result and $preserveMtime) {
$this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
}
fclose($source);
fclose($target);
if (!$result) {
if($result) {
if ($preserveMtime) {
$this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
}
$isEncrypted = $this->mount->getOption('encrypt', true) ? 1 : 0;
// in case of a rename we need to manipulate the source cache because
// this information will be kept for the new target
if ($isRename) {
$sourceStorage->getCache()->put($sourceInternalPath, ['encrypted' => $isEncrypted]);
} else {
$this->getCache()->put($targetInternalPath, ['encrypted' => $isEncrypted]);
}
} else {
// delete partially written target file
$this->unlink($targetInternalPath);
// delete cache entry that was created by fopen

Loading…
Cancel
Save