distinguish between source and target mount point to allow copy/rename between system wide mount points and user specific mountpoints

This commit is contained in:
Bjoern Schiessle 2015-05-21 14:06:45 +02:00
parent 896130b68d
commit 38bceb0d74
2 changed files with 43 additions and 18 deletions

View file

@ -233,13 +233,18 @@ class Storage implements IStorage {
list($owner, $source) = $this->util->getUidAndFilename($source);
list(, $target) = $this->util->getUidAndFilename($target);
$systemWide = $this->util->isSystemWideMountPoint($target, $owner);
$systemWideSource = $this->util->isSystemWideMountPoint($source, $owner);
$systemWideTarget = $this->util->isSystemWideMountPoint($target, $owner);
if ($systemWide) {
if ($systemWideSource) {
$sourcePath = $this->keys_base_dir . $source . '/';
$targetPath = $this->keys_base_dir . $target . '/';
} else {
$sourcePath = '/' . $owner . $this->keys_base_dir . $source . '/';
}
if ($systemWideTarget) {
$targetPath = $this->keys_base_dir . $target . '/';
} else {
$targetPath = '/' . $owner . $this->keys_base_dir . $target . '/';
}
@ -264,13 +269,17 @@ class Storage implements IStorage {
list($owner, $source) = $this->util->getUidAndFilename($source);
list(, $target) = $this->util->getUidAndFilename($target);
$systemWide = $this->util->isSystemWideMountPoint($target, $owner);
$systemWideTarget = $this->util->isSystemWideMountPoint($target, $owner);
$systemWideSource = $this->util->isSystemWideMountPoint($source, $owner);
if ($systemWide) {
if ($systemWideSource) {
$sourcePath = $this->keys_base_dir . $source . '/';
$targetPath = $this->keys_base_dir . $target . '/';
} else {
$sourcePath = '/' . $owner . $this->keys_base_dir . $source . '/';
}
if ($systemWideTarget) {
$targetPath = $this->keys_base_dir . $target . '/';
} else {
$targetPath = '/' . $owner . $this->keys_base_dir . $target . '/';
}

View file

@ -276,7 +276,7 @@ class StorageTest extends TestCase {
/**
* @dataProvider dataProviderCopyRename
*/
public function testRenameKeys($source, $target, $systemWideMount, $expectedSource, $expectedTarget) {
public function testRenameKeys($source, $target, $systemWideMountSource, $systemWideMountTarget, $expectedSource, $expectedTarget) {
$this->view->expects($this->any())
->method('file_exists')
->willReturn(true);
@ -294,7 +294,12 @@ class StorageTest extends TestCase {
->will($this->returnCallback(array($this, 'getUidAndFilenameCallback')));
$this->util->expects($this->any())
->method('isSystemWideMountPoint')
->willReturn($systemWideMount);
->willReturnCallback(function($path, $owner) use ($systemWideMountSource, $systemWideMountTarget) {
if(strpos($path, 'source.txt') !== false) {
return $systemWideMountSource;
}
return $systemWideMountTarget;
});
$this->storage->renameKeys($source, $target);
}
@ -302,7 +307,7 @@ class StorageTest extends TestCase {
/**
* @dataProvider dataProviderCopyRename
*/
public function testCopyKeys($source, $target, $systemWideMount, $expectedSource, $expectedTarget) {
public function testCopyKeys($source, $target, $systemWideMountSource, $systemWideMountTarget , $expectedSource, $expectedTarget) {
$this->view->expects($this->any())
->method('file_exists')
->willReturn(true);
@ -320,7 +325,12 @@ class StorageTest extends TestCase {
->will($this->returnCallback(array($this, 'getUidAndFilenameCallback')));
$this->util->expects($this->any())
->method('isSystemWideMountPoint')
->willReturn($systemWideMount);
->willReturnCallback(function($path, $owner) use ($systemWideMountSource, $systemWideMountTarget) {
if(strpos($path, 'source.txt') !== false) {
return $systemWideMountSource;
}
return $systemWideMountTarget;
});
$this->storage->copyKeys($source, $target);
}
@ -336,14 +346,20 @@ class StorageTest extends TestCase {
public function dataProviderCopyRename() {
return array(
array('/user1/files/foo.txt', '/user1/files/bar.txt', false,
'/user1/files_encryption/keys/files/foo.txt/', '/user1/files_encryption/keys/files/bar.txt/'),
array('/user1/files/foo/foo.txt', '/user1/files/bar.txt', false,
'/user1/files_encryption/keys/files/foo/foo.txt/', '/user1/files_encryption/keys/files/bar.txt/'),
array('/user1/files/foo.txt', '/user1/files/foo/bar.txt', false,
'/user1/files_encryption/keys/files/foo.txt/', '/user1/files_encryption/keys/files/foo/bar.txt/'),
array('/user1/files/foo.txt', '/user1/files/foo/bar.txt', true,
'/files_encryption/keys/files/foo.txt/', '/files_encryption/keys/files/foo/bar.txt/'),
array('/user1/files/source.txt', '/user1/files/target.txt', false, false,
'/user1/files_encryption/keys/files/source.txt/', '/user1/files_encryption/keys/files/target.txt/'),
array('/user1/files/foo/source.txt', '/user1/files/target.txt', false, false,
'/user1/files_encryption/keys/files/foo/source.txt/', '/user1/files_encryption/keys/files/target.txt/'),
array('/user1/files/source.txt', '/user1/files/foo/target.txt', false, false,
'/user1/files_encryption/keys/files/source.txt/', '/user1/files_encryption/keys/files/foo/target.txt/'),
array('/user1/files/source.txt', '/user1/files/foo/target.txt', true, true,
'/files_encryption/keys/files/source.txt/', '/files_encryption/keys/files/foo/target.txt/'),
array('/user1/files/source.txt', '/user1/files/target.txt', false, true,
'/user1/files_encryption/keys/files/source.txt/', '/files_encryption/keys/files/target.txt/'),
array('/user1/files/source.txt', '/user1/files/target.txt', true, false,
'/files_encryption/keys/files/source.txt/', '/user1/files_encryption/keys/files/target.txt/'),
);
}