From 407c0b53c7b0ed97e68eeec8234f680878b83441 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Mon, 4 Feb 2013 21:45:20 +0000 Subject: [PATCH] (trunk) add portability wrappers tr_rename(), tr_remove() for the rename() and remove() funcs s.t. utf16 can be handled --- daemon/daemon.c | 6 +++--- libtransmission/blocklist-test.c | 2 +- libtransmission/libtransmission-test.c | 2 +- libtransmission/platform.c | 2 +- libtransmission/rename-test.c | 10 +++++----- libtransmission/session.c | 10 +++++----- libtransmission/torrent-magnet.c | 3 +-- libtransmission/torrent.c | 9 ++++----- libtransmission/utils.c | 18 +++++++++++++++++- libtransmission/utils.h | 6 ++++++ libtransmission/variant.c | 6 +----- 11 files changed, 45 insertions(+), 29 deletions(-) diff --git a/daemon/daemon.c b/daemon/daemon.c index dfa678793..f0c7ab911 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -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; } diff --git a/libtransmission/blocklist-test.c b/libtransmission/blocklist-test.c index 9bc9f7427..79f9f1721 100644 --- a/libtransmission/blocklist-test.c +++ b/libtransmission/blocklist-test.c @@ -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); diff --git a/libtransmission/libtransmission-test.c b/libtransmission/libtransmission-test.c index e3159ee99..7353731e3 100644 --- a/libtransmission/libtransmission-test.c +++ b/libtransmission/libtransmission-test.c @@ -166,7 +166,7 @@ rm_rf (const char * killme) if (verbose) fprintf (stderr, "cleanup: removing %s\n", killme); - remove (killme); + tr_remove (killme); } } diff --git a/libtransmission/platform.c b/libtransmission/platform.c index 95b3fbce8..317426e6d 100644 --- a/libtransmission/platform.c +++ b/libtransmission/platform.c @@ -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); diff --git a/libtransmission/rename-test.c b/libtransmission/rename-test.c index 6c3ba5ed1..d95999967 100644 --- a/libtransmission/rename-test.c +++ b/libtransmission/rename-test.c @@ -1,6 +1,6 @@ #include #include -#include /* remove() */ +#include /* fopen() */ #include /* strcmp() */ #include @@ -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 (); diff --git a/libtransmission/session.c b/libtransmission/session.c index 418f95468..e128dbbe2 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -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); diff --git a/libtransmission/torrent-magnet.c b/libtransmission/torrent-magnet.c index aaa156caf..305fc66a8 100644 --- a/libtransmission/torrent-magnet.c +++ b/libtransmission/torrent-magnet.c @@ -11,7 +11,6 @@ */ #include -#include /* remove () */ #include /* memcpy (), memset (), memcmp () */ #include @@ -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); diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 9ca66e75f..31f10e009 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -27,7 +27,6 @@ #include #include /* memcmp */ #include /* qsort */ -#include /* remove () */ #include /* 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; diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 8335876b7..e26832d3a 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -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) { diff --git a/libtransmission/utils.h b/libtransmission/utils.h index 1f0c3f2f3..09704491c 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -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); diff --git a/libtransmission/variant.c b/libtransmission/variant.c index 2f295654e..965302c9b 100644 --- a/libtransmission/variant.c +++ b/libtransmission/variant.c @@ -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); } -- 2.40.0