Esempio n. 1
0
 /**
  * Libère définitivement de l'espace disque
  */
 public function free()
 {
     $mountPaths = Mount::getMountPaths();
     $paths = $this->in->getArgument('paths');
     if ($this->in->getOption("all-mountpoints")) {
         // Tous les points de montage.
         $paths = array_keys(Mount::getMountPaths());
     }
     if (count($paths) === 0) {
         throw new Exception("Aucun point de montage spécifié.");
     }
     foreach ($paths as $path) {
         $mountPath = Mount::getMountPath($path);
         // On détermine combien d'espace est demandé.
         $toFree = null;
         $m = null;
         if (preg_match('~^(\\d+)%$~', $this->in->getOption('free'), $m)) {
             $used = $mountPaths[$mountPath]['used'];
             $total = $mountPaths[$mountPath]['total'];
             $toFree = Utils::bcmax('0', bcsub($used, bcdiv(bcmul($total, $m[1]), '100')));
         } elseif (preg_match('~^(\\d+)([KMGT]?)$~', $this->in->getOption('free'), $m)) {
             $multipl = array('K' => '1024', 'M' => bcpow('1024', '2'), 'G' => bcpow('1024', '3'), 'T' => bcpow('1024', '4'));
             $toFree = $m[1];
             if (!empty($m[2])) {
                 $toFree = bcmul($toFree, $multipl[$m[2]]);
             }
         } else {
             throw new Exception("Impossible de déterminer l'espace à récupérer. : " . $this->in->getOption('free'));
         }
         if (Utils::bcmax('0', $toFree) === '0') {
             // Rien à libérer sur ce montage.
             continue;
         }
         Logger::log(Utils::humanFilesize($toFree) . " à libérer sur " . $mountPath);
         // On commence par le dossier toDelete dans le dossier trashman du montage.
         $trashmanFolder = Mount::getTrashmanFolderPath($mountPath);
         $trashmanToDeleteFolder = $trashmanFolder . "/toDelete";
         $toFree = $this->doDelete($trashmanToDeleteFolder, $toFree);
         while (Utils::bcmax('0', $toFree) !== '0') {
             $path = Database::getNextPathToDelete($mountPath);
             if ($path === null) {
                 // Terminé, mais on n'a pas pu récupérer assez de place.
                 Logger::error("Impossible de récupérer assez de place sur \"" . $mountPath . "\" (" . Utils::humanFilesize($toFree) . " manquants).");
                 break;
             }
             $toFree = $this->doDelete($path, $toFree);
         }
     }
 }