From a2898f2ee9d10cd87d55e12664c8cb31b954e850 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Fri, 4 Jul 2014 03:23:27 +0000 Subject: [PATCH] (trunk, libT) #5656 'Problems renaming files' -- fixed, patch by rb07 --- libtransmission/rename-test.c | 39 ++++++++++++++++++++++++++++++++++- libtransmission/torrent.c | 5 +++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/libtransmission/rename-test.c b/libtransmission/rename-test.c index 9022f31d2..55ea2f085 100644 --- a/libtransmission/rename-test.c +++ b/libtransmission/rename-test.c @@ -368,7 +368,7 @@ test_multifile_torrent (void) for (i=0; i<4; ++i) { check_streq (expected_files[i], files[i].name); - check (testFileExistsAndConsistsOfThisString (tor, 1, expected_contents[1])); + check (testFileExistsAndConsistsOfThisString (tor, i, expected_contents[i])); } check (files[0].is_renamed == false); check (files[1].is_renamed == true); @@ -439,6 +439,43 @@ test_multifile_torrent (void) testFileExistsAndConsistsOfThisString (tor, i, expected_contents[i]); } + /** + *** Test renaming prefixes (shouldn't work) + **/ + + tr_torrentRemove (tor, false, NULL); + do { + tr_wait_msec (10); + } while (0); + ctor = tr_ctorNew (session); + tor = create_torrent_from_base64_metainfo (ctor, + "ZDEwOmNyZWF0ZWQgYnkyNTpUcmFuc21pc3Npb24vMi42MSAoMTM0MDcpMTM6Y3JlYXRpb24gZGF0" + "ZWkxMzU4NTU1NDIwZTg6ZW5jb2Rpbmc1OlVURi04NDppbmZvZDU6ZmlsZXNsZDY6bGVuZ3RoaTI4" + "ZTQ6cGF0aGw3OkZlbGluYWU4OkFjaW5vbnl4NzpDaGVldGFoNzpDaGVzdGVyZWVkNjpsZW5ndGhp" + "MTJlNDpwYXRobDc6RmVsaW5hZTU6RmVsaXM1OmNhdHVzNTpLeXBoaWVlZDY6bGVuZ3RoaTZlNDpw" + "YXRobDc6RmVsaW5hZTU6RmVsaXM1OmNhdHVzNzpTYWZmcm9uZWVkNjpsZW5ndGhpMjFlNDpwYXRo" + "bDExOlBhbnRoZXJpbmFlODpQYW50aGVyYTU6VGlnZXI0OlRvbnllZWU0Om5hbWU3OkZlbGlkYWUx" + "MjpwaWVjZSBsZW5ndGhpMzI3NjhlNjpwaWVjZXMyMDp27buFkmy8ICfNX4nsJmt0Ckm2Ljc6cHJp" + "dmF0ZWkwZWVl"); + check (tr_isTorrent (tor)); + files = tor->info.files; + + /* rename prefix of top */ + check_int_eq (EINVAL, torrentRenameAndWait (tor, "Feli", "FelidaeX")); + check_streq (tor->info.name, "Felidae"); + check (files[0].is_renamed == false); + check (files[1].is_renamed == false); + check (files[2].is_renamed == false); + check (files[3].is_renamed == false); + + /* rename false path */ + check_int_eq (EINVAL, torrentRenameAndWait (tor, "Felidae/FelinaeX", "Genus Felinae")); + check_streq (tor->info.name, "Felidae"); + check (files[0].is_renamed == false); + check (files[1].is_renamed == false); + check (files[2].is_renamed == false); + check (files[3].is_renamed == false); + /*** **** ***/ diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 8138a7962..4dea99cb1 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -3592,7 +3592,8 @@ renameFindAffectedFiles (tr_torrent * tor, const char * oldpath, size_t * setme_ { const char * name = tor->info.files[i].name; const size_t len = strlen (name); - if ((len >= oldpath_len) && !memcmp (oldpath, name, oldpath_len)) + if ((len == oldpath_len || (len > oldpath_len && name[oldpath_len] == '/')) && + !memcmp (oldpath, name, oldpath_len)) indices[n++] = i; } @@ -3735,7 +3736,7 @@ torrentRenamePath (void * vdata) file_indices = renameFindAffectedFiles (tor, oldpath, &n); if (n == 0) { - errno = EINVAL; + error = EINVAL; } else { -- 2.40.0