| @@ 1961-1989 (lines=29) @@ | ||
| 1958 | * @return bool False if the path is excluded from locking, true otherwise |
|
| 1959 | * @throws \OCP\Lock\LockedException if the path is already locked |
|
| 1960 | */ |
|
| 1961 | private function lockPath($path, $type, $lockMountPoint = false) { |
|
| 1962 | $absolutePath = $this->getAbsolutePath($path); |
|
| 1963 | $absolutePath = Filesystem::normalizePath($absolutePath); |
|
| 1964 | if (!$this->shouldLockFile($absolutePath)) { |
|
| 1965 | return false; |
|
| 1966 | } |
|
| 1967 | ||
| 1968 | $mount = $this->getMountForLock($absolutePath, $lockMountPoint); |
|
| 1969 | if ($mount) { |
|
| 1970 | try { |
|
| 1971 | $storage = $mount->getStorage(); |
|
| 1972 | if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
| 1973 | $storage->acquireLock( |
|
| 1974 | $mount->getInternalPath($absolutePath), |
|
| 1975 | $type, |
|
| 1976 | $this->lockingProvider |
|
| 1977 | ); |
|
| 1978 | } |
|
| 1979 | } catch (\OCP\Lock\LockedException $e) { |
|
| 1980 | // rethrow with the a human-readable path |
|
| 1981 | throw new \OCP\Lock\LockedException( |
|
| 1982 | $this->getPathRelativeToFiles($absolutePath), |
|
| 1983 | $e |
|
| 1984 | ); |
|
| 1985 | } |
|
| 1986 | } |
|
| 1987 | ||
| 1988 | return true; |
|
| 1989 | } |
|
| 1990 | ||
| 1991 | /** |
|
| 1992 | * Change the lock type |
|
| @@ 2001-2030 (lines=30) @@ | ||
| 1998 | * @return bool False if the path is excluded from locking, true otherwise |
|
| 1999 | * @throws \OCP\Lock\LockedException if the path is already locked |
|
| 2000 | */ |
|
| 2001 | public function changeLock($path, $type, $lockMountPoint = false) { |
|
| 2002 | $path = Filesystem::normalizePath($path); |
|
| 2003 | $absolutePath = $this->getAbsolutePath($path); |
|
| 2004 | $absolutePath = Filesystem::normalizePath($absolutePath); |
|
| 2005 | if (!$this->shouldLockFile($absolutePath)) { |
|
| 2006 | return false; |
|
| 2007 | } |
|
| 2008 | ||
| 2009 | $mount = $this->getMountForLock($absolutePath, $lockMountPoint); |
|
| 2010 | if ($mount) { |
|
| 2011 | try { |
|
| 2012 | $storage = $mount->getStorage(); |
|
| 2013 | if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
| 2014 | $storage->changeLock( |
|
| 2015 | $mount->getInternalPath($absolutePath), |
|
| 2016 | $type, |
|
| 2017 | $this->lockingProvider |
|
| 2018 | ); |
|
| 2019 | } |
|
| 2020 | } catch (LockedException $e) { |
|
| 2021 | // rethrow with the a human-readable path |
|
| 2022 | throw new LockedException( |
|
| 2023 | $this->getPathRelativeToFiles($absolutePath), |
|
| 2024 | $e |
|
| 2025 | ); |
|
| 2026 | } |
|
| 2027 | } |
|
| 2028 | ||
| 2029 | return true; |
|
| 2030 | } |
|
| 2031 | ||
| 2032 | /** |
|
| 2033 | * Unlock the given path |
|