本文整理汇总了PHP中OC\Files\View::lockFile方法的典型用法代码示例。如果您正苦于以下问题:PHP View::lockFile方法的具体用法?PHP View::lockFile怎么用?PHP View::lockFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\View
的用法示例。
在下文中一共展示了View::lockFile方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testChangeLock
public function testChangeLock()
{
Filesystem::initMountPoints($this->recipientUid);
$recipientView = new View('/' . $this->recipientUid . '/files');
$recipientView->lockFile('bar.txt', ILockingProvider::LOCK_SHARED);
$recipientView->changeLock('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
$recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
$this->assertTrue(true);
}
示例2: acquireLock
/**
* @param string $path
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
* @param \OCP\Lock\ILockingProvider $provider
* @throws \OCP\Lock\LockedException
*/
public function acquireLock($path, $type, ILockingProvider $provider)
{
/** @var \OCP\Files\Storage $targetStorage */
list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
$targetStorage->acquireLock($targetInternalPath, $type, $provider);
// lock the parent folders of the owner when locking the share as recipient
if ($path === '') {
$sourcePath = $this->ownerView->getPath($this->share['file_source']);
$this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
}
}
示例3: isFileLocked
/**
* Check if the given path is locked with a given type
*
* @param \OC\Files\View $view view
* @param string $path path to check
* @param int $type lock type
* @param bool $onMountPoint true to check the mount point instead of the
* mounted storage
*
* @return boolean true if the file is locked with the
* given type, false otherwise
*/
protected function isFileLocked($view, $path, $type, $onMountPoint = false)
{
// Note: this seems convoluted but is necessary because
// the format of the lock key depends on the storage implementation
// (in our case mostly md5)
if ($type === \OCP\Lock\ILockingProvider::LOCK_SHARED) {
// to check if the file has a shared lock, try acquiring an exclusive lock
$checkType = \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE;
} else {
// a shared lock cannot be set if exclusive lock is in place
$checkType = \OCP\Lock\ILockingProvider::LOCK_SHARED;
}
try {
$view->lockFile($path, $checkType, $onMountPoint);
// no exception, which means the lock of $type is not set
// clean up
$view->unlockFile($path, $checkType, $onMountPoint);
return false;
} catch (\OCP\Lock\LockedException $e) {
// we could not acquire the counter-lock, which means
// the lock of $type was in place
return true;
}
}
示例4: lockFiles
/**
* @param View $view
* @param string $dir
* @param string[]|string $files
*/
public static function lockFiles($view, $dir, $files)
{
if (!is_array($files)) {
$file = $dir . '/' . $files;
$files = [$file];
}
foreach ($files as $file) {
$file = $dir . '/' . $file;
$view->lockFile($file, ILockingProvider::LOCK_SHARED);
if ($view->is_dir($file)) {
$contents = $view->getDirectoryContent($file);
$contents = array_map(function ($fileInfo) use($file) {
/** @var \OCP\Files\FileInfo $fileInfo */
return $file . '/' . $fileInfo->getName();
}, $contents);
self::lockFiles($view, $dir, $contents);
}
}
}
示例5: acquireLock
/**
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
*/
public function acquireLock($type)
{
$this->fileView->lockFile($this->path, $type);
}
示例6: copyFileContents
/**
* Stream copy file contents from $path1 to $path2
*
* @param View $view view to use for copying
* @param string $path1 source file to copy
* @param string $path2 target file
*
* @return bool true for success, false otherwise
*/
private static function copyFileContents($view, $path1, $path2)
{
/** @var \OC\Files\Storage\Storage $storage1 */
list($storage1, $internalPath1) = $view->resolvePath($path1);
/** @var \OC\Files\Storage\Storage $storage2 */
list($storage2, $internalPath2) = $view->resolvePath($path2);
$view->lockFile($path1, ILockingProvider::LOCK_EXCLUSIVE);
$view->lockFile($path2, ILockingProvider::LOCK_EXCLUSIVE);
// TODO add a proper way of overwriting a file while maintaining file ids
if ($storage1->instanceOfStorage('\\OC\\Files\\ObjectStore\\ObjectStoreStorage') || $storage2->instanceOfStorage('\\OC\\Files\\ObjectStore\\ObjectStoreStorage')) {
$source = $storage1->fopen($internalPath1, 'r');
$target = $storage2->fopen($internalPath2, 'w');
list(, $result) = \OC_Helper::streamCopy($source, $target);
fclose($source);
fclose($target);
if ($result !== false) {
$storage1->unlink($internalPath1);
}
} else {
$result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2);
}
$view->unlockFile($path1, ILockingProvider::LOCK_EXCLUSIVE);
$view->unlockFile($path2, ILockingProvider::LOCK_EXCLUSIVE);
return $result !== false;
}
示例7: lock
/**
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
* @throws \OCP\Lock\LockedException
*/
public function lock($type)
{
$this->view->lockFile($this->path, $type);
}
示例8: copyFileContents
/**
* Stream copy file contents from $path1 to $path2
*
* @param \OC\Files\View $view view to use for copying
* @param string $path1 source file to copy
* @param string $path2 target file
*
* @return bool true for success, false otherwise
*/
private static function copyFileContents($view, $path1, $path2)
{
/** @var \OC\Files\Storage\Storage $storage1 */
list($storage1, $internalPath1) = $view->resolvePath($path1);
/** @var \OC\Files\Storage\Storage $storage2 */
list($storage2, $internalPath2) = $view->resolvePath($path2);
$view->lockFile($path1, ILockingProvider::LOCK_EXCLUSIVE);
$view->lockFile($path2, ILockingProvider::LOCK_EXCLUSIVE);
$result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2);
$view->unlockFile($path1, ILockingProvider::LOCK_EXCLUSIVE);
$view->unlockFile($path2, ILockingProvider::LOCK_EXCLUSIVE);
return $result !== false;
}