diff options
author | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2016-12-13 20:45:48 +0300 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-12-16 17:50:58 +0100 |
commit | 876754a5a55e076a56e98e4ed3fc7e82589e2afa (patch) | |
tree | 1a7319a5bf8f79fc83fc1ab81b54511e5d55d826 /lib/private/IntegrityCheck/Helpers | |
parent | b0c1460a1d7d71cb752637b42154cd515c2b489e (diff) | |
download | nextcloud-server-876754a5a55e076a56e98e4ed3fc7e82589e2afa.tar.gz nextcloud-server-876754a5a55e076a56e98e4ed3fc7e82589e2afa.zip |
Check return value for file_put_contents. Add return value to the commands
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'lib/private/IntegrityCheck/Helpers')
-rw-r--r-- | lib/private/IntegrityCheck/Helpers/FileAccessHelper.php | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/private/IntegrityCheck/Helpers/FileAccessHelper.php b/lib/private/IntegrityCheck/Helpers/FileAccessHelper.php index 9e2b76ce11a..c3193457890 100644 --- a/lib/private/IntegrityCheck/Helpers/FileAccessHelper.php +++ b/lib/private/IntegrityCheck/Helpers/FileAccessHelper.php @@ -53,10 +53,33 @@ class FileAccessHelper { * Wrapper around file_put_contents($filename, $data) * * @param string $filename - * @param $data - * @return int|false + * @param string $data + * @return int + * @throws \Exception */ public function file_put_contents($filename, $data) { - return file_put_contents($filename, $data); + $bytesWritten = file_put_contents($filename, $data); + if ($bytesWritten === false || $bytesWritten !== strlen($data)){ + throw new \Exception('Failed to write into ' . $filename); + } + return $bytesWritten; + } + + /** + * @param string $path + * @return bool + */ + public function is_writeable($path){ + return is_writeable($path); + } + + /** + * @param string $path + * @throws \Exception + */ + public function assertDirectoryExists($path){ + if (!is_dir($path)) { + throw new \Exception('Directory ' . $path . ' does not exist.'); + } } } |