public static function cleanup() { $counter = 0; $tasks = self::obtain(); foreach ($tasks as $id => $task) { $finished_with_error = $task["status"] > 0; $in_progress = !$finished_with_error && $task["pid"] && self::isPIDExists($task["pid"]); if (!$finished_with_error && !$in_progress && $counter >= self::MAX_TASK_COUNT) { rTask::clean(rTask::formatPath($id)); } else { $counter++; } } }
} else { if ($useExternal === false) { $useExternal = "inner"; } } $task = new rTask(array('arg' => call_user_func('getFileName', $path_edit), 'requester' => 'create', 'name' => 'create', 'path_edit' => $_REQUEST['path_edit'], 'trackers' => $_REQUEST['trackers'], 'comment' => $_REQUEST['comment'], 'start_seeding' => $_REQUEST['start_seeding'], 'piece_size' => $_REQUEST['piece_size'], 'private' => $_REQUEST['private'])); $commands = array(); $commands[] = escapeshellarg($rootPath . '/plugins/create/' . $useExternal . '.sh') . " " . $task->id . " " . escapeshellarg(getPHP()) . " " . escapeshellarg($pathToCreatetorrent) . " " . escapeshellarg($path_edit) . " " . $piece_size . " " . escapeshellarg(getUser()) . " " . escapeshellarg(rTask::formatPath($task->id)); $commands[] = '{'; $commands[] = 'chmod a+r "${dir}"/result.torrent'; $commands[] = '}'; $ret = $task->start($commands, 0); break; } else { $error = 'Incorrect directory (' . mb_substr($path_edit, mb_strlen($topDirectory) - 1) . ')'; } } $ret = array("no" => -1, "pid" => 0, "status" => 255, "log" => array(), "errors" => array($error)); break; case "getfile": $dir = rTask::formatPath($_REQUEST['no']); $torrent = new Torrent($dir . "/result.torrent"); if (!$torrent->errors()) { $torrent->send(); } else { header('HTTP/1.0 404 Not Found'); } exit; } } cachedEcho(safe_json_encode($ret), "application/json");
if ($trackersCount > 1) { $torrent->announce_list($announce_list); } } else { $torrent = new Torrent($path_edit, array(), $piece_size, $callback_log, $callback_err); } if (isset($request['comment'])) { $comment = trim($request['comment']); if (strlen($comment)) { $torrent->comment($comment); } } if ($request['private']) { $torrent->is_private(true); } $fname = rTask::formatPath($taskNo) . '/result.torrent'; $torrent->save($fname); if ($request['start_seeding']) { $fname = getUniqueUploadedFilename($torrent->info['name'] . '.torrent'); $path_edit = trim($request['path_edit']); if (is_dir($path_edit)) { $path_edit = addslash($path_edit); } if (rTorrentSettings::get()->correctDirectory($path_edit)) { $path_edit = dirname($path_edit); if ($resumed = rTorrent::fastResume($torrent, $path_edit)) { $torrent = $resumed; } $torrent->save($fname); rTorrent::sendTorrent($torrent, true, true, $path_edit, null, true, isLocalMode()); @chmod($fname, $profileMask & 0666);
public static function cleanup() { $tasks = self::obtain(); foreach ($tasks as $id => $task) { if ($task["status"] < 0 && (!$task["pid"] || !self::isPIDExists($task["pid"]))) { rTask::clean(rTask::formatPath($id)); } } }