From f3513f3fe4dc52143798e60deb4367f2c829029f Mon Sep 17 00:00:00 2001 From: Tigran Mkrtchyan Date: Mon, 7 Dec 2020 17:57:07 +0100 Subject: [PATCH 1/2] files: Local#writeStream should use it's own file_put_contents The OC\Files\Storage\Local#writeStream use system provided file_put_contents. However, it overrides file_put_contents, thus expects that the default behaviour can be different. Use Local#file_put_contents in writeStream to benefit from class specific functionality. Signed-off-by: Tigran Mkrtchyan --- lib/private/Files/Storage/Local.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index f0a81f4893..ed80a4718d 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -556,7 +556,7 @@ class Local extends \OC\Files\Storage\Common { } public function writeStream(string $path, $stream, int $size = null): int { - $result = file_put_contents($this->getSourcePath($path), $stream); + $result = $this->file_put_contents($path, $stream); if ($result === false) { throw new GenericFileException("Failed write steam to $path"); } else { From 4f2dc18f58737894f52f585203402307c64b595e Mon Sep 17 00:00:00 2001 From: Tigran Mkrtchyan Date: Mon, 21 Dec 2020 13:43:51 +0100 Subject: [PATCH 2/2] storage: update IStorage#file_put_contents docs to match usage The current phpdoc of IStorage#file_put_contents doesnt corresponds to it's actual usage in code, e.g. Signed-off-by: Tigran Mkrtchyan --- lib/private/Files/ObjectStore/ObjectStoreStorage.php | 4 ++-- lib/private/Files/Storage/DAV.php | 4 ++-- lib/private/Files/Storage/Flysystem.php | 6 +++++- lib/private/Files/Storage/Wrapper/Encoding.php | 4 ++-- lib/private/Files/Storage/Wrapper/Encryption.php | 4 ++-- lib/private/Files/Storage/Wrapper/Jail.php | 4 ++-- lib/private/Files/Storage/Wrapper/Quota.php | 4 ++-- lib/private/Files/Storage/Wrapper/Wrapper.php | 4 ++-- lib/public/Files/Storage.php | 4 ++-- lib/public/Files/Storage/IStorage.php | 4 ++-- 10 files changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index e855c16661..9815fe6a24 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -439,9 +439,9 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common { public function file_put_contents($path, $data) { $handle = $this->fopen($path, 'w+'); - fwrite($handle, $data); + $result = fwrite($handle, $data); fclose($handle); - return true; + return $result; } public function writeStream(string $path, $stream, int $size = null): int { diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 974feee899..a2355f553c 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -486,8 +486,8 @@ class DAV extends Common { /** * @param string $path - * @param string $data - * @return int + * @param mixed $data + * @return int|false */ public function file_put_contents($path, $data) { $path = $this->cleanPath($path); diff --git a/lib/private/Files/Storage/Flysystem.php b/lib/private/Files/Storage/Flysystem.php index a7747823ac..9b26516bef 100644 --- a/lib/private/Files/Storage/Flysystem.php +++ b/lib/private/Files/Storage/Flysystem.php @@ -73,7 +73,11 @@ abstract class Flysystem extends Common { * {@inheritdoc} */ public function file_put_contents($path, $data) { - return $this->flysystem->put($this->buildPath($path), $data); + $result = $this->flysystem->put($this->buildPath($path), $data); + if ($result === true) { + return strlen($data); + } + return $result; } /** diff --git a/lib/private/Files/Storage/Wrapper/Encoding.php b/lib/private/Files/Storage/Wrapper/Encoding.php index a2ef1780d6..875bdb2991 100644 --- a/lib/private/Files/Storage/Wrapper/Encoding.php +++ b/lib/private/Files/Storage/Wrapper/Encoding.php @@ -309,8 +309,8 @@ class Encoding extends Wrapper { * see http://php.net/manual/en/function.file_put_contents.php * * @param string $path - * @param string $data - * @return bool + * @param mixed $data + * @return int|false */ public function file_put_contents($path, $data) { return $this->storage->file_put_contents($this->findPathToUse($path), $data); diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 3a97764fbb..38b252f8aa 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -234,8 +234,8 @@ class Encryption extends Wrapper { * see http://php.net/manual/en/function.file_put_contents.php * * @param string $path - * @param string $data - * @return bool + * @param mixed $data + * @return int|false */ public function file_put_contents($path, $data) { // file put content will always be translated to a stream write diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 449a238096..2396c07a0f 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -259,8 +259,8 @@ class Jail extends Wrapper { * see http://php.net/manual/en/function.file_put_contents.php * * @param string $path - * @param string $data - * @return bool + * @param mixed $data + * @return int|false */ public function file_put_contents($path, $data) { return $this->getWrapperStorage()->file_put_contents($this->getUnjailedPath($path), $data); diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index 406f0fd464..41fae7cafc 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -121,8 +121,8 @@ class Quota extends Wrapper { * see http://php.net/manual/en/function.file_put_contents.php * * @param string $path - * @param string $data - * @return bool + * @param mixed $data + * @return int|false */ public function file_put_contents($path, $data) { $free = $this->free_space($path); diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index 4584bebe07..313f73f589 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -250,8 +250,8 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea * see http://php.net/manual/en/function.file_put_contents.php * * @param string $path - * @param string $data - * @return bool + * @param mixed $data + * @return int|false */ public function file_put_contents($path, $data) { return $this->getWrapperStorage()->file_put_contents($path, $data); diff --git a/lib/public/Files/Storage.php b/lib/public/Files/Storage.php index d642512641..2d89ce9f28 100644 --- a/lib/public/Files/Storage.php +++ b/lib/public/Files/Storage.php @@ -230,8 +230,8 @@ interface Storage extends IStorage { * see http://php.net/manual/en/function.file_put_contents.php * * @param string $path - * @param string $data - * @return bool + * @param mixed $data + * @return int|false * @since 6.0.0 */ public function file_put_contents($path, $data); diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php index f5073d1ad7..9cd5553b8b 100644 --- a/lib/public/Files/Storage/IStorage.php +++ b/lib/public/Files/Storage/IStorage.php @@ -226,8 +226,8 @@ interface IStorage { * see http://php.net/manual/en/function.file_put_contents.php * * @param string $path - * @param string $data - * @return bool + * @param mixed $data + * @return int|false * @since 9.0.0 */ public function file_put_contents($path, $data);