Unlock files even if an exception occurs

Signed-off-by: Kristof Hamann <korelstar@users.noreply.github.com>
This commit is contained in:
korelstar 2017-10-30 18:12:37 +01:00 committed by Kristof Hamann
parent 097e8a4994
commit f907cdc09d
1 changed files with 89 additions and 86 deletions

View File

@ -766,10 +766,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))) {
@ -797,6 +793,7 @@ class View {
$internalPath2 = $mount2->getInternalPath($absolutePath2);
$this->changeLock($path1, ILockingProvider::LOCK_EXCLUSIVE, true);
try {
$this->changeLock($path2, ILockingProvider::LOCK_EXCLUSIVE, true);
if ($internalPath1 === '') {
@ -828,16 +825,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()) {
@ -856,9 +855,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;
}