]> source.dussan.org Git - nextcloud-server.git/commitdiff
check quota when trying to download a file via new -> web
authorJörn Friedrich Dreyer <jfd@butonic.de>
Fri, 8 Aug 2014 12:35:33 +0000 (14:35 +0200)
committerJörn Friedrich Dreyer <jfd@butonic.de>
Wed, 13 Aug 2014 08:44:52 +0000 (10:44 +0200)
apps/files/ajax/newfile.php

index 7d6be59beab2b9e29c257fa9a5192b71db7a3000..9cfe51a6218e635e80cadb3ea53f00c803ad528d 100644 (file)
@@ -108,6 +108,29 @@ if($source) {
        $sourceStream=@fopen($source, 'rb', false, $ctx);
        $result = 0;
        if (is_resource($sourceStream)) {
+               $meta = stream_get_meta_data($sourceStream);
+               if (isset($meta['wrapper_data']) && is_array($meta['wrapper_data'])) {
+                       //check stream size
+                       $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
+                       $freeSpace = $storageStats['freeSpace'];
+
+                       foreach($meta['wrapper_data'] as $header) {
+                               list($name, $value) = explode(':', $header);
+                               if ('content-length' === strtolower(trim($name))) {
+                                       $length = (int) trim($value);
+
+                                       if ($length > $freeSpace) {
+                                               $delta = $length - $freeSpace;
+                                               $humanDelta = OCP\Util::humanFileSize($delta);
+
+                                               $eventSource->send('error', array('message' => (string)$l10n->t('The file exceeds your quota by %s', array($humanDelta))));
+                                               $eventSource->close();
+                                               fclose($sourceStream);
+                                               exit();
+                                       }
+                               }
+                       }
+               }
                $result=\OC\Files\Filesystem::file_put_contents($target, $sourceStream);
        }
        if($result) {