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) {
return $this->keyStorage->deleteAllFileKeys($path, Encryption::ID);
return $this->keyStorage->deleteAllFileKeys($path);
}
/**

View File

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

View File

@ -206,8 +206,7 @@ class Encryption extends Wrapper {
$encryptionModule = $this->getEncryptionModule($path);
if ($encryptionModule) {
$this->keyStorage->deleteAllFileKeys($this->getFullPath($path),
$encryptionModule->getId());
$this->keyStorage->deleteAllFileKeys($this->getFullPath($path));
}
return $this->storage->unlink($path);
@ -238,6 +237,21 @@ class Encryption extends Wrapper {
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
*
@ -269,8 +283,13 @@ class Encryption extends Wrapper {
}
}
$data = $this->getMetaData($path1);
$this->getCache()->put($path2, ['encrypted' => $data['encrypted']]);
$this->updateUnencryptedSize($fullPath2, $data['size']);
if (isset($data['encrypted'])) {
$this->getCache()->put($path2, ['encrypted' => $data['encrypted']]);
}
if (isset($data['size'])) {
$this->updateUnencryptedSize($fullPath2, $data['size']);
}
}
return $result;

View File

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