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 5672f14fd1
commit c7482402b8
1 changed files with 89 additions and 86 deletions

View File

@ -737,10 +737,6 @@ class View {
$this->lockFile($path1, ILockingProvider::LOCK_SHARED, true); $this->lockFile($path1, ILockingProvider::LOCK_SHARED, true);
try { try {
$this->lockFile($path2, ILockingProvider::LOCK_SHARED, true); $this->lockFile($path2, ILockingProvider::LOCK_SHARED, true);
} catch (LockedException $e) {
$this->unlockFile($path1, ILockingProvider::LOCK_SHARED);
throw $e;
}
$run = true; $run = true;
if ($this->shouldEmitHooks($path1) && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2))) { if ($this->shouldEmitHooks($path1) && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2))) {
@ -768,6 +764,7 @@ class View {
$internalPath2 = $mount2->getInternalPath($absolutePath2); $internalPath2 = $mount2->getInternalPath($absolutePath2);
$this->changeLock($path1, ILockingProvider::LOCK_EXCLUSIVE, true); $this->changeLock($path1, ILockingProvider::LOCK_EXCLUSIVE, true);
try {
$this->changeLock($path2, ILockingProvider::LOCK_EXCLUSIVE, true); $this->changeLock($path2, ILockingProvider::LOCK_EXCLUSIVE, true);
if ($internalPath1 === '') { if ($internalPath1 === '') {
@ -799,16 +796,18 @@ class View {
if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) { 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 // 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); $this->writeUpdate($storage2, $internalPath2);
} else if ($result) { } else if ($result) {
if ($internalPath1 !== '') { // don't do a cache update for moved mounts if ($internalPath1 !== '') { // don't do a cache update for moved mounts
$this->renameUpdate($storage1, $storage2, $internalPath1, $internalPath2); $this->renameUpdate($storage1, $storage2, $internalPath1, $internalPath2);
} }
} }
} catch(\Exception $e) {
throw $e;
} finally {
$this->changeLock($path1, ILockingProvider::LOCK_SHARED, true); $this->changeLock($path1, ILockingProvider::LOCK_SHARED, true);
$this->changeLock($path2, ILockingProvider::LOCK_SHARED, true); $this->changeLock($path2, ILockingProvider::LOCK_SHARED, true);
}
if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) { if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
if ($this->shouldEmitHooks()) { if ($this->shouldEmitHooks()) {
@ -827,9 +826,13 @@ class View {
} }
} }
} }
} catch(\Exception $e) {
throw $e;
} finally {
$this->unlockFile($path1, ILockingProvider::LOCK_SHARED, true); $this->unlockFile($path1, ILockingProvider::LOCK_SHARED, true);
$this->unlockFile($path2, ILockingProvider::LOCK_SHARED, true); $this->unlockFile($path2, ILockingProvider::LOCK_SHARED, true);
} }
}
return $result; return $result;
} }