| @@ 1944-1972 (lines=29) @@ | ||
| 1941 | * @return bool False if the path is excluded from locking, true otherwise |
|
| 1942 | * @throws \OCP\Lock\LockedException if the path is already locked |
|
| 1943 | */ |
|
| 1944 | private function lockPath($path, $type, $lockMountPoint = false) { |
|
| 1945 | $absolutePath = $this->getAbsolutePath($path); |
|
| 1946 | $absolutePath = Filesystem::normalizePath($absolutePath); |
|
| 1947 | if (!$this->shouldLockFile($absolutePath)) { |
|
| 1948 | return false; |
|
| 1949 | } |
|
| 1950 | ||
| 1951 | $mount = $this->getMountForLock($absolutePath, $lockMountPoint); |
|
| 1952 | if ($mount) { |
|
| 1953 | try { |
|
| 1954 | $storage = $mount->getStorage(); |
|
| 1955 | if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
| 1956 | $storage->acquireLock( |
|
| 1957 | $mount->getInternalPath($absolutePath), |
|
| 1958 | $type, |
|
| 1959 | $this->lockingProvider |
|
| 1960 | ); |
|
| 1961 | } |
|
| 1962 | } catch (\OCP\Lock\LockedException $e) { |
|
| 1963 | // rethrow with the a human-readable path |
|
| 1964 | throw new \OCP\Lock\LockedException( |
|
| 1965 | $this->getPathRelativeToFiles($absolutePath), |
|
| 1966 | $e |
|
| 1967 | ); |
|
| 1968 | } |
|
| 1969 | } |
|
| 1970 | ||
| 1971 | return true; |
|
| 1972 | } |
|
| 1973 | ||
| 1974 | /** |
|
| 1975 | * Change the lock type |
|
| @@ 1984-2013 (lines=30) @@ | ||
| 1981 | * @return bool False if the path is excluded from locking, true otherwise |
|
| 1982 | * @throws \OCP\Lock\LockedException if the path is already locked |
|
| 1983 | */ |
|
| 1984 | public function changeLock($path, $type, $lockMountPoint = false) { |
|
| 1985 | $path = Filesystem::normalizePath($path); |
|
| 1986 | $absolutePath = $this->getAbsolutePath($path); |
|
| 1987 | $absolutePath = Filesystem::normalizePath($absolutePath); |
|
| 1988 | if (!$this->shouldLockFile($absolutePath)) { |
|
| 1989 | return false; |
|
| 1990 | } |
|
| 1991 | ||
| 1992 | $mount = $this->getMountForLock($absolutePath, $lockMountPoint); |
|
| 1993 | if ($mount) { |
|
| 1994 | try { |
|
| 1995 | $storage = $mount->getStorage(); |
|
| 1996 | if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
| 1997 | $storage->changeLock( |
|
| 1998 | $mount->getInternalPath($absolutePath), |
|
| 1999 | $type, |
|
| 2000 | $this->lockingProvider |
|
| 2001 | ); |
|
| 2002 | } |
|
| 2003 | } catch (LockedException $e) { |
|
| 2004 | // rethrow with the a human-readable path |
|
| 2005 | throw new LockedException( |
|
| 2006 | $this->getPathRelativeToFiles($absolutePath), |
|
| 2007 | $e |
|
| 2008 | ); |
|
| 2009 | } |
|
| 2010 | } |
|
| 2011 | ||
| 2012 | return true; |
|
| 2013 | } |
|
| 2014 | ||
| 2015 | /** |
|
| 2016 | * Unlock the given path |
|