summaryrefslogtreecommitdiffstats
path: root/lib/public/Files
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public/Files')
-rw-r--r--lib/public/Files/Cache/ICache.php2
-rw-r--r--lib/public/Files/Cache/ICacheEntry.php10
-rw-r--r--lib/public/Files/Events/BeforeDirectFileDownloadEvent.php84
-rw-r--r--lib/public/Files/Events/BeforeZipCreatedEvent.php91
-rw-r--r--lib/public/Files/SimpleFS/ISimpleFile.php22
-rw-r--r--lib/public/Files/SimpleFS/ISimpleFolder.php17
-rw-r--r--lib/public/Files/SimpleFS/ISimpleRoot.php4
-rw-r--r--lib/public/Files/SimpleFS/InMemoryFile.php24
8 files changed, 210 insertions, 44 deletions
diff --git a/lib/public/Files/Cache/ICache.php b/lib/public/Files/Cache/ICache.php
index e27f4207f1e..37e71f3ac79 100644
--- a/lib/public/Files/Cache/ICache.php
+++ b/lib/public/Files/Cache/ICache.php
@@ -243,7 +243,7 @@ interface ICache {
* use the one with the highest id gives the best result with the background scanner, since that is most
* likely the folder where we stopped scanning previously
*
- * @return string|bool the path of the folder or false when no folder matched
+ * @return string|false the path of the folder or false when no folder matched
* @since 9.0.0
*/
public function getIncomplete();
diff --git a/lib/public/Files/Cache/ICacheEntry.php b/lib/public/Files/Cache/ICacheEntry.php
index 17eecf89ddb..e1e8129394c 100644
--- a/lib/public/Files/Cache/ICacheEntry.php
+++ b/lib/public/Files/Cache/ICacheEntry.php
@@ -162,4 +162,14 @@ interface ICacheEntry extends ArrayAccess {
* @since 18.0.0
*/
public function getUploadTime(): ?int;
+
+ /**
+ * Get the unencrypted size
+ *
+ * This might be different from the result of getSize
+ *
+ * @return int
+ * @since 25.0.0
+ */
+ public function getUnencryptedSize(): int;
}
diff --git a/lib/public/Files/Events/BeforeDirectFileDownloadEvent.php b/lib/public/Files/Events/BeforeDirectFileDownloadEvent.php
new file mode 100644
index 00000000000..a32c95c6408
--- /dev/null
+++ b/lib/public/Files/Events/BeforeDirectFileDownloadEvent.php
@@ -0,0 +1,84 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2022 Carl Schwan <carl@carlschwan.eu>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCP\Files\Events;
+
+use OCP\EventDispatcher\Event;
+
+/**
+ * This event is triggered when a user tries to download a file
+ * directly.
+ *
+ * @since 25.0.0
+ */
+class BeforeDirectFileDownloadEvent extends Event {
+ private string $path;
+ private bool $successful = true;
+ private ?string $errorMessage = null;
+
+ /**
+ * @since 25.0.0
+ */
+ public function __construct(string $path) {
+ parent::__construct();
+ $this->path = $path;
+ }
+
+ /**
+ * @since 25.0.0
+ */
+ public function getPath(): string {
+ return $this->path;
+ }
+
+ /**
+ * @since 25.0.0
+ */
+ public function isSuccessful(): bool {
+ return $this->successful;
+ }
+
+ /**
+ * Set if the event was successful
+ *
+ * @since 25.0.0
+ */
+ public function setSuccessful(bool $successful): void {
+ $this->successful = $successful;
+ }
+
+ /**
+ * Get the error message, if any
+ * @since 25.0.0
+ */
+ public function getErrorMessage(): ?string {
+ return $this->errorMessage;
+ }
+
+ /**
+ * @since 25.0.0
+ */
+ public function setErrorMessage(string $errorMessage): void {
+ $this->errorMessage = $errorMessage;
+ }
+}
diff --git a/lib/public/Files/Events/BeforeZipCreatedEvent.php b/lib/public/Files/Events/BeforeZipCreatedEvent.php
new file mode 100644
index 00000000000..18f41a42899
--- /dev/null
+++ b/lib/public/Files/Events/BeforeZipCreatedEvent.php
@@ -0,0 +1,91 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2022 Carl Schwan <carl@carlschwan.eu>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCP\Files\Events;
+
+use OCP\EventDispatcher\Event;
+
+/**
+ * @since 25.0.0
+ */
+class BeforeZipCreatedEvent extends Event {
+ private string $directory;
+ private array $files;
+ private bool $successful = true;
+ private ?string $errorMessage = null;
+
+ /**
+ * @since 25.0.0
+ */
+ public function __construct(string $directory, array $files) {
+ parent::__construct();
+ $this->directory = $directory;
+ $this->files = $files;
+ }
+
+ /**
+ * @since 25.0.0
+ */
+ public function getDirectory(): string {
+ return $this->directory;
+ }
+
+ /**
+ * @since 25.0.0
+ */
+ public function getFiles(): array {
+ return $this->files;
+ }
+
+ /**
+ * @since 25.0.0
+ */
+ public function isSuccessful(): bool {
+ return $this->successful;
+ }
+
+ /**
+ * Set if the event was successful
+ *
+ * @since 25.0.0
+ */
+ public function setSuccessful(bool $successful): void {
+ $this->successful = $successful;
+ }
+
+ /**
+ * Get the error message, if any
+ * @since 25.0.0
+ */
+ public function getErrorMessage(): ?string {
+ return $this->errorMessage;
+ }
+
+ /**
+ * @since 25.0.0
+ */
+ public function setErrorMessage(string $errorMessage): void {
+ $this->errorMessage = $errorMessage;
+ }
+}
diff --git a/lib/public/Files/SimpleFS/ISimpleFile.php b/lib/public/Files/SimpleFS/ISimpleFile.php
index 8f1921cb7cb..34cd128d449 100644
--- a/lib/public/Files/SimpleFS/ISimpleFile.php
+++ b/lib/public/Files/SimpleFS/ISimpleFile.php
@@ -41,44 +41,39 @@ interface ISimpleFile {
/**
* Get the name
*
- * @return string
* @since 11.0.0
*/
- public function getName();
+ public function getName(): string;
/**
* Get the size in bytes
*
- * @return int
* @since 11.0.0
*/
- public function getSize();
+ public function getSize(): int;
/**
* Get the ETag
*
- * @return string
* @since 11.0.0
*/
- public function getETag();
+ public function getETag(): string;
/**
* Get the last modification time
*
- * @return int
* @since 11.0.0
*/
- public function getMTime();
+ public function getMTime(): int;
/**
* Get the content
*
* @throws NotPermittedException
* @throws NotFoundException
- * @return string
* @since 11.0.0
*/
- public function getContent();
+ public function getContent(): string;
/**
* Overwrite the file
@@ -88,7 +83,7 @@ interface ISimpleFile {
* @throws NotFoundException
* @since 11.0.0
*/
- public function putContent($data);
+ public function putContent($data): void;
/**
* Delete the file
@@ -96,15 +91,14 @@ interface ISimpleFile {
* @throws NotPermittedException
* @since 11.0.0
*/
- public function delete();
+ public function delete(): void;
/**
* Get the MimeType
*
- * @return string
* @since 11.0.0
*/
- public function getMimeType();
+ public function getMimeType(): string;
/**
* @since 24.0.0
diff --git a/lib/public/Files/SimpleFS/ISimpleFolder.php b/lib/public/Files/SimpleFS/ISimpleFolder.php
index 0159c41760b..3c8e6e88ab3 100644
--- a/lib/public/Files/SimpleFS/ISimpleFolder.php
+++ b/lib/public/Files/SimpleFS/ISimpleFolder.php
@@ -38,7 +38,7 @@ interface ISimpleFolder {
* @return ISimpleFile[]
* @since 11.0.0
*/
- public function getDirectoryListing();
+ public function getDirectoryListing(): array;
/**
* Check if a file with $name exists
@@ -47,28 +47,24 @@ interface ISimpleFolder {
* @return bool
* @since 11.0.0
*/
- public function fileExists($name);
+ public function fileExists(string $name): bool;
/**
* Get the file named $name from the folder
*
- * @param string $name
- * @return ISimpleFile
* @throws NotFoundException
* @since 11.0.0
*/
- public function getFile($name);
+ public function getFile(string $name): ISimpleFile;
/**
* Creates a new file with $name in the folder
*
- * @param string $name
* @param string|resource|null $content @since 19.0.0
- * @return ISimpleFile
* @throws NotPermittedException
* @since 11.0.0
*/
- public function newFile($name, $content = null);
+ public function newFile(string $name, $content = null): ISimpleFile;
/**
* Remove the folder and all the files in it
@@ -76,13 +72,12 @@ interface ISimpleFolder {
* @throws NotPermittedException
* @since 11.0.0
*/
- public function delete();
+ public function delete(): void;
/**
* Get the folder name
*
- * @return string
* @since 11.0.0
*/
- public function getName();
+ public function getName(): string;
}
diff --git a/lib/public/Files/SimpleFS/ISimpleRoot.php b/lib/public/Files/SimpleFS/ISimpleRoot.php
index fd590b66b31..31c3efe76dd 100644
--- a/lib/public/Files/SimpleFS/ISimpleRoot.php
+++ b/lib/public/Files/SimpleFS/ISimpleRoot.php
@@ -35,8 +35,6 @@ interface ISimpleRoot {
/**
* Get the folder with name $name
*
- * @param string $name
- * @return ISimpleFolder
* @throws NotFoundException
* @throws \RuntimeException
* @since 11.0.0
@@ -56,8 +54,6 @@ interface ISimpleRoot {
/**
* Create a new folder named $name
*
- * @param string $name
- * @return ISimpleFolder
* @throws NotPermittedException
* @throws \RuntimeException
* @since 11.0.0
diff --git a/lib/public/Files/SimpleFS/InMemoryFile.php b/lib/public/Files/SimpleFS/InMemoryFile.php
index 590cb43e1d6..393449d4f1f 100644
--- a/lib/public/Files/SimpleFS/InMemoryFile.php
+++ b/lib/public/Files/SimpleFS/InMemoryFile.php
@@ -36,17 +36,13 @@ use OCP\Files\NotPermittedException;
class InMemoryFile implements ISimpleFile {
/**
* Holds the file name.
- *
- * @var string
*/
- private $name;
+ private string $name;
/**
* Holds the file contents.
- *
- * @var string
*/
- private $contents;
+ private string $contents;
/**
* InMemoryFile constructor.
@@ -64,7 +60,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function getName() {
+ public function getName(): string {
return $this->name;
}
@@ -72,7 +68,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function getSize() {
+ public function getSize(): int {
return strlen($this->contents);
}
@@ -80,7 +76,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function getETag() {
+ public function getETag(): string {
return '';
}
@@ -88,7 +84,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function getMTime() {
+ public function getMTime(): int {
return time();
}
@@ -96,7 +92,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function getContent() {
+ public function getContent(): string {
return $this->contents;
}
@@ -104,7 +100,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function putContent($data) {
+ public function putContent($data): void {
$this->contents = $data;
}
@@ -113,7 +109,7 @@ class InMemoryFile implements ISimpleFile {
*
* @since 16.0.0
*/
- public function delete() {
+ public function delete(): void {
// unimplemented for in memory files
}
@@ -121,7 +117,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function getMimeType() {
+ public function getMimeType(): string {
$fileInfo = new \finfo(FILEINFO_MIME_TYPE);
return $fileInfo->buffer($this->contents);
}