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