Code Duplication    Length = 29-30 lines in 2 locations

lib/private/Files/View.php 2 locations

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