| @@ 1889-1917 (lines=29) @@ | ||
| 1886 | * @return bool False if the path is excluded from locking, true otherwise |
|
| 1887 | * @throws \OCP\Lock\LockedException if the path is already locked |
|
| 1888 | */ |
|
| 1889 | private function lockPath($path, $type, $lockMountPoint = false) { |
|
| 1890 | $absolutePath = $this->getAbsolutePath($path); |
|
| 1891 | $absolutePath = Filesystem::normalizePath($absolutePath); |
|
| 1892 | if (!$this->shouldLockFile($absolutePath)) { |
|
| 1893 | return false; |
|
| 1894 | } |
|
| 1895 | ||
| 1896 | $mount = $this->getMountForLock($absolutePath, $lockMountPoint); |
|
| 1897 | if ($mount) { |
|
| 1898 | try { |
|
| 1899 | $storage = $mount->getStorage(); |
|
| 1900 | if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
| 1901 | $storage->acquireLock( |
|
| 1902 | $mount->getInternalPath($absolutePath), |
|
| 1903 | $type, |
|
| 1904 | $this->lockingProvider |
|
| 1905 | ); |
|
| 1906 | } |
|
| 1907 | } catch (\OCP\Lock\LockedException $e) { |
|
| 1908 | // rethrow with the a human-readable path |
|
| 1909 | throw new \OCP\Lock\LockedException( |
|
| 1910 | $this->getPathRelativeToFiles($absolutePath), |
|
| 1911 | $e |
|
| 1912 | ); |
|
| 1913 | } |
|
| 1914 | } |
|
| 1915 | ||
| 1916 | return true; |
|
| 1917 | } |
|
| 1918 | ||
| 1919 | /** |
|
| 1920 | * Change the lock type |
|
| @@ 1929-1958 (lines=30) @@ | ||
| 1926 | * @return bool False if the path is excluded from locking, true otherwise |
|
| 1927 | * @throws \OCP\Lock\LockedException if the path is already locked |
|
| 1928 | */ |
|
| 1929 | public function changeLock($path, $type, $lockMountPoint = false) { |
|
| 1930 | $path = Filesystem::normalizePath($path); |
|
| 1931 | $absolutePath = $this->getAbsolutePath($path); |
|
| 1932 | $absolutePath = Filesystem::normalizePath($absolutePath); |
|
| 1933 | if (!$this->shouldLockFile($absolutePath)) { |
|
| 1934 | return false; |
|
| 1935 | } |
|
| 1936 | ||
| 1937 | $mount = $this->getMountForLock($absolutePath, $lockMountPoint); |
|
| 1938 | if ($mount) { |
|
| 1939 | try { |
|
| 1940 | $storage = $mount->getStorage(); |
|
| 1941 | if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { |
|
| 1942 | $storage->changeLock( |
|
| 1943 | $mount->getInternalPath($absolutePath), |
|
| 1944 | $type, |
|
| 1945 | $this->lockingProvider |
|
| 1946 | ); |
|
| 1947 | } |
|
| 1948 | } catch (LockedException $e) { |
|
| 1949 | // rethrow with the a human-readable path |
|
| 1950 | throw new LockedException( |
|
| 1951 | $this->getPathRelativeToFiles($absolutePath), |
|
| 1952 | $e |
|
| 1953 | ); |
|
| 1954 | } |
|
| 1955 | } |
|
| 1956 | ||
| 1957 | return true; |
|
| 1958 | } |
|
| 1959 | ||
| 1960 | /** |
|
| 1961 | * Unlock the given path |
|