Commit 2c7f2cb6c59e9e5546d9ad7f91cd9f199466072d

Authored by Benjamin Renard
1 parent 8edd6346

Remove old log files when user WS is full (#6245)

Showing 2 changed files with 23 additions and 6 deletions   Show diff stats
php/classes/AmdaAction.php
... ... @@ -892,8 +892,12 @@ class AmdaAction
892 892 }
893 893 else {
894 894 // check disk space
895   - if ($dd->getWsSize() > DISK_QUOTA)
896   - return array('success' => false, 'message' => 'Please clean up your workspace.<br/>No more space is available');
  895 + if ($dd->getWsSize() > DISK_QUOTA) {
  896 + //Try to delete log files - cf. #6245
  897 + if ($dd->getWsSize(TRUE) > DISK_QUOTA) {
  898 + return array('success' => false, 'message' => 'Please clean up your workspace.<br/>No more space is available');
  899 + }
  900 + }
897 901 }
898 902  
899 903 $this->user = $dd->user;
... ...
php/classes/UserMgr.php
... ... @@ -661,28 +661,41 @@ class UserMgr
661 661 return $xml->save($file);
662 662 }
663 663  
664   - public function dirSize($dir)
  664 + public function dirSize($dir, $files_to_delete = array())
665 665 {
666 666 $handle = opendir($dir);
667 667  
668 668 $mas = 0;
669 669 while ($file = readdir($handle)) {
670 670 if ($file != '..' && $file != '.' && !is_dir($dir.'/'.$file)) {
  671 + if (in_array($file, $files_to_delete)) {
  672 + unlink($dir.'/'.$file);
  673 + continue;
  674 + }
671 675 $mas += filesize($dir.'/'.$file);
672 676 }
673 677 else if (is_dir($dir.'/'.$file) && $file != '..' && $file != '.') {
674   - $mas += $this->dirSize($dir.'/'.$file);
  678 + $mas += $this->dirSize($dir.'/'.$file, $files_to_delete);
675 679 }
676 680 }
677 681 return $mas;
678 682 }
679 683  
680   - public function getWsSize()
  684 + public function getWsSize($delete_log_files = FALSE)
681 685 {
682 686 $dirsToCheck = array(USERDATADIR, USERTTDIR, USERWORKINGDIR);
683 687 $wsSize = 0;
  688 + if ($delete_log_files) {
  689 + $files_to_delete = array(
  690 + 'example.log',
  691 + 'cmd_output',
  692 + );
  693 + }
  694 + else {
  695 + $files_to_delete = array();
  696 + }
684 697 foreach ($dirsToCheck as $dir)
685   - if (is_dir($dir)) $wsSize += $this->dirSize($dir);
  698 + if (is_dir($dir)) $wsSize += $this->dirSize($dir, $files_to_delete);
686 699  
687 700 return $wsSize;
688 701 }
... ...