after the initial verification this can only really be invalidated by a system mount (external/group/etc) being created at the share target since any normal file/folder creation will already conflict with the share
Signed-off-by: Robin Appelman <robin@icewind.nl>
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
/** @var IEventDispatcher */
protected $eventDispatcher;
+ /** @var ICacheFactory */
+ protected $cacheFactory;
+
/**
* @param \OCP\IConfig $config
* @param IManager $shareManager
IConfig $config,
IManager $shareManager,
ILogger $logger,
- IEventDispatcher $eventDispatcher
+ IEventDispatcher $eventDispatcher,
+ ICacheFactory $cacheFactory
) {
$this->config = $config;
$this->shareManager = $shareManager;
$this->logger = $logger;
$this->eventDispatcher = $eventDispatcher;
+ $this->cacheFactory = $cacheFactory;
}
$view,
$foldersExistCache,
$this->eventDispatcher,
- $user
+ $user,
+ $this->cacheFactory->createLocal('share-valid-mountpoint')
);
$event = new ShareMountedEvent($mount);
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
+
namespace OCA\Files_Sharing;
use OC\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\InvalidateMountCacheEvent;
use OCP\Files\Storage\IStorageFactory;
+use OCP\ICache;
use OCP\IUser;
use OCP\Share\Events\VerifyMountPointEvent;
private IEventDispatcher $eventDispatcher;
+ private ICache $cache;
+
public function __construct(
$storage,
array $mountpoints,
View $recipientView,
CappedMemoryCache $folderExistCache,
IEventDispatcher $eventDispatcher,
- IUser $user
+ IUser $user,
+ ICache $cache
) {
$this->user = $user;
$this->recipientView = $recipientView;
$this->eventDispatcher = $eventDispatcher;
+ $this->cache = $cache;
$this->superShare = $arguments['superShare'];
$this->groupedShares = $arguments['groupedShares'];
* @param SharedMount[] $mountpoints
* @return string
*/
- private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints, CappedMemoryCache $folderExistCache) {
+ private function verifyMountPoint(
+ \OCP\Share\IShare $share,
+ array $mountpoints,
+ CappedMemoryCache $folderExistCache
+ ) {
+ $cacheKey = $this->user->getUID() . '/' . $share->getTarget();
+ $cached = $this->cache->get($cacheKey);
+ if ($cached !== null) {
+ return $cached;
+ }
+
$mountPoint = basename($share->getTarget());
$parent = dirname($share->getTarget());
$this->updateFileTarget($newMountPoint, $share);
}
+ $this->cache->set($cacheKey, $newMountPoint, 60 * 60);
+
return $newMountPoint;
}
*/
namespace OCA\Files_Sharing\Tests;
+use OC\Memcache\NullCache;
use OCA\Files_Sharing\MountProvider;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\Files\Storage\IStorageFactory;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
$this->shareManager = $this->getMockBuilder(IManager::class)->getMock();
$this->logger = $this->getMockBuilder(ILogger::class)->getMock();
$eventDispatcher = $this->createMock(IEventDispatcher::class);
+ $cacheFactory = $this->createMock(ICacheFactory::class);
+ $cacheFactory->method('createLocal')
+ ->willReturn(new NullCache());
- $this->provider = new MountProvider($this->config, $this->shareManager, $this->logger, $eventDispatcher);
+ $this->provider = new MountProvider($this->config, $this->shareManager, $this->logger, $eventDispatcher, $cacheFactory);
}
private function makeMockShare($id, $nodeId, $owner = 'user2', $target = null, $permissions = 31) {