(libT) #1220 'change file and folder names': fold tr_torrentRename() into tr_torrentRenamePath(); it's not useful enough on its own to be a separate function

This commit is contained in:
Jordan Lee 2013-01-22 04:57:45 +00:00
parent 806fdb0314
commit 2e354dfb10
2 changed files with 8 additions and 74 deletions

View File

@ -3440,16 +3440,6 @@ struct rename_data
void * callback_user_data;
};
static void
torrentRenameDone (tr_torrent * tor UNUSED,
const char * oldpath UNUSED,
const char * newname UNUSED,
int error,
void * user_data)
{
*(int*)user_data = error;
}
static void
torrentRenamePath (void * vdata)
{
@ -3493,7 +3483,10 @@ torrentRenamePath (void * vdata)
/* update tr_info.name if user changed the toplevel */
if ((n == tor->info.fileCount) && (strchr(oldpath,'/')==NULL))
tr_torrentRename (tor, newname, torrentRenameDone, &error);
{
tr_free (tor->info.name);
tor->info.name = tr_strdup (newname);
}
tr_torrentSetDirty (tor);
}
@ -3537,45 +3530,3 @@ tr_torrentRenamePath (tr_torrent * tor,
tr_runInEventThread (tor->session, torrentRenamePath, data);
}
/**
***
**/
static void
torrentRename (void * vdata)
{
int error = 0;
struct rename_data * data = vdata;
tr_torrent * const tor = data->tor;
char * const oldname = tor->info.name;
tor->info.name = data->newname;
tr_torrentSetDirty (tor);
tor->anyDate = tr_time ();
/* callback */
if (data->callback != NULL)
(*data->callback)(tor, oldname, data->newname, error, data->callback_user_data);
/* cleanup */
tr_free (oldname);
tr_free (data);
}
void
tr_torrentRename (tr_torrent * tor,
const char * newname,
tr_torrent_rename_done_func callback,
void * callback_user_data)
{
struct rename_data * data;
data = tr_new0 (struct rename_data, 1);
data->tor = tor;
data->newname = tr_strdup (newname);
data->callback = callback;
data->callback_user_data = callback_user_data;
tr_runInEventThread (tor->session, torrentRename, data);
}

View File

@ -1109,8 +1109,8 @@ typedef void (tr_torrent_rename_done_func)(tr_torrent * torrent,
* @callback: the callback invoked when the renaming finishes, or NULL
* @callback_data: the pointer to pass in the callback's user_data arg
*
* As a special case, renaming the root file in a torrent will call
* tr_torrentRename (tor, newname).
* As a special case, renaming the root file in a torrent will allso
* update tr_info.name.
*
* EXAMPLES
*
@ -1119,8 +1119,8 @@ typedef void (tr_torrent_rename_done_func)(tr_torrent * torrent,
* info.files[1].name is "frobnitz-linux/frobnitz.iso".
*
* 1. tr_torrentRenamePath (tor, "frobnitz-linux", "foo") will rename
* the "frotbnitz-linux" folder as "foo", update info.files[*].name,
* and also call tr_torrentRename(tor,"foo").
* the "frotbnitz-linux" folder as "foo", and update both info.name
* and info.files[*].name.
*
* 2. tr_torrentRenamePath (tor, "frobnitz-linux/checksum", "foo") will
* rename the "frobnitz-linux/checksum" file as "foo" and update
@ -1147,22 +1147,6 @@ void tr_torrentRenamePath (tr_torrent * tor,
tr_torrent_rename_done_func callback,
void * callback_user_data);
/**
* @brief Changes the torrent's name.
* @see-also tr_torrentRenamePath
*
* This function changes tr_info.name.
*
* Changing tr_info's contents requires a session lock, so this function
* returns asynchronously to avoid blocking. If you don't want to be notified
* when the function has finished, you can pass NULL as the callback arg.
*/
void tr_torrentRename (tr_torrent * tor,
const char * newname,
tr_torrent_rename_done_func callback,
void * callback_user_data);
enum
{
TR_LOC_MOVING,
@ -1777,7 +1761,6 @@ struct tr_info
uint64_t totalSize;
/* The original name that came in this torrent's metainfo.
* This may differ from "name" if tr_torrentRename() is called.
* CLIENT CODE: NOT USE THIS FIELD. */
char * originalName;