Skip to content

Commit

Permalink
Merge pull request #50763 from nextcloud/backport/50498/stable31
Browse files Browse the repository at this point in the history
[stable31] Don't rethrow a type error
  • Loading branch information
AndyScherzinger authored Feb 11, 2025
2 parents 205b597 + 856b87c commit 2a76114
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
4 changes: 2 additions & 2 deletions apps/dav/lib/Connector/Sabre/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ public function createFile($name, $data = null) {

// only allow 1 process to upload a file at once but still allow reading the file while writing the part file
$node->acquireLock(ILockingProvider::LOCK_SHARED);
$this->fileView->lockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
$this->fileView->lockFile($this->path . '/' . $name . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);

$result = $node->put($data);

$this->fileView->unlockFile($path . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
$this->fileView->unlockFile($this->path . '/' . $name . '.upload.part', ILockingProvider::LOCK_EXCLUSIVE);
$node->releaseLock(ILockingProvider::LOCK_SHARED);
return $result;
} catch (StorageNotAvailableException $e) {
Expand Down
18 changes: 8 additions & 10 deletions apps/dav/lib/Connector/Sabre/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Sabre\DAV\Exception;
use Sabre\DAV\Version;
use TypeError;

/**
* Class \OCA\DAV\Connector\Sabre\Server
Expand Down Expand Up @@ -47,20 +48,17 @@ public function start() {
$this->httpRequest->setBaseUrl($this->getBaseUri());
$this->invokeMethod($this->httpRequest, $this->httpResponse);
} catch (\Throwable $e) {
if ($e instanceof \TypeError) {
try {
$this->emit('exception', [$e]);
} catch (\Exception) {
}

if ($e instanceof TypeError) {
/*
* The TypeError includes the file path where the error occurred,
* potentially revealing the installation directory.
*
* By re-throwing the exception, we ensure that the
* default exception handler processes it.
*/
throw $e;
}

try {
$this->emit('exception', [$e]);
} catch (\Exception $ignore) {
$e = new TypeError('A type error occurred. For more details, please refer to the logs, which provide additional context about the type error.');
}

$DOM = new \DOMDocument('1.0', 'utf-8');
Expand Down
24 changes: 8 additions & 16 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -2062,9 +2062,9 @@ private function lockPath($path, $type, $lockMountPoint = false) {
);
}
} catch (LockedException $e) {
// rethrow with the a human-readable path
// rethrow with the human-readable path
throw new LockedException(
$this->getPathRelativeToFiles($absolutePath),
$path,
$e,
$e->getExistingLock()
);
Expand Down Expand Up @@ -2102,20 +2102,12 @@ public function changeLock($path, $type, $lockMountPoint = false) {
);
}
} catch (LockedException $e) {
try {
// rethrow with the a human-readable path
throw new LockedException(
$this->getPathRelativeToFiles($absolutePath),
$e,
$e->getExistingLock()
);
} catch (\InvalidArgumentException $ex) {
throw new LockedException(
$absolutePath,
$ex,
$e->getExistingLock()
);
}
// rethrow with the a human-readable path
throw new LockedException(
$path,
$e,
$e->getExistingLock()
);
}

return true;
Expand Down

0 comments on commit 2a76114

Please sign in to comment.