quota.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2011 Robin Appelman icewind1991@gmail.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * user quota managment
  24. */
  25. class OC_FileProxy_Quota extends OC_FileProxy{
  26. private $userQuota=-1;
  27. /**
  28. * get the quota for the current user
  29. * @return int
  30. */
  31. private function getQuota(){
  32. if($this->userQuota!=-1){
  33. return $this->userQuota;
  34. }
  35. $userQuota=OC_Preferences::getValue(OC_User::getUser(),'files','quota','default');
  36. if($userQuota=='default'){
  37. $userQuota=OC_AppConfig::getValue('files','default_quota','none');
  38. }
  39. if($userQuota=='none'){
  40. $this->userQuota=0;
  41. }else{
  42. $this->userQuota=OC_Helper::computerFileSize($userQuota);
  43. }
  44. return $this->userQuota;
  45. }
  46. /**
  47. * get the free space in the users home folder
  48. * @return int
  49. */
  50. private function getFreeSpace(){
  51. $rootInfo=OC_FileCache::get('');
  52. $usedSpace=$rootInfo['size'];
  53. $totalSpace=$this->getQuota();
  54. if($totalSpace==0){
  55. return 0;
  56. }
  57. return $totalSpace-$usedSpace;
  58. }
  59. public function postFree_space($path,$space){
  60. $free=$this->getFreeSpace();
  61. if($free==0){
  62. return $space;
  63. }
  64. return min($free,$space);
  65. }
  66. public function preFile_put_contents($path,$data){
  67. if (is_resource($data)) {
  68. $data = '';//TODO: find a way to get the length of the stream without emptying it
  69. }
  70. return (strlen($data)<$this->getFreeSpace() or $this->getFreeSpace()==0);
  71. }
  72. public function preCopy($path1,$path2){
  73. return (OC_Filesystem::filesize($path1)<$this->getFreeSpace() or $this->getFreeSpace()==0);
  74. }
  75. public function preFromTmpFile($tmpfile,$path){
  76. return (filesize($tmpfile)<$this->getFreeSpace() or $this->getFreeSpace()==0);
  77. }
  78. public function preFromUploadedFile($tmpfile,$path){
  79. return (filesize($tmpfile)<$this->getFreeSpace() or $this->getFreeSpace()==0);
  80. }
  81. }