]> granicus.if.org Git - transmission/commitdiff
(trunk, libT) #5656 'Problems renaming files' -- fixed, patch by rb07
authorJordan Lee <jordan@transmissionbt.com>
Fri, 4 Jul 2014 03:23:27 +0000 (03:23 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Fri, 4 Jul 2014 03:23:27 +0000 (03:23 +0000)
libtransmission/rename-test.c
libtransmission/torrent.c

index 9022f31d26916fa324ddcd41e8ee3148c21b6943..55ea2f085d23023737bcea552c93e328f0316f6c 100644 (file)
@@ -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);
+
   /***
   ****
   ***/
index 8138a7962258daed548d8a5d8cae1cd9484b7411..4dea99cb175223fd2a4dc5f5a1cc50fd68cdb10a 100644 (file)
@@ -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
         {