only trigger locking on lockingstorages

This commit is contained in:
Robin Appelman 2016-01-04 14:11:21 +01:00
parent 0724ac1e5e
commit bdf51d9ea4
3 changed files with 49 additions and 24 deletions

View file

@ -38,6 +38,7 @@ use OC\Files\Filesystem;
use OC\Hooks\BasicEmitter;
use OCP\Config;
use OCP\Files\Cache\IScanner;
use OCP\Files\Storage\ILockingStorage;
use OCP\Lock\ILockingProvider;
/**
@ -132,7 +133,9 @@ class Scanner extends BasicEmitter implements IScanner {
and !Filesystem::isFileBlacklisted($file)
) {
if ($lock) {
$this->storage->acquireLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$this->storage->acquireLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
}
}
$this->emit('\OC\Files\Cache\Scanner', 'scanFile', array($file, $this->storageId));
\OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId));
@ -192,7 +195,9 @@ class Scanner extends BasicEmitter implements IScanner {
$this->removeFromCache($file);
}
if ($lock) {
$this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$this->storage->releaseLock($file, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
}
}
return $data;
}
@ -259,7 +264,9 @@ class Scanner extends BasicEmitter implements IScanner {
$reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : self::REUSE_ETAG;
}
if ($lock) {
$this->storage->acquireLock($path, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$this->storage->acquireLock($path, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
}
}
$data = $this->scanFile($path, $reuse, -1, null, $lock);
if ($data and $data['mimetype'] === 'httpd/unix-directory') {
@ -267,7 +274,9 @@ class Scanner extends BasicEmitter implements IScanner {
$data['size'] = $size;
}
if ($lock) {
$this->storage->releaseLock($path, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$this->storage->releaseLock($path, ILockingProvider::LOCK_SHARED, $this->lockingProvider);
}
}
return $data;
}

View file

@ -26,9 +26,10 @@
namespace OC\Files\Storage\Wrapper;
use OCP\Files\InvalidPathException;
use OCP\Files\Storage\ILockingStorage;
use OCP\Lock\ILockingProvider;
class Wrapper implements \OC\Files\Storage\Storage {
class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage {
/**
* @var \OC\Files\Storage\Storage $storage
*/
@ -583,7 +584,9 @@ class Wrapper implements \OC\Files\Storage\Storage {
* @throws \OCP\Lock\LockedException
*/
public function acquireLock($path, $type, ILockingProvider $provider) {
$this->storage->acquireLock($path, $type, $provider);
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$this->storage->acquireLock($path, $type, $provider);
}
}
/**
@ -592,7 +595,9 @@ class Wrapper implements \OC\Files\Storage\Storage {
* @param \OCP\Lock\ILockingProvider $provider
*/
public function releaseLock($path, $type, ILockingProvider $provider) {
$this->storage->releaseLock($path, $type, $provider);
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$this->storage->releaseLock($path, $type, $provider);
}
}
/**
@ -601,6 +606,8 @@ class Wrapper implements \OC\Files\Storage\Storage {
* @param \OCP\Lock\ILockingProvider $provider
*/
public function changeLock($path, $type, ILockingProvider $provider) {
$this->storage->changeLock($path, $type, $provider);
if ($this->storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$this->storage->changeLock($path, $type, $provider);
}
}
}

View file

@ -43,7 +43,6 @@
namespace OC\Files;
use Icewind\Streams\CallbackWrapper;
use OC\Files\Cache\Updater;
use OC\Files\Mount\MoveableMount;
use OC\Files\Storage\Storage;
use OC\User\User;
@ -53,6 +52,7 @@ use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidPathException;
use OCP\Files\NotFoundException;
use OCP\Files\ReservedWordException;
use OCP\Files\Storage\ILockingStorage;
use OCP\IUser;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
@ -1835,11 +1835,14 @@ class View {
$mount = $this->getMountForLock($absolutePath, $lockMountPoint);
if ($mount) {
try {
$mount->getStorage()->acquireLock(
$mount->getInternalPath($absolutePath),
$type,
$this->lockingProvider
);
$storage = $mount->getStorage();
if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$storage->acquireLock(
$mount->getInternalPath($absolutePath),
$type,
$this->lockingProvider
);
}
} catch (\OCP\Lock\LockedException $e) {
// rethrow with the a human-readable path
throw new \OCP\Lock\LockedException(
@ -1873,11 +1876,14 @@ class View {
$mount = $this->getMountForLock($absolutePath, $lockMountPoint);
if ($mount) {
try {
$mount->getStorage()->changeLock(
$mount->getInternalPath($absolutePath),
$type,
$this->lockingProvider
);
$storage = $mount->getStorage();
if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$storage->changeLock(
$mount->getInternalPath($absolutePath),
$type,
$this->lockingProvider
);
}
} catch (\OCP\Lock\LockedException $e) {
// rethrow with the a human-readable path
throw new \OCP\Lock\LockedException(
@ -1908,11 +1914,14 @@ class View {
$mount = $this->getMountForLock($absolutePath, $lockMountPoint);
if ($mount) {
$mount->getStorage()->releaseLock(
$mount->getInternalPath($absolutePath),
$type,
$this->lockingProvider
);
$storage = $mount->getStorage();
if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$storage->releaseLock(
$mount->getInternalPath($absolutePath),
$type,
$this->lockingProvider
);
}
}
return true;