Skip to content

Commit

Permalink
fix: Split storage wrappers for 25/26
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Feb 10, 2023
1 parent d23484d commit 9a2d39f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
9 changes: 1 addition & 8 deletions lib/ACL/ACLStorageWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Constants;

class ACLStorageWrapper extends Wrapper {
abstract class ACLStorageWrapper extends Wrapper {
private int $permissions;
private bool $inShare;

Expand Down Expand Up @@ -177,13 +177,6 @@ public function filetype($path) {
return parent::filetype($path);
}

public function filesize($path): false|int|float {
if (!$this->checkPermissions(Constants::PERMISSION_READ)) {
return false;
}
return parent::filesize($path);
}

public function file_exists($path): bool {
return $this->checkPermissions(Constants::PERMISSION_READ) && parent::file_exists($path);
}
Expand Down
16 changes: 16 additions & 0 deletions lib/ACL/ACLStorageWrapper26.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace OCA\Collectives\ACL;

use OCP\Constants;

class ACLStorageWrapper26 extends ACLStorageWrapper {
public function filesize($path): float|false|int {
if (!$this->checkPermissions(Constants::PERMISSION_READ)) {
return false;
}
return parent::filesize($path);
}
}
22 changes: 16 additions & 6 deletions lib/Mount/CollectiveFolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use OC\Files\Node\LazyFolder;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\Storage\Wrapper\PermissionsMask;
use OCA\Collectives\ACL\ACLStorageWrapper;
use OCA\Collectives\ACL\ACLStorageWrapper26;
use OCA\Collectives\ACL\ACLStorageWrapper25;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
Expand Down Expand Up @@ -140,11 +141,20 @@ public function getMount(int $id,
// apply acl before jail
if ($user) {
$inShare = $this->getCurrentUID() === null || $this->getCurrentUID() !== $user->getUID();
$storage = new ACLStorageWrapper([
'storage' => $storage,
'permissions' => $permissions,
'in_share' => $inShare
]);
[$major, $minor, $micro] = \OCP\Util::getVersion();
if ($major >= 26) {
$storage = new ACLStorageWrapper26([
'storage' => $storage,
'permissions' => $permissions,
'in_share' => $inShare
]);
} else {
$storage = new ACLStorageWrapper25([
'storage' => $storage,
'permissions' => $permissions,
'in_share' => $inShare
]);
}
$cacheEntry['permissions'] &= $permissions;
}

Expand Down

0 comments on commit 9a2d39f

Please sign in to comment.