Throw an exception if file_put_contents fails
* This will help with AppData hardening etc * Introduced a GenericFileException for if nothing else is appropiate - Maybe the other File exceptions should base on this? Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
709589f2db
commit
53447ae2b2
|
@ -26,6 +26,7 @@
|
|||
|
||||
namespace OC\Files\Node;
|
||||
|
||||
use OCP\Files\GenericFileException;
|
||||
use OCP\Files\NotPermittedException;
|
||||
|
||||
class File extends Node implements \OCP\Files\File {
|
||||
|
@ -57,11 +58,14 @@ class File extends Node implements \OCP\Files\File {
|
|||
/**
|
||||
* @param string $data
|
||||
* @throws \OCP\Files\NotPermittedException
|
||||
* @throws \OCP\Files\GenericFileException
|
||||
*/
|
||||
public function putContent($data) {
|
||||
if ($this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE)) {
|
||||
$this->sendHooks(array('preWrite'));
|
||||
$this->view->file_put_contents($this->path, $data);
|
||||
if ($this->view->file_put_contents($this->path, $data) === false) {
|
||||
throw new GenericFileException('file_put_contents failed');
|
||||
}
|
||||
$this->fileInfo = null;
|
||||
$this->sendHooks(array('postWrite'));
|
||||
} else {
|
||||
|
|
|
@ -53,7 +53,7 @@ interface File extends Node {
|
|||
*
|
||||
* @param string $data
|
||||
* @throws \OCP\Files\NotPermittedException
|
||||
* @return void
|
||||
* @throws \OCP\Files\GenericFileException
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public function putContent($data);
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* Class GenericFileException
|
||||
*
|
||||
* @package OCP\Files
|
||||
* @since 14.0.0
|
||||
*/
|
||||
class GenericFileException extends \Exception {
|
||||
|
||||
}
|
Loading…
Reference in New Issue