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