Example #1
0
function rtOpFiles($files, $src, $dst, $op, $dbg = false)
{
    // Check if source and destination directories are valid
    if (!is_array($files) || $src == '' || $dst == '') {
        if ($dbg) {
            rtDbg(__FUNCTION__, "invalid params");
        }
        return false;
    }
    // Check if source directory exists
    if (!is_dir($src)) {
        if ($dbg) {
            rtDbg(__FUNCTION__, "src is not a directory");
        }
        if ($dbg) {
            rtDbg(__FUNCTION__, "( " . $src . " )");
        }
        return false;
    } else {
        $src = rtAddTailSlash($src);
    }
    // Check if destination directory exists or can be created
    if (!rtMkDir(dirname($dst), 0777)) {
        if ($dbg) {
            rtDbg(__FUNCTION__, "can't create " . dirname($dst));
        }
        return false;
    } else {
        $dst = rtAddTailSlash($dst);
    }
    // Check if source and destination directories are the same
    if (realpath($src) == realpath($dst)) {
        if ($dbg) {
            rtDbg(__FUNCTION__, "source is equal to destination");
        }
        if ($dbg) {
            rtDbg(__FUNCTION__, "( " . realpath($src) . " )");
        }
        return false;
    }
    foreach ($files as $file) {
        $source = $src . $file;
        $dest = $dst . $file;
        if (!rtMkDir(dirname($dest), 0777)) {
            if ($dbg) {
                rtDbg(__FUNCTION__, "can't create " . dirname($dest));
            }
            return false;
        }
        if (rtIsFile($dest)) {
            unlink($dest);
        }
        switch ($op) {
            case "HardLink":
                if (link($source, $dest)) {
                    break;
                }
            case "Copy":
                if (!copy($source, $dest)) {
                    return false;
                }
                break;
            case "SoftLink":
                if (!symlink($source, $dest)) {
                    return false;
                }
                break;
            default:
                if (!rtMoveFile($source, $dest, $dbg)) {
                    return false;
                }
                break;
        }
    }
    if ($dbg) {
        rtDbg(__FUNCTION__, "finished");
    }
    return true;
}
Example #2
0
 // 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;
     }
     if ($is_ok && !rtMkDir($dest_path, 0777)) {
         Debug("can't create " . $dest_path);
         $is_ok = false;
     }
     if ($is_ok) {
         //			$hash = rtAddTorrent(
         //				$torrent_file,			// path to .torrent file
         //				$auto_start,			// start it or not
         //				$dest_path,			// directory for torrent's data
         //				null,				// label is emply
         //				$autodebug_enabled
         //			);
         $hash = rTorrent::sendTorrent($torrent_file, $auto_start, true, $dest_path, null, false, false);
         if ($hash === false) {
             Debug("rtAddTorrent() fail");
             $is_ok = false;
Example #3
0
    if ($datadir_debug_enabled) {
        rtDbg("SetDir", $str);
    }
}
Debug("");
Debug("--- begin ---");
$is_ok = true;
if (count($argv) < 6) {
    Debug("called without arguments (at least 5 params wanted)");
    $is_ok = false;
} else {
    $hash = trim($argv[1]);
    $datadir = trim($argv[2]);
    $move_addpath = trim($argv[3]);
    $move_datafiles = trim($argv[4]);
    $move_fastresume = trim($argv[5]);
}
if ($is_ok && $hash && strlen($datadir) > 0) {
    Debug("hash        : " . $hash);
    Debug("data dir    : " . $datadir);
    Debug("add path    : " . $move_addpath);
    Debug("move files  : " . $move_datafiles);
    Debug("fast resume : " . $move_fastresume);
    if (!rtMkDir($datadir, 0777)) {
        Debug("can't create " . $datadir);
    } elseif (!rtSetDataDir($hash, $datadir, $move_addpath == '1', $move_datafiles == '1', $move_fastresume == '1', $datadir_debug_enabled)) {
        Debug("rtSetDataDir() fail!");
    }
}
Debug("--- end ---");
rtSemUnlock($DataDir_Sem);