mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
(trunk) add portability wrappers tr_rename(), tr_remove() for the rename() and remove() funcs s.t. utf16 can be handled
This commit is contained in:
+3
-3
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -166,7 +166,7 @@ rm_rf (const char * killme)
|
||||
if (verbose)
|
||||
fprintf (stderr, "cleanup: removing %s\n", killme);
|
||||
|
||||
remove (killme);
|
||||
tr_remove (killme);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
+17
-1
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user