Code Duplication    Length = 14-14 lines in 2 locations

lib/private/Lock/MemcacheLockingProvider.php 2 locations

@@ 72-85 (lines=14) @@
69
	 * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
70
	 * @throws \OCP\Lock\LockedException
71
	 */
72
	public function acquireLock(string $path, int $type) {
73
		if ($type === self::LOCK_SHARED) {
74
			if (!$this->memcache->inc($path)) {
75
				throw new LockedException($path, null, $this->getExistingLockForException($path));
76
			}
77
		} else {
78
			$this->memcache->add($path, 0);
79
			if (!$this->memcache->cas($path, 0, 'exclusive')) {
80
				throw new LockedException($path, null, $this->getExistingLockForException($path));
81
			}
82
		}
83
		$this->setTTL($path);
84
		$this->markAcquire($path, $type);
85
	}
86
87
	/**
88
	 * @param string $path
@@ 121-134 (lines=14) @@
118
	 * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE
119
	 * @throws \OCP\Lock\LockedException
120
	 */
121
	public function changeLock(string $path, int $targetType) {
122
		if ($targetType === self::LOCK_SHARED) {
123
			if (!$this->memcache->cas($path, 'exclusive', 1)) {
124
				throw new LockedException($path, null, $this->getExistingLockForException($path));
125
			}
126
		} else if ($targetType === self::LOCK_EXCLUSIVE) {
127
			// we can only change a shared lock to an exclusive if there's only a single owner of the shared lock
128
			if (!$this->memcache->cas($path, 1, 'exclusive')) {
129
				throw new LockedException($path, null, $this->getExistingLockForException($path));
130
			}
131
		}
132
		$this->setTTL($path);
133
		$this->markChange($path, $targetType);
134
	}
135
136
	private function getExistingLockForException($path) {
137
		$existing = $this->memcache->get($path);