]> granicus.if.org Git - transmission/commitdiff
(trunk) add portability wrappers tr_rename(), tr_remove() for the rename() and remove...
authorJordan Lee <jordan@transmissionbt.com>
Mon, 4 Feb 2013 21:45:20 +0000 (21:45 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Mon, 4 Feb 2013 21:45:20 +0000 (21:45 +0000)
daemon/daemon.c
libtransmission/blocklist-test.c
libtransmission/libtransmission-test.c
libtransmission/platform.c
libtransmission/rename-test.c
libtransmission/session.c
libtransmission/torrent-magnet.c
libtransmission/torrent.c
libtransmission/utils.c
libtransmission/utils.h
libtransmission/variant.c

index dfa678793e9f3c2ac27b235e2987c65360fab03e..f0c7ab911a8701daf14e9fa8fb4064da170c6fbb 100644 (file)
@@ -277,13 +277,13 @@ onFileAdded (tr_session * session, const char * dir, const char * file)
             if (!test && trash)
             {
                 tr_logAddInfo ("Deleting input .torrent file \"%s\"", file);
-                if (remove (filename))
+                if (tr_remove (filename))
                     tr_logAddError ("Error deleting .torrent file: %s", tr_strerror (errno));
             }
             else
             {
                 char * new_filename = tr_strdup_printf ("%s.added", filename);
-                rename (filename, new_filename);
+                tr_rename (filename, new_filename);
                 tr_free (new_filename);
             }
         }
@@ -597,7 +597,7 @@ main (int argc, char ** argv)
 
     /* cleanup */
     if (pidfile_created)
-        remove (pid_filename);
+        tr_remove (pid_filename);
     tr_variantFree (&settings);
     return 0;
 }
index 9bc9f74273053931e3c295f55cd6b905840eb1ff..79f9f1721334c640385e2af19c2dcea5765db812 100644 (file)
@@ -33,7 +33,7 @@ create_text_file (const char * path, const char * contents)
   tr_mkdirp (dir, 0700);
   tr_free (dir);
 
-  remove (path);
+  tr_remove (path);
   fp = fopen (path, "w+");
   fprintf (fp, "%s", contents);
   fclose (fp);
index e3159ee993c6d3cc9cecd4c29c8a972be2f56402..7353731e35e7c1a4bd265bdde15a23204b001845 100644 (file)
@@ -166,7 +166,7 @@ rm_rf (const char * killme)
       if (verbose)
         fprintf (stderr, "cleanup: removing %s\n", killme);
 
-      remove (killme);
+      tr_remove (killme);
     }
 }
 
index 95b3fbce805c8d911898e7e209765814369bfb51..317426e6dd1d5555a92854fa3745767426c4df0c 100644 (file)
@@ -371,7 +371,7 @@ moveFiles (const char * oldDir, const char * newDir)
                 {
                   char * o = tr_buildPath (oldDir, name, NULL);
                   char * n = tr_buildPath (newDir, name, NULL);
-                  rename (o, n);
+                  tr_rename (o, n);
                   ++count;
                   tr_free (n);
                   tr_free (o);
index 6c3ba5ed1328f51358e1b5a30095f610cb8498f6..d9599996791eb6f3a24102f60d6ad3fbff14d698 100644 (file)
@@ -1,6 +1,6 @@
 #include <assert.h>
 #include <errno.h>
-#include <stdio.h> /* remove() */
+#include <stdio.h> /* fopen() */
 #include <string.h> /* strcmp() */
 #include <stdio.h>
 
@@ -98,7 +98,7 @@ create_file_with_contents (const char * path, const char * str)
   assert (rv == 0);
   tr_free (dir);
 
-  remove (path);
+  tr_remove (path);
   fp = fopen (path, "wb");
   fprintf (fp, "%s", str);
   fclose (fp);
@@ -398,13 +398,13 @@ test_multifile_torrent (void)
   /* remove the directory Felidae/Felinae/Felis/catus */
   str = tr_torrentFindFile (tor, 1);
   check (str != NULL);
-  remove (str);
+  tr_remove (str);
   tr_free (str);
   str = tr_torrentFindFile (tor, 2);
   check (str != NULL);
-  remove (str);
+  tr_remove (str);
   tmp = tr_dirname (str);
-  remove (tmp);
+  tr_remove (tmp);
   tr_free (tmp);
   tr_free (str);
   sync ();
index 418f95468ac518ea6a64280fda593779658f4438..e128dbbe21b3f4580713fc52d916339b9ca4cf4e 100644 (file)
@@ -2238,17 +2238,17 @@ loadBlocklists (tr_session * session)
               tr_blocklistFile * b;
 
               old = tr_strdup_printf ("%s.old", binname);
-              remove (old);
-              rename (binname, old);
+              tr_remove (old);
+              tr_rename (binname, old);
               b = tr_blocklistFileNew (binname, isEnabled);
               if (tr_blocklistFileSetContent (b, path) > 0)
                 {
-                  remove (old);
+                  tr_remove (old);
                 }
               else
                 {
-                  remove (binname);
-                  rename (old, binname);
+                  tr_remove (binname);
+                  tr_rename (old, binname);
                 }
 
               tr_blocklistFileFree (b);
index aaa156caf3bfe9312330993c54088dc963197297..305fc66a85b3fe1d3ec5cc19130f79bda63af464 100644 (file)
@@ -11,7 +11,6 @@
  */
 
 #include <assert.h>
-#include <stdio.h> /* remove () */
 #include <string.h> /* memcpy (), memset (), memcmp () */
 
 #include <event2/buffer.h>
@@ -263,7 +262,7 @@ tr_torrentSetMetadataPiece (tr_torrent  * tor, int piece, const void  * data, in
                   int infoDictLength;
 
                   /* remove any old .torrent and .resume files */
-                  remove (path);
+                  tr_remove (path);
                   tr_torrentRemoveResume (tor);
 
                   dbgmsg (tor, "Saving completed metadata to \"%s\"", path);
index 9ca66e75f316e1de49a3431b256dac83eeca3a2d..31f10e0099d7bea7ba7059c060ac09a005e73891 100644 (file)
@@ -27,7 +27,6 @@
 #include <stdarg.h>
 #include <string.h> /* memcmp */
 #include <stdlib.h> /* qsort */
-#include <stdio.h> /* remove () */
 
 #include <event2/util.h> /* evutil_vsnprintf () */
 
@@ -2775,11 +2774,11 @@ removeEmptyFoldersAndJunkFiles (const char * folder)
                 if (!stat (filename, &sb) && S_ISDIR (sb.st_mode))
                     removeEmptyFoldersAndJunkFiles (filename);
                 else if (isJunkFile (d->d_name))
-                    remove (filename);
+                    tr_remove (filename);
                 tr_free (filename);
             }
         }
-        remove (folder);
+        tr_remove (folder);
         closedir (odir);
     }
 }
@@ -3106,7 +3105,7 @@ tr_torrentFileCompleted (tr_torrent * tor, tr_file_index_t fileIndex)
             char * oldpath = tr_buildPath (base, sub, NULL);
             char * newpath = tr_buildPath (base, f->name, NULL);
 
-            if (rename (oldpath, newpath))
+            if (tr_rename (oldpath, newpath))
                 tr_logAddTorErr (tor, "Error moving \"%s\" to \"%s\": %s", oldpath, newpath, tr_strerror (errno));
 
             tr_free (newpath);
@@ -3524,7 +3523,7 @@ renamePath (tr_torrent  * tor,
           int rv;
 
           tmp = errno;
-          rv = rename (src, tgt);
+          rv = tr_rename (src, tgt);
           if (rv != 0)
             error = errno;
           errno = tmp;
index 8335876b7fd4419862cd5556555e14dd4d4e3fad..e26832d3afbb070029fa710dbc2767507a4fd70a 100644 (file)
@@ -1437,7 +1437,7 @@ tr_moveFile (const char * oldpath, const char * newpath, bool * renamed)
 
   /* they might be on the same filesystem... */
   {
-    const int i = rename (oldpath, newpath);
+    const int i = tr_rename (oldpath, newpath);
     if (renamed != NULL)
       *renamed = i == 0;
     if (!i)
@@ -1472,6 +1472,22 @@ tr_moveFile (const char * oldpath, const char * newpath, bool * renamed)
   return 0;
 }
 
+int
+tr_rename (const char * oldpath, const char * newpath)
+{
+  /* FIXME: needs win32 utf-16 support */
+
+  return rename (oldpath, newpath);
+}
+
+int
+tr_remove (const char * pathname)
+{
+  /* FIXME: needs win32 utf-16 support */
+
+  return remove (pathname);
+}
+
 bool
 tr_is_same_file (const char * filename1, const char * filename2)
 {
index 1f0c3f2f3614352982ce0935fd4369592cd45d38..09704491ccf93bbc0d224b08eb4a2b35e9f72820 100644 (file)
@@ -390,6 +390,12 @@ struct tm * tr_localtime_r (const time_t *_clock, struct tm *_result);
 int tr_moveFile (const char * oldpath, const char * newpath,
                  bool * renamed) TR_GNUC_NONNULL (1,2);
 
+/** @brief Portability wrapper for rename () */
+int tr_rename (const char * oldpath_utf8, const char * newpath_utf8);
+
+/** @brief Portability wrapper for remove () */
+int tr_remove (const char * pathname_utf8);
+
 /** @brief Test to see if the two filenames point to the same file. */
 bool tr_is_same_file (const char * filename1, const char * filename2);
 
index 2f295654eedbc373243e93eca0706fd00d841722..965302c9be009a82f37dd99b5ee53e688ba6cb2d 100644 (file)
@@ -1212,11 +1212,7 @@ tr_variantToFile (const tr_variant  * v,
         {
           tr_close_file (fd);
 
-#ifdef WIN32
-          if (MoveFileEx (tmp, filename, MOVEFILE_REPLACE_EXISTING))
-#else
-          if (!rename (tmp, filename))
-#endif
+          if (!tr_rename (tmp, filename))
             {
               tr_logAddInfo (_("Saved \"%s\""), filename);
             }