/**
  * Prune the backup files down to keepNFiles. If $keepNFiles = -1 then don't
  * do anything
  *
  * @param <type> $path
  * @param <type> $stemName
  * @param <type> $keepNFiles
  */
 public static function pruneFiles($path, $stemName, $keepNFiles, &$output)
 {
     $outcome = true;
     if ($keepNFiles == -1) {
         $output = 'No files pruned because keepNFiles parameter is -1';
     } else {
         $searchPath = uFs::mp(array($path, $stemName));
         $options = array('sort-by' => 'date', 'sort-order' => 'DESC');
         $fileList = self::getListOfFiles($searchPath, $options, true);
         if (count($fileList) > $keepNFiles) {
             array_splice($fileList, 0, $keepNFiles);
             foreach ($fileList as $fileName) {
                 uFs::unlink($fileName, true);
             }
         }
     }
     return $outcome;
 }
예제 #2
0
 public static function symlink($target, $linkName, $throwException = true)
 {
     if (function_exists('symlink')) {
         if (is_link($linkName)) {
             if (readlink($linkName) != $target) {
                 uFs::unlink($linkName, false);
             }
         }
         if (!self::relativeSymlink($target, $linkName)) {
             if ($throwException) {
                 throw new Exception('symlink(' . $target . ',' . $linkName . ') failed.');
             } else {
                 return false;
             }
         }
     } else {
         if ($throwException) {
             throw new Exception('Function \'symlink\' does not exist.');
         } else {
             return false;
         }
     }
 }
예제 #3
0
 public function __destruct()
 {
     uFs::unlink($this->fullPath);
 }