Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable25] fix: Check before writing if writing without a part file #358

Merged
merged 3 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/StorageWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,17 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
* @throws ForbiddenException
*/
public function writeStream(string $path, $stream, int $size = null): int {
if (!$this->isPartFile($path)) {
$this->checkFileAccess($path);
}

$result = $this->storage->writeStream($path, $stream, $size);
if (!$this->isPartFile($path)) {
return $result;
}

// Required for object storage since part file is not in the storage so we cannot check it before moving it to the storage
// As an alternative we might be able to check on the cache update/insert/delete though the Cache wrapper
$result = $this->storage->writeStream($path, $stream, $size);
try {
$this->checkFileAccess($path);
} catch (\Exception $e) {
Expand All @@ -326,4 +334,9 @@ public function writeStream(string $path, $stream, int $size = null): int {
}
return $result;
}

private function isPartFile($path) {
$extension = pathinfo($path, PATHINFO_EXTENSION);
return ($extension === 'part');
}
}
3 changes: 2 additions & 1 deletion tests/Integration/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"phpunit/phpunit": "^9.5",
"behat/behat": "^3.10",
"guzzlehttp/guzzle": "6.5.8",
"jarnaiz/behat-junit-formatter": "^1.3"
"jarnaiz/behat-junit-formatter": "^1.3",
"sabre/dav": "^4.4"
}
}
Loading