delete all file keys doesn't need the encryption module as parameter; implement rmdir; getFileKeyDir should also work for part files and complete directories

This commit is contained in:
Bjoern Schiessle 2015-05-13 14:39:27 +02:00
parent 5941e826b8
commit ccbefb6e75
4 changed files with 28 additions and 18 deletions

View File

@ -483,7 +483,7 @@ class KeyManager {
} }
public function deleteAllFileKeys($path) { public function deleteAllFileKeys($path) {
return $this->keyStorage->deleteAllFileKeys($path, Encryption::ID); return $this->keyStorage->deleteAllFileKeys($path);
} }
/** /**

View File

@ -125,10 +125,9 @@ class Storage implements IStorage {
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function deleteAllFileKeys($path, $encryptionModuleId) { public function deleteAllFileKeys($path) {
$keyDir = $this->getFileKeyDir($encryptionModuleId, $path); $keyDir = $this->getFileKeyDir('', $path);
$path = dirname($keyDir); return !$this->view->file_exists($keyDir) || $this->view->deleteAll($keyDir);
return !$this->view->file_exists($path) || $this->view->deleteAll($path);
} }
/** /**
@ -208,17 +207,10 @@ class Storage implements IStorage {
* @param string $encryptionModuleId * @param string $encryptionModuleId
* @param string $path path to the file, relative to data/ * @param string $path path to the file, relative to data/
* @return string * @return string
* @throws GenericEncryptionException
* @internal param string $keyId
*/ */
private function getFileKeyDir($encryptionModuleId, $path) { private function getFileKeyDir($encryptionModuleId, $path) {
if ($this->view->is_dir($path)) {
throw new GenericEncryptionException("file was expected but directory was given: $path");
}
list($owner, $filename) = $this->util->getUidAndFilename($path); list($owner, $filename) = $this->util->getUidAndFilename($path);
$filename = $this->util->stripPartialFileExtension($filename);
// in case of system wide mount points the keys are stored directly in the data directory // in case of system wide mount points the keys are stored directly in the data directory
if ($this->util->isSystemWideMountPoint($filename, $owner)) { if ($this->util->isSystemWideMountPoint($filename, $owner)) {

View File

@ -206,8 +206,7 @@ class Encryption extends Wrapper {
$encryptionModule = $this->getEncryptionModule($path); $encryptionModule = $this->getEncryptionModule($path);
if ($encryptionModule) { if ($encryptionModule) {
$this->keyStorage->deleteAllFileKeys($this->getFullPath($path), $this->keyStorage->deleteAllFileKeys($this->getFullPath($path));
$encryptionModule->getId());
} }
return $this->storage->unlink($path); return $this->storage->unlink($path);
@ -238,6 +237,21 @@ class Encryption extends Wrapper {
return $result; return $result;
} }
/**
* see http://php.net/manual/en/function.rmdir.php
*
* @param string $path
* @return bool
*/
public function rmdir($path) {
$result = $this->storage->rmdir($path);
if ($result && $this->encryptionManager->isEnabled()) {
$this->keyStorage->deleteAllFileKeys($this->getFullPath($path));
}
return $result;
}
/** /**
* see http://php.net/manual/en/function.copy.php * see http://php.net/manual/en/function.copy.php
* *
@ -269,9 +283,14 @@ class Encryption extends Wrapper {
} }
} }
$data = $this->getMetaData($path1); $data = $this->getMetaData($path1);
if (isset($data['encrypted'])) {
$this->getCache()->put($path2, ['encrypted' => $data['encrypted']]); $this->getCache()->put($path2, ['encrypted' => $data['encrypted']]);
}
if (isset($data['size'])) {
$this->updateUnencryptedSize($fullPath2, $data['size']); $this->updateUnencryptedSize($fullPath2, $data['size']);
} }
}
return $result; return $result;
} }

View File

@ -129,12 +129,11 @@ interface IStorage {
* delete all file keys for a given file * delete all file keys for a given file
* *
* @param string $path to the file * @param string $path to the file
* @param string $encryptionModuleId
* *
* @return boolean False when the keys could not be deleted * @return boolean False when the keys could not be deleted
* @since 8.1.0 * @since 8.1.0
*/ */
public function deleteAllFileKeys($path, $encryptionModuleId); public function deleteAllFileKeys($path);
/** /**
* delete system-wide encryption keys not related to a specific user, * delete system-wide encryption keys not related to a specific user,