Merge pull request #16708 from owncloud/enc_fix_move_to_trash
make sure that we always use the correct owner for both source and target
This commit is contained in:
commit
e3440863bc
2 changed files with 63 additions and 31 deletions
|
@ -232,22 +232,8 @@ class Storage implements IStorage {
|
|||
*/
|
||||
public function renameKeys($source, $target) {
|
||||
|
||||
list($owner, $source) = $this->util->getUidAndFilename($source);
|
||||
list(, $target) = $this->util->getUidAndFilename($target);
|
||||
$systemWideSource = $this->util->isSystemWideMountPoint($source, $owner);
|
||||
$systemWideTarget = $this->util->isSystemWideMountPoint($target, $owner);
|
||||
|
||||
if ($systemWideSource) {
|
||||
$sourcePath = $this->keys_base_dir . $source . '/';
|
||||
} else {
|
||||
$sourcePath = '/' . $owner . $this->keys_base_dir . $source . '/';
|
||||
}
|
||||
|
||||
if ($systemWideTarget) {
|
||||
$targetPath = $this->keys_base_dir . $target . '/';
|
||||
} else {
|
||||
$targetPath = '/' . $owner . $this->keys_base_dir . $target . '/';
|
||||
}
|
||||
$sourcePath = $this->getPathToKeys($source);
|
||||
$targetPath = $this->getPathToKeys($target);
|
||||
|
||||
if ($this->view->file_exists($sourcePath)) {
|
||||
$this->keySetPreparation(dirname($targetPath));
|
||||
|
@ -259,6 +245,7 @@ class Storage implements IStorage {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* copy keys if a file was renamed
|
||||
*
|
||||
|
@ -268,21 +255,8 @@ class Storage implements IStorage {
|
|||
*/
|
||||
public function copyKeys($source, $target) {
|
||||
|
||||
list($owner, $source) = $this->util->getUidAndFilename($source);
|
||||
list(, $target) = $this->util->getUidAndFilename($target);
|
||||
$systemWideTarget = $this->util->isSystemWideMountPoint($target, $owner);
|
||||
$systemWideSource = $this->util->isSystemWideMountPoint($source, $owner);
|
||||
|
||||
if ($systemWideSource) {
|
||||
$sourcePath = $this->keys_base_dir . $source . '/';
|
||||
} else {
|
||||
$sourcePath = '/' . $owner . $this->keys_base_dir . $source . '/';
|
||||
}
|
||||
if ($systemWideTarget) {
|
||||
$targetPath = $this->keys_base_dir . $target . '/';
|
||||
} else {
|
||||
$targetPath = '/' . $owner . $this->keys_base_dir . $target . '/';
|
||||
}
|
||||
$sourcePath = $this->getPathToKeys($source);
|
||||
$targetPath = $this->getPathToKeys($target);
|
||||
|
||||
if ($this->view->file_exists($sourcePath)) {
|
||||
$this->keySetPreparation(dirname($targetPath));
|
||||
|
@ -293,6 +267,25 @@ class Storage implements IStorage {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* get system wide path and detect mount points
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
protected function getPathToKeys($path) {
|
||||
list($owner, $relativePath) = $this->util->getUidAndFilename($path);
|
||||
$systemWideMountPoint = $this->util->isSystemWideMountPoint($relativePath, $owner);
|
||||
|
||||
if ($systemWideMountPoint) {
|
||||
$systemPath = $this->keys_base_dir . $relativePath . '/';
|
||||
} else {
|
||||
$systemPath = '/' . $owner . $this->keys_base_dir . $relativePath . '/';
|
||||
}
|
||||
|
||||
return $systemPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make preparations to filesystem for saving a key file
|
||||
*
|
||||
|
|
|
@ -361,7 +361,46 @@ class StorageTest extends TestCase {
|
|||
array('/user1/files/source.txt', '/user1/files/target.txt', true, false,
|
||||
'/files_encryption/keys/files/source.txt/', '/user1/files_encryption/keys/files/target.txt/'),
|
||||
|
||||
array('/user2/files/source.txt', '/user1/files/target.txt', false, false,
|
||||
'/user2/files_encryption/keys/files/source.txt/', '/user1/files_encryption/keys/files/target.txt/'),
|
||||
array('/user2/files/foo/source.txt', '/user1/files/target.txt', false, false,
|
||||
'/user2/files_encryption/keys/files/foo/source.txt/', '/user1/files_encryption/keys/files/target.txt/'),
|
||||
array('/user2/files/source.txt', '/user1/files/foo/target.txt', false, false,
|
||||
'/user2/files_encryption/keys/files/source.txt/', '/user1/files_encryption/keys/files/foo/target.txt/'),
|
||||
array('/user2/files/source.txt', '/user1/files/foo/target.txt', true, true,
|
||||
'/files_encryption/keys/files/source.txt/', '/files_encryption/keys/files/foo/target.txt/'),
|
||||
array('/user2/files/source.txt', '/user1/files/target.txt', false, true,
|
||||
'/user2/files_encryption/keys/files/source.txt/', '/files_encryption/keys/files/target.txt/'),
|
||||
array('/user2/files/source.txt', '/user1/files/target.txt', true, false,
|
||||
'/files_encryption/keys/files/source.txt/', '/user1/files_encryption/keys/files/target.txt/'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataTestGetPathToKeys
|
||||
*
|
||||
* @param string $path
|
||||
* @param boolean $systemWideMountPoint
|
||||
* @param string $expected
|
||||
*/
|
||||
public function testGetPathToKeys($path, $systemWideMountPoint, $expected) {
|
||||
|
||||
$this->util->expects($this->any())
|
||||
->method('getUidAndFilename')
|
||||
->will($this->returnCallback(array($this, 'getUidAndFilenameCallback')));
|
||||
$this->util->expects($this->any())
|
||||
->method('isSystemWideMountPoint')
|
||||
->willReturn($systemWideMountPoint);
|
||||
|
||||
$this->assertSame($expected,
|
||||
\Test_Helper::invokePrivate($this->storage, 'getPathToKeys', [$path])
|
||||
);
|
||||
}
|
||||
|
||||
public function dataTestGetPathToKeys() {
|
||||
return array(
|
||||
array('/user1/files/source.txt', false, '/user1/files_encryption/keys/files/source.txt/'),
|
||||
array('/user1/files/source.txt', true, '/files_encryption/keys/files/source.txt/')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue