Merge pull request #7014 from nextcloud/rename-locks

Unlock files even if an exception occurs while renaming
This commit is contained in:
Morris Jobke 2017-11-09 09:47:36 +01:00 committed by GitHub
commit 5d8421135e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 89 additions and 86 deletions

View File

@ -755,10 +755,6 @@ class View {
$this->lockFile($path1, ILockingProvider::LOCK_SHARED, true);
try {
$this->lockFile($path2, ILockingProvider::LOCK_SHARED, true);
} catch (LockedException $e) {
$this->unlockFile($path1, ILockingProvider::LOCK_SHARED);
throw $e;
}
$run = true;
if ($this->shouldEmitHooks($path1) && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2))) {
@ -786,6 +782,7 @@ class View {
$internalPath2 = $mount2->getInternalPath($absolutePath2);
$this->changeLock($path1, ILockingProvider::LOCK_EXCLUSIVE, true);
try {
$this->changeLock($path2, ILockingProvider::LOCK_EXCLUSIVE, true);
if ($internalPath1 === '') {
@ -817,16 +814,18 @@ class View {
if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
// if it was a rename from a part file to a regular file it was a write and not a rename operation
$this->writeUpdate($storage2, $internalPath2);
} else if ($result) {
if ($internalPath1 !== '') { // don't do a cache update for moved mounts
$this->renameUpdate($storage1, $storage2, $internalPath1, $internalPath2);
}
}
} catch(\Exception $e) {
throw $e;
} finally {
$this->changeLock($path1, ILockingProvider::LOCK_SHARED, true);
$this->changeLock($path2, ILockingProvider::LOCK_SHARED, true);
}
if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
if ($this->shouldEmitHooks()) {
@ -845,9 +844,13 @@ class View {
}
}
}
} catch(\Exception $e) {
throw $e;
} finally {
$this->unlockFile($path1, ILockingProvider::LOCK_SHARED, true);
$this->unlockFile($path2, ILockingProvider::LOCK_SHARED, true);
}
}
return $result;
}