Exemplo n.º 1
0
char *
libtest_sandbox_create (void)
{
  char * path = tr_getcwd ();
  char * sandbox = tr_buildPath (path, "sandbox-XXXXXX", NULL);
  tr_free (path);
  tr_mkdtemp (sandbox);
  return sandbox;
}
Exemplo n.º 2
0
int
main (int argc, char * argv[])
{
  char * out2 = NULL;
  tr_metainfo_builder * b = NULL;

  tr_logSetLevel (TR_LOG_ERROR);

  if (parseCommandLine (argc, (const char**)argv))
    return EXIT_FAILURE;

  if (showVersion)
    {
      fprintf (stderr, MY_NAME" "LONG_VERSION_STRING"\n");
      return EXIT_SUCCESS;
    }

  if (!infile)
    {
      fprintf (stderr, "ERROR: No input file or directory specified.\n");
      tr_getopt_usage (MY_NAME, getUsage (), options);
      fprintf (stderr, "\n");
      return EXIT_FAILURE;
    }

  if (outfile == NULL)
    {
      char * base = tr_basename (infile);
      char * end = tr_strdup_printf ("%s.torrent", base);
      char * cwd = tr_getcwd ();
      outfile = out2 = tr_buildPath (cwd, end, NULL);
      tr_free (cwd);
      tr_free (end);
      tr_free (base);
    }

  if (!trackerCount)
    {
      if (isPrivate)
        {
          fprintf (stderr, "ERROR: no trackers specified for a private torrent\n");
          return EXIT_FAILURE;
        }
        else
        {
          printf ("WARNING: no trackers specified\n");
        }
    }

  printf ("Creating torrent \"%s\" ...", outfile);
  fflush (stdout);

  b = tr_metaInfoBuilderCreate (infile);

  if (piecesize_kib != 0)
    tr_metaInfoBuilderSetPieceSize (b, piecesize_kib * KiB);

  tr_makeMetaInfo (b, outfile, trackers, trackerCount, comment, isPrivate);
  while (!b->isDone)
    {
      tr_wait_msec (500);
      putc ('.', stdout);
      fflush (stdout);
    }

  putc (' ', stdout);
  switch (b->result)
    {
      case TR_MAKEMETA_OK:
        printf ("done!");
        break;

      case TR_MAKEMETA_URL:
        printf ("bad announce URL: \"%s\"", b->errfile);
        break;

      case TR_MAKEMETA_IO_READ:
        printf ("error reading \"%s\": %s", b->errfile, tr_strerror (b->my_errno));
        break;

      case TR_MAKEMETA_IO_WRITE:
        printf ("error writing \"%s\": %s", b->errfile, tr_strerror (b->my_errno));
        break;

      case TR_MAKEMETA_CANCELLED:
        printf ("cancelled");
        break;
    }
  putc ('\n', stdout);

  tr_metaInfoBuilderFree (b);
  tr_free (out2);
  return EXIT_SUCCESS;
}