Merge pull request #57573 from nextcloud/fix/fix-beforezipcreatedlistener

fix(files_sharing): Fix BeforeZipCreatedListener path handling
This commit is contained in:
Côme Chilliet 2026-01-20 16:08:05 +01:00 committed by GitHub
commit a467589328
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 6 deletions

View file

@ -32,12 +32,17 @@ class BeforeZipCreatedListener implements IEventListener {
return;
}
/** @psalm-suppress DeprecatedMethod should be migrated to getFolder but for now it would just duplicate code */
$dir = $event->getDirectory();
$files = $event->getFiles();
$pathsToCheck = [];
foreach ($files as $file) {
$pathsToCheck[] = $dir . '/' . $file;
if (empty($files)) {
$pathsToCheck = [$dir];
} else {
$pathsToCheck = [];
foreach ($files as $file) {
$pathsToCheck[] = $dir . '/' . $file;
}
}
// Check only for user/group shares. Don't restrict e.g. share links

View file

@ -24,7 +24,7 @@ class ViewOnly {
}
/**
* @param string[] $pathsToCheck
* @param string[] $pathsToCheck paths to check, relative to the user folder
* @return bool
*/
public function check(array $pathsToCheck): bool {

View file

@ -21,12 +21,13 @@ use OCP\Files\Folder;
* @since 25.0.0
*/
class BeforeZipCreatedEvent extends Event {
private string $directory;
private string $directory = '';
private bool $successful = true;
private ?string $errorMessage = null;
private ?Folder $folder = null;
/**
* @param string|Folder $directory Folder instance, or (deprecated) string path relative to user folder
* @param list<string> $files
* @since 25.0.0
* @since 31.0.0 support `OCP\Files\Folder` as `$directory` parameter - passing a string is deprecated now
@ -37,7 +38,6 @@ class BeforeZipCreatedEvent extends Event {
) {
parent::__construct();
if ($directory instanceof Folder) {
$this->directory = $directory->getPath();
$this->folder = $directory;
} else {
$this->directory = $directory;
@ -53,8 +53,13 @@ class BeforeZipCreatedEvent extends Event {
/**
* @since 25.0.0
* @deprecated 33.0.0 Use getFolder instead and use node API
* @return string returns folder path relative to user folder
*/
public function getDirectory(): string {
if ($this->folder instanceof Folder) {
return preg_replace('|^/[^/]+/files/|', '/', $this->folder->getPath());
}
return $this->directory;
}