Skip to content

Commit

Permalink
Fix hook encryption with cron job
Browse files Browse the repository at this point in the history
Make sure the setup fs is set before using the Update service

Fix #29674

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
  • Loading branch information
CarlSchwan committed Mar 31, 2022
1 parent cf4c77e commit 8f9b2af
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions lib/private/Encryption/HookManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,56 @@

use OC\Files\Filesystem;
use OC\Files\View;
use OC\Files\SetupManager;
use Psr\Log\LoggerInterface;

class HookManager {
/**
* @var Update
*/
private static $updater;
private static ?Update $updater = null;
private static bool $shouldTearDown = false;

public static function postShared($params) {
public static function postShared($params): void {
self::getUpdate()->postShared($params);
self::tearDown();
}
public static function postUnshared($params) {
public static function postUnshared($params): void {
self::getUpdate()->postUnshared($params);
self::tearDown();
}

public static function postRename($params) {
public static function postRename($params): void {
self::getUpdate()->postRename($params);
self::tearDown();
}

public static function postRestore($params) {
public static function postRestore($params): void {
self::getUpdate()->postRestore($params);
}

/**
* @return Update
*/
private static function getUpdate() {
private static function tearDown(): void {
if (!self::$shouldTearDown) {
return;
}

$setupManager = \OC::$server->get(SetupManager::class);
$setupManager->tearDownFS(); // TODO ideally we should only tear down the user fs and not the root
self::shouldTearDown = false;
}

private static function getUpdate(): Update {
if (is_null(self::$updater)) {
$user = \OC::$server->getUserSession()->getUser();

$uid = '';
if ($user) {
$uid = $user->getUID();
}

$setupManager = \OC::$server->get(SetupManager::class);
if (!$setupManager->isSetupComplete($user)) {
self::$shouldTearDown = true;
$setupManager->setupForUser($user);
}

self::$updater = new Update(
new View(),
new Util(
Expand Down

0 comments on commit 8f9b2af

Please sign in to comment.