Example #1
0
        }
    } else {
        $is_ok = false;
    }
}
// Ask info from rTorrent
if ($is_ok) {
    $directory = rtAddTailSlash(rTorrentSettings::get()->directory);
    Debug("get_directory    : " . $directory);
    if ($directory == '' || $directory == '/') {
        $is_ok = false;
    }
}
// Scan for *.torrent files at $path_to_watch
if ($is_ok) {
    $files = rtScanFiles($path_to_watch, "/.*\\.torrent\$/i");
    // ignore case
    foreach ($files as $file) {
        $torrent_file = $path_to_watch . $file;
        // don't use realpath() here !!!
        $dest_path = rtAddTailSlash(dirname($directory . $file));
        Debug("torrent file     : " . $torrent_file);
        Debug("save data to     : " . $dest_path);
        $is_ok = true;
        // rTorrent store info about all added torrents,
        // so we must change $torrent_file's time to trick rTorrent.
        // ( If we want to add same torrent again )
        if ($is_ok && (!is_writeable($torrent_file) || !touch($torrent_file))) {
            Debug("no access to " . $torrent_file);
            $is_ok = false;
        }
Example #2
0
function rtScanFiles($path, $mask, $subdir = '')
{
    $path = rtAddTailSlash($path);
    if ($subdir != '') {
        $subdir = rtAddTailSlash($subdir);
    }
    $ret = array();
    if (is_dir($path . $subdir)) {
        $handle = opendir($path . $subdir);
        while (false !== ($item = readdir($handle))) {
            if ($item == '.' || $item == '..') {
                continue;
            }
            $path_to_item = $path . $subdir . $item;
            if (is_dir($path_to_item)) {
                $ret = array_merge($ret, rtScanFiles($path, $mask, $subdir . $item));
            } elseif (rtIsFile($path_to_item) && preg_match($mask, $item)) {
                $ret[] = $subdir . $item;
            }
        }
        closedir($handle);
    }
    return $ret;
}