Changeset 13829
- Timestamp:
- Jan 22, 2013, 12:25:42 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/metainfo.c
r13722 r13829 37 37 { 38 38 size_t i; 39 const size_t name_len = strlen (inf->name); 40 char * ret = tr_strdup_printf ("%s.%16.16s", inf->name, inf->hashString); 39 const char * name = inf->originalName; 40 const size_t name_len = strlen (name); 41 char * ret = tr_strdup_printf ("%s.%16.16s", name, inf->hashString); 41 42 42 43 for (i=0; i<name_len; ++i) … … 406 407 { 407 408 tr_free (inf->name); 409 tr_free (inf->originalName); 408 410 inf->name = tr_strndup (str, len); 411 inf->originalName = tr_strndup (str, len); 409 412 } 410 413 411 414 if (!inf->name) 412 inf->name = tr_strdup (inf->hashString); 415 inf->name = tr_strdup (inf->hashString); 416 if (!inf->originalName) 417 inf->originalName = tr_strdup (inf->hashString); 413 418 } 414 419 else /* not a magnet link and has no info dict... */ … … 440 445 return "name"; 441 446 tr_free (inf->name); 447 tr_free (inf->originalName); 442 448 inf->name = tr_utf8clean (str, len); 449 inf->originalName = tr_strdup (inf->name); 443 450 } 444 451 … … 561 568 tr_free (inf->creator); 562 569 tr_free (inf->torrent); 570 tr_free (inf->originalName); 563 571 tr_free (inf->name); 564 572 -
trunk/libtransmission/rename-test.c
r13812 r13829 155 155 test_single_filename_torrent (void) 156 156 { 157 uint64_t loaded; 157 158 tr_torrent * tor; 158 159 char * tmpstr; … … 208 209 tmpstr = tr_buildPath (tor->downloadDir, "hello-world.txt", NULL); 209 210 check (tr_fileExists (tmpstr, NULL)); 211 check_streq ("hello-world.txt", tr_torrentName(tor)); 210 212 check_int_eq (0, torrentRenameAndWait (tor, "hello-world.txt", "foobar")); 211 213 check (!tr_fileExists (tmpstr, NULL)); 212 214 check (tor->info.files[0].is_renamed); 213 215 check_streq ("foobar", tor->info.files[0].name); 216 check_streq ("foobar", tr_torrentName(tor)); 217 check (strstr (tor->info.torrent, "foobar") == NULL); 218 check (testFileExistsAndConsistsOfThisString (tor, 0, "hello, world!\n")); 214 219 tr_free (tmpstr); 215 check (testFileExistsAndConsistsOfThisString (tor, 0, "hello, world!\n")); 220 221 /* (while it's renamed: confirm that the .resume file remembers the changes) */ 222 tr_torrentSaveResume (tor); 223 sync (); 224 loaded = tr_torrentLoadResume (tor, ~0, ctor); 225 check_streq ("foobar", tr_torrentName(tor)); 226 check ((loaded & TR_FR_NAME) != 0); 216 227 217 228 /*** … … 225 236 check (tor->info.files[0].is_renamed); 226 237 check_streq ("hello-world.txt", tor->info.files[0].name); 238 check_streq ("hello-world.txt", tr_torrentName(tor)); 227 239 tr_free (tmpstr); 228 240 check (testFileExistsAndConsistsOfThisString (tor, 0, "hello, world!\n")); … … 266 278 test_multifile_torrent (void) 267 279 { 268 //tr_file_stat * file_stats;269 //tr_file_index_t n;270 280 tr_file_index_t i; 271 281 uint64_t loaded; 272 282 tr_torrent * tor; 273 //tr_file_index_t i;274 283 tr_ctor * ctor; 275 284 char * str; -
trunk/libtransmission/resume.c
r13807 r13829 335 335 336 336 return ret; 337 } 338 339 /*** 340 **** 341 ***/ 342 343 static void 344 saveName (tr_variant * dict, const tr_torrent * tor) 345 { 346 tr_variantDictAddStr (dict, TR_KEY_name, tr_torrentName(tor)); 347 } 348 349 static uint64_t 350 loadName (tr_variant * dict, tr_torrent * tor) 351 { 352 uint64_t ret = 0; 353 const char * name; 354 355 if (tr_variantDictFindStr (dict, TR_KEY_name, &name, NULL)) 356 { 357 ret = TR_FR_NAME; 358 359 if (tr_strcmp0 (tr_torrentName(tor), name)) 360 { 361 tr_free (tor->info.name); 362 tor->info.name = tr_strdup (name); 363 } 364 } 365 366 return ret; 337 367 } 338 368 … … 651 681 saveIdleLimits (&top, tor); 652 682 saveFilenames (&top, tor); 683 saveName (&top, tor); 653 684 654 685 filename = getResumeFilename (tor); … … 806 837 fieldsLoaded |= loadFilenames (&top, tor); 807 838 839 if (fieldsToLoad & TR_FR_NAME) 840 fieldsLoaded |= loadName (&top, tor); 841 808 842 /* loading the resume file triggers of a lot of changes, 809 843 * but none of them needs to trigger a re-saving of the -
trunk/libtransmission/resume.h
r13807 r13829 40 40 TR_FR_TIME_SEEDING = (1 << 18), 41 41 TR_FR_TIME_DOWNLOADING = (1 << 19), 42 TR_FR_FILENAMES = (1 << 20) 42 TR_FR_FILENAMES = (1 << 20), 43 TR_FR_NAME = (1 << 21), 43 44 }; 44 45 … … 54 55 void tr_torrentRemoveResume (const tr_torrent * tor); 55 56 57 int tr_torrentRenameResume (const tr_torrent * tor, 58 const char * newname); 59 56 60 #endif -
trunk/libtransmission/torrent-magnet.c
r13781 r13829 375 375 } 376 376 377 /* FIXME: this should be renamed tr_metainfoGetMagnetLink() and moved to metainfo.c for consistency */ 377 378 char * 378 379 tr_torrentInfoGetMagnetLink (const tr_info * inf) -
trunk/libtransmission/torrent.c
r13810 r13829 3442 3442 3443 3443 static void 3444 torrentRenameDone (tr_torrent * tor UNUSED, 3445 const char * oldpath UNUSED, 3446 const char * newname UNUSED, 3447 int error, 3448 void * user_data) 3449 { 3450 *(int*)user_data = error; 3451 } 3452 3453 static void 3444 3454 torrentRenamePath (void * vdata) 3445 3455 { … … 3478 3488 if (!error) 3479 3489 { 3490 /* update tr_info.files */ 3480 3491 for (i=0; i<n; ++i) 3481 3492 renameTorrentFileString(tor, oldpath, newname, file_indices[i]); 3493 3494 /* update tr_info.name if user changed the toplevel */ 3495 if ((n == tor->info.fileCount) && (strchr(oldpath,'/')==NULL)) 3496 tr_torrentRename (tor, newname, torrentRenameDone, &error); 3497 3482 3498 tr_torrentSetDirty (tor); 3483 3499 } … … 3522 3538 tr_runInEventThread (tor->session, torrentRenamePath, data); 3523 3539 } 3540 3541 /** 3542 *** 3543 **/ 3544 3545 static void 3546 torrentRename (void * vdata) 3547 { 3548 int error = 0; 3549 struct rename_data * data = vdata; 3550 tr_torrent * const tor = data->tor; 3551 3552 tr_free (tor->info.name); 3553 tor->info.name = data->newname; 3554 tr_torrentSetDirty (tor); 3555 tor->anyDate = tr_time (); 3556 3557 /* callback */ 3558 if (data->callback != NULL) 3559 (*data->callback)(tor, data->oldpath, data->newname, error, data->callback_user_data); 3560 3561 /* cleanup */ 3562 tr_free (data); 3563 } 3564 3565 void 3566 tr_torrentRename (tr_torrent * tor, 3567 const char * newname, 3568 tr_torrent_rename_done_func callback, 3569 void * callback_user_data) 3570 { 3571 struct rename_data * data; 3572 3573 data = tr_new0 (struct rename_data, 1); 3574 data->tor = tor; 3575 data->newname = tr_strdup (newname); 3576 data->callback = callback; 3577 data->callback_user_data = callback_user_data; 3578 3579 tr_runInEventThread (tor->session, torrentRename, data); 3580 } -
trunk/libtransmission/transmission.h
r13809 r13829 1110 1110 * @callback_data: the pointer to pass in the callback's user_data arg 1111 1111 * 1112 * As a special case, renaming the root file in a torrent will call 1113 * tr_torrentRename (tor, newname). 1114 * 1112 1115 * EXAMPLES 1113 1116 * … … 1117 1120 * 1118 1121 * 1. tr_torrentRenamePath (tor, "frobnitz-linux", "foo") will rename 1119 * the "frotbnitz-linux" folder as "foo" and update files[*].name. 1122 * the "frotbnitz-linux" folder as "foo", update info.files[*].name, 1123 * and also call tr_torrentRename(tor,"foo"). 1120 1124 * 1121 1125 * 2. tr_torrentRenamePath (tor, "frobnitz-linux/checksum", "foo") will … … 1126 1130 * 1127 1131 * Changing tr_info's contents requires a session lock, so this function 1128 * returns asynchronously to avoid blocking. If you don't care about error1129 * checking, you can pass NULL as the callback and callback_user_dataarg.1132 * returns asynchronously to avoid blocking. If you don't want to be notified 1133 * when the function has finished, you can pass NULL as the callback arg. 1130 1134 * 1131 1135 * On success, the callback's error argument will be 0. … … 1144 1148 void * callback_user_data); 1145 1149 1150 1151 /** 1152 * @brief Changes the torrent's name. 1153 * @see-also tr_torrentRenamePath 1154 * 1155 * This function changes tr_info.name. 1156 * 1157 * Changing tr_info's contents requires a session lock, so this function 1158 * returns asynchronously to avoid blocking. If you don't want to be notified 1159 * when the function has finished, you can pass NULL as the callback arg. 1160 */ 1161 void tr_torrentRename (tr_torrent * tor, 1162 const char * newname, 1163 tr_torrent_rename_done_func callback, 1164 void * callback_user_data); 1146 1165 1147 1166 enum … … 1758 1777 uint64_t totalSize; 1759 1778 1760 /* the torrent's name */ 1779 /* The original name that came in this torrent's metainfo. 1780 * This may differ from "name" if tr_torrentRename() is called. 1781 * CLIENT CODE: NOT USE THIS FIELD. */ 1782 char * originalName; 1783 1784 /* The torrent's name. */ 1761 1785 char * name; 1762 1786 -
trunk/qt/session.cc
r13810 r13829 828 828 { 829 829 // let's get the updated file list 830 char * req = tr_strdup_printf ("{ \"arguments\": { \"fields\": [ \"files\", \"id\" ], \"ids\": %d }, \"method\": \"torrent-get\", \"tag\": %d }",830 char * req = tr_strdup_printf ("{ \"arguments\": { \"fields\": [ \"files\", \"id\", \"name\" ], \"ids\": %d }, \"method\": \"torrent-get\", \"tag\": %d }", 831 831 int(id), 832 832 int(TAG_SOME_TORRENTS));
Note: See TracChangeset
for help on using the changeset viewer.