Ticket #5879: close_on_complete.diff

File close_on_complete.diff, 2.9 KB (added by duskCoder, 7 years ago)
  • cli.c

     
    7070
    7171static bool showVersion              = false;
    7272static bool verify                   = false;
     73static bool closeOnFinished          = false;
    7374static sig_atomic_t gotsig           = false;
     75static sig_atomic_t closing          = false;
    7476static sig_atomic_t manualUpdate     = false;
    7577
    7678static const char * torrentPath  = NULL;
     
    7981{
    8082  { 'b', "blocklist",            "Enable peer blocklists", "b",  0, NULL },
    8183  { 'B', "no-blocklist",         "Disable peer blocklists", "B",  0, NULL },
     84  { 'c', "close-on-finished",    "Close when the torrent finishes", "c", 0, NULL },
    8285  { 'd', "downlimit",            "Set max download speed in "SPEED_K_STR, "d",  1, "<speed>" },
    8386  { 'D', "no-downlimit",         "Don't limit the download speed", "D",  0, NULL },
    8487  { 910, "encryption-required",  "Encrypt all peer connections", "er", 0, NULL },
     
    221224  return configDir;
    222225}
    223226
     227static void
     228closeOnFinishedCallback (tr_torrent       * torrent UNUSED,
     229                         tr_completeness    completeness,
     230                         bool               wasRunning UNUSED,
     231                         void             * user_data UNUSED)
     232{
     233    if (completeness == TR_SEED)
     234      {
     235        closing = true;
     236      }
     237}
     238
    224239int
    225240main (int argc, char ** argv)
    226241{
     
    328343#ifndef _WIN32
    329344  signal (SIGHUP, sigHandler);
    330345#endif
     346  if (closeOnFinished)
     347    {
     348      tr_torrentSetCompletenessCallback (tor, closeOnFinishedCallback, NULL);
     349    }
     350
    331351  tr_torrentStart (tor);
    332352
    333353  if (verify)
     
    346366
    347367      tr_wait_msec (200);
    348368
    349       if (gotsig)
     369      if (gotsig || closing)
    350370        {
    351371          gotsig = false;
     372          closing = false;
    352373          printf ("\nStopping torrent...\n");
    353374          tr_torrentStop (tor);
    354375        }
     
    408429          case 'B': tr_variantDictAddBool (d, TR_KEY_blocklist_enabled, false);
    409430            break;
    410431
     432          case 'c':
     433            closeOnFinished = true;
     434            break;
     435
    411436          case 'd':
    412437            tr_variantDictAddInt (d, TR_KEY_speed_limit_down, atoi (optarg));
    413438            tr_variantDictAddBool (d, TR_KEY_speed_limit_down_enabled, true);
  • transmission-cli.1

     
    2525.Fl h
    2626.Nm
    2727.Op Fl b | B
     28.Op Fl c
    2829.Op Fl d Ar number | Fl D
    2930.Op Fl er | ep | et
    3031.Op Fl f Ar script
     
    5152New blocklists can be added by copying them into the config-dir's "blocklists" subdirectory.
    5253.It Fl B Fl -no-blocklist
    5354Disble blocklists.
     55.It Fl c, Fl -close-on-finished
     56Close when the torrent finishes.
    5457.It Fl d, -downlimit Ar number
    5558Set the maximum download speed in KB/s
    5659.It Fl D, -no-downlimit