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,8 +892,12 @@ class AmdaAction
892 } 892 }
893 else { 893 else {
894 // check disk space 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 $this->user = $dd->user; 903 $this->user = $dd->user;
php/classes/UserMgr.php
@@ -661,28 +661,41 @@ class UserMgr @@ -661,28 +661,41 @@ class UserMgr
661 return $xml->save($file); 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 $handle = opendir($dir); 666 $handle = opendir($dir);
667 667
668 $mas = 0; 668 $mas = 0;
669 while ($file = readdir($handle)) { 669 while ($file = readdir($handle)) {
670 if ($file != '..' && $file != '.' && !is_dir($dir.'/'.$file)) { 670 if ($file != '..' && $file != '.' && !is_dir($dir.'/'.$file)) {
  671 + if (in_array($file, $files_to_delete)) {
  672 + unlink($dir.'/'.$file);
  673 + continue;
  674 + }
671 $mas += filesize($dir.'/'.$file); 675 $mas += filesize($dir.'/'.$file);
672 } 676 }
673 else if (is_dir($dir.'/'.$file) && $file != '..' && $file != '.') { 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 return $mas; 681 return $mas;
678 } 682 }
679 683
680 - public function getWsSize() 684 + public function getWsSize($delete_log_files = FALSE)
681 { 685 {
682 $dirsToCheck = array(USERDATADIR, USERTTDIR, USERWORKINGDIR); 686 $dirsToCheck = array(USERDATADIR, USERTTDIR, USERWORKINGDIR);
683 $wsSize = 0; 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 foreach ($dirsToCheck as $dir) 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 return $wsSize; 700 return $wsSize;
688 } 701 }