Merge pull request #5603 from owncloud/fix_file_cache_updater_master
Fix file cache updater (backport to master of #5513)
This commit is contained in:
commit
de342a5ac7
4 changed files with 105 additions and 33 deletions
|
@ -35,6 +35,12 @@ class Hooks {
|
||||||
* @note This method should never be called for users using client side encryption
|
* @note This method should never be called for users using client side encryption
|
||||||
*/
|
*/
|
||||||
public static function login($params) {
|
public static function login($params) {
|
||||||
|
|
||||||
|
if (\OCP\App::isEnabled('files_encryption') === false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$l = new \OC_L10N('files_encryption');
|
$l = new \OC_L10N('files_encryption');
|
||||||
|
|
||||||
$view = new \OC_FilesystemView('/');
|
$view = new \OC_FilesystemView('/');
|
||||||
|
@ -117,11 +123,12 @@ class Hooks {
|
||||||
* @note This method should never be called for users using client side encryption
|
* @note This method should never be called for users using client side encryption
|
||||||
*/
|
*/
|
||||||
public static function postCreateUser($params) {
|
public static function postCreateUser($params) {
|
||||||
$view = new \OC_FilesystemView('/');
|
|
||||||
|
|
||||||
$util = new Util($view, $params['uid']);
|
if (\OCP\App::isEnabled('files_encryption')) {
|
||||||
|
$view = new \OC_FilesystemView('/');
|
||||||
Helper::setupUser($util, $params['password']);
|
$util = new Util($view, $params['uid']);
|
||||||
|
Helper::setupUser($util, $params['password']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,26 +136,31 @@ class Hooks {
|
||||||
* @note This method should never be called for users using client side encryption
|
* @note This method should never be called for users using client side encryption
|
||||||
*/
|
*/
|
||||||
public static function postDeleteUser($params) {
|
public static function postDeleteUser($params) {
|
||||||
$view = new \OC_FilesystemView('/');
|
|
||||||
|
|
||||||
// cleanup public key
|
if (\OCP\App::isEnabled('files_encryption')) {
|
||||||
$publicKey = '/public-keys/' . $params['uid'] . '.public.key';
|
$view = new \OC_FilesystemView('/');
|
||||||
|
|
||||||
// Disable encryption proxy to prevent recursive calls
|
// cleanup public key
|
||||||
$proxyStatus = \OC_FileProxy::$enabled;
|
$publicKey = '/public-keys/' . $params['uid'] . '.public.key';
|
||||||
\OC_FileProxy::$enabled = false;
|
|
||||||
|
|
||||||
$view->unlink($publicKey);
|
// Disable encryption proxy to prevent recursive calls
|
||||||
|
$proxyStatus = \OC_FileProxy::$enabled;
|
||||||
|
\OC_FileProxy::$enabled = false;
|
||||||
|
|
||||||
\OC_FileProxy::$enabled = $proxyStatus;
|
$view->unlink($publicKey);
|
||||||
|
|
||||||
|
\OC_FileProxy::$enabled = $proxyStatus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief If the password can't be changed within ownCloud, than update the key password in advance.
|
* @brief If the password can't be changed within ownCloud, than update the key password in advance.
|
||||||
*/
|
*/
|
||||||
public static function preSetPassphrase($params) {
|
public static function preSetPassphrase($params) {
|
||||||
if ( ! \OC_User::canUserChangePassword($params['uid']) ) {
|
if (\OCP\App::isEnabled('files_encryption')) {
|
||||||
self::setPassphrase($params);
|
if ( ! \OC_User::canUserChangePassword($params['uid']) ) {
|
||||||
|
self::setPassphrase($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +169,11 @@ class Hooks {
|
||||||
* @param array $params keys: uid, password
|
* @param array $params keys: uid, password
|
||||||
*/
|
*/
|
||||||
public static function setPassphrase($params) {
|
public static function setPassphrase($params) {
|
||||||
|
|
||||||
|
if (\OCP\App::isEnabled('files_encryption') === false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Only attempt to change passphrase if server-side encryption
|
// Only attempt to change passphrase if server-side encryption
|
||||||
// is in use (client-side encryption does not have access to
|
// is in use (client-side encryption does not have access to
|
||||||
// the necessary keys)
|
// the necessary keys)
|
||||||
|
@ -227,6 +244,10 @@ class Hooks {
|
||||||
*/
|
*/
|
||||||
public static function preShared($params) {
|
public static function preShared($params) {
|
||||||
|
|
||||||
|
if (\OCP\App::isEnabled('files_encryption') === false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$l = new \OC_L10N('files_encryption');
|
$l = new \OC_L10N('files_encryption');
|
||||||
$users = array();
|
$users = array();
|
||||||
$view = new \OC\Files\View('/public-keys/');
|
$view = new \OC\Files\View('/public-keys/');
|
||||||
|
@ -278,6 +299,10 @@ class Hooks {
|
||||||
// [run] => whether emitting script should continue to run
|
// [run] => whether emitting script should continue to run
|
||||||
// TODO: Should other kinds of item be encrypted too?
|
// TODO: Should other kinds of item be encrypted too?
|
||||||
|
|
||||||
|
if (\OCP\App::isEnabled('files_encryption') === false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
|
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
|
||||||
|
|
||||||
$view = new \OC_FilesystemView('/');
|
$view = new \OC_FilesystemView('/');
|
||||||
|
@ -372,6 +397,10 @@ class Hooks {
|
||||||
// [shareWith] => test1
|
// [shareWith] => test1
|
||||||
// [itemParent] =>
|
// [itemParent] =>
|
||||||
|
|
||||||
|
if (\OCP\App::isEnabled('files_encryption') === false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
|
if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
|
||||||
|
|
||||||
$view = new \OC_FilesystemView('/');
|
$view = new \OC_FilesystemView('/');
|
||||||
|
@ -453,6 +482,11 @@ class Hooks {
|
||||||
* of the stored versions along the actual file
|
* of the stored versions along the actual file
|
||||||
*/
|
*/
|
||||||
public static function postRename($params) {
|
public static function postRename($params) {
|
||||||
|
|
||||||
|
if (\OCP\App::isEnabled('files_encryption') === false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Disable encryption proxy to prevent recursive calls
|
// Disable encryption proxy to prevent recursive calls
|
||||||
$proxyStatus = \OC_FileProxy::$enabled;
|
$proxyStatus = \OC_FileProxy::$enabled;
|
||||||
\OC_FileProxy::$enabled = false;
|
\OC_FileProxy::$enabled = false;
|
||||||
|
|
|
@ -49,13 +49,6 @@ class Shared_Updater {
|
||||||
}
|
}
|
||||||
$users = $reshareUsers;
|
$users = $reshareUsers;
|
||||||
}
|
}
|
||||||
// Correct folders of shared file owner
|
|
||||||
$target = substr($target, 8);
|
|
||||||
if ($uidOwner !== $uid && $source = \OC_Share_Backend_File::getSource($target)) {
|
|
||||||
\OC\Files\Filesystem::initMountPoints($uidOwner);
|
|
||||||
$source = '/'.$uidOwner.'/'.$source['path'];
|
|
||||||
\OC\Files\Cache\Updater::correctFolder($source, $info['mtime']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
51
lib/private/files/cache/updater.php
vendored
51
lib/private/files/cache/updater.php
vendored
|
@ -94,6 +94,24 @@ class Updater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief get file owner and path
|
||||||
|
* @param string $filename
|
||||||
|
* @return array with the oweners uid and the owners path
|
||||||
|
*/
|
||||||
|
private static function getUidAndFilename($filename) {
|
||||||
|
|
||||||
|
$uid = \OC\Files\Filesystem::getOwner($filename);
|
||||||
|
\OC\Files\Filesystem::initMountPoints($uid);
|
||||||
|
|
||||||
|
if ($uid != \OCP\User::getUser()) {
|
||||||
|
$info = \OC\Files\Filesystem::getFileInfo($filename);
|
||||||
|
$ownerView = new \OC\Files\View('/' . $uid . '/files');
|
||||||
|
$filename = $ownerView->getPath($info['fileid']);
|
||||||
|
}
|
||||||
|
return array($uid, '/files/' . $filename);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the mtime and ETag of all parent folders
|
* Update the mtime and ETag of all parent folders
|
||||||
*
|
*
|
||||||
|
@ -102,23 +120,32 @@ class Updater {
|
||||||
*/
|
*/
|
||||||
static public function correctFolder($path, $time) {
|
static public function correctFolder($path, $time) {
|
||||||
if ($path !== '' && $path !== '/') {
|
if ($path !== '' && $path !== '/') {
|
||||||
$parent = dirname($path);
|
|
||||||
if ($parent === '.' || $parent === '\\') {
|
list($owner, $realPath) = self::getUidAndFilename(dirname($path));
|
||||||
$parent = '';
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\Files\Storage\Storage $storage
|
* @var \OC\Files\Storage\Storage $storage
|
||||||
* @var string $internalPath
|
* @var string $internalPath
|
||||||
*/
|
*/
|
||||||
list($storage, $internalPath) = self::resolvePath($parent);
|
$view = new \OC\Files\View('/' . $owner);
|
||||||
if ($storage) {
|
|
||||||
$cache = $storage->getCache();
|
list($storage, $internalPath) = $view->resolvePath($realPath);
|
||||||
$id = $cache->getId($internalPath);
|
$cache = $storage->getCache();
|
||||||
if ($id !== -1) {
|
$id = $cache->getId($internalPath);
|
||||||
$cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath)));
|
|
||||||
self::correctFolder($parent, $time);
|
while ($id !== -1) {
|
||||||
|
$cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath)));
|
||||||
|
if ($realPath !== '') {
|
||||||
|
$realPath = dirname($realPath);
|
||||||
|
if($realPath === '/') {
|
||||||
|
$realPath = "";
|
||||||
|
}
|
||||||
|
// check storage for parent in case we change the storage in this step
|
||||||
|
list($storage, $internalPath) = $view->resolvePath($realPath);
|
||||||
|
$cache = $storage->getCache();
|
||||||
|
$id = $cache->getId($internalPath);
|
||||||
} else {
|
} else {
|
||||||
Util::writeLog('core', 'Path not in cache: '.$internalPath, Util::ERROR);
|
$id = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
tests/lib/files/cache/updater.php
vendored
18
tests/lib/files/cache/updater.php
vendored
|
@ -21,6 +21,8 @@ class Updater extends \PHPUnit_Framework_TestCase {
|
||||||
*/
|
*/
|
||||||
private $scanner;
|
private $scanner;
|
||||||
|
|
||||||
|
private $stateFilesEncryption;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \OC\Files\Cache\Cache $cache
|
* @var \OC\Files\Cache\Cache $cache
|
||||||
*/
|
*/
|
||||||
|
@ -29,6 +31,12 @@ class Updater extends \PHPUnit_Framework_TestCase {
|
||||||
private static $user;
|
private static $user;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
|
|
||||||
|
// remember files_encryption state
|
||||||
|
$this->stateFilesEncryption = \OC_App::isEnabled('files_encryption');
|
||||||
|
// we want to tests with the encryption app disabled
|
||||||
|
\OC_App::disable('files_encryption');
|
||||||
|
|
||||||
$this->storage = new \OC\Files\Storage\Temporary(array());
|
$this->storage = new \OC\Files\Storage\Temporary(array());
|
||||||
$textData = "dummy file data\n";
|
$textData = "dummy file data\n";
|
||||||
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
|
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
|
||||||
|
@ -46,6 +54,10 @@ class Updater extends \PHPUnit_Framework_TestCase {
|
||||||
if (!self::$user) {
|
if (!self::$user) {
|
||||||
self::$user = uniqid();
|
self::$user = uniqid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
\OC_User::createUser(self::$user, 'password');
|
||||||
|
\OC_User::setUserId(self::$user);
|
||||||
|
|
||||||
\OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
|
\OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
|
||||||
|
|
||||||
Filesystem::clearMounts();
|
Filesystem::clearMounts();
|
||||||
|
@ -63,7 +75,13 @@ class Updater extends \PHPUnit_Framework_TestCase {
|
||||||
if ($this->cache) {
|
if ($this->cache) {
|
||||||
$this->cache->clear();
|
$this->cache->clear();
|
||||||
}
|
}
|
||||||
|
$result = \OC_User::deleteUser(self::$user);
|
||||||
|
$this->assertTrue($result);
|
||||||
Filesystem::tearDown();
|
Filesystem::tearDown();
|
||||||
|
// reset app files_encryption
|
||||||
|
if ($this->stateFilesEncryption) {
|
||||||
|
\OC_App::enable('files_encryption');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWrite() {
|
public function testWrite() {
|
||||||
|
|
Loading…
Reference in a new issue