(trunk) #920 Add "Move Data" to libT so all clients can use it
This commit is contained in:
parent
9d1ea6eb6b
commit
7d844ec279
|
@ -36,7 +36,7 @@ onTimer( gpointer gdata )
|
|||
struct UpdateData * data = gdata;
|
||||
const tr_bool done = data->done;
|
||||
|
||||
if( done )
|
||||
if( done != TR_LOC_MOVING )
|
||||
{
|
||||
gtk_widget_destroy( GTK_WIDGET( data->dialog ) );
|
||||
g_free( data );
|
||||
|
@ -75,7 +75,7 @@ onResponse( GtkDialog * dialog, int response, gpointer unused UNUSED )
|
|||
updateData = g_new( struct UpdateData, 1 );
|
||||
updateData->dialog = dialog;
|
||||
updateData->done = FALSE;
|
||||
tr_torrentSetLocation( tor, location, do_move, &updateData->done );
|
||||
tr_torrentSetLocation( tor, location, do_move, NULL, &updateData->done );
|
||||
gtr_timeout_add_seconds( 1, onTimer, updateData );
|
||||
|
||||
/* remember this location so that it can be the default next time */
|
||||
|
|
|
@ -794,7 +794,7 @@ torrentSetLocation( tr_session * session,
|
|||
for( i=0; i<torrentCount; ++i )
|
||||
{
|
||||
tr_torrent * tor = torrents[i];
|
||||
tr_torrentSetLocation( tor, location, move, NULL );
|
||||
tr_torrentSetLocation( tor, location, move, NULL, NULL );
|
||||
notify( session, TR_RPC_TORRENT_CHANGED, tor );
|
||||
}
|
||||
|
||||
|
|
|
@ -2280,7 +2280,8 @@ tr_torrentDeleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc )
|
|||
struct LocationData
|
||||
{
|
||||
tr_bool move_from_old_location;
|
||||
tr_bool * setme_done;
|
||||
int * setme_state;
|
||||
double * setme_progress;
|
||||
char * location;
|
||||
tr_torrent * tor;
|
||||
};
|
||||
|
@ -2288,10 +2289,12 @@ struct LocationData
|
|||
static void
|
||||
setLocation( void * vdata )
|
||||
{
|
||||
int err = 0;
|
||||
struct LocationData * data = vdata;
|
||||
tr_torrent * tor = data->tor;
|
||||
const tr_bool do_move = data->move_from_old_location;
|
||||
const char * location = data->location;
|
||||
double bytesHandled = 0;
|
||||
|
||||
assert( tr_isTorrent( tor ) );
|
||||
|
||||
|
@ -2313,37 +2316,51 @@ setLocation( void * vdata )
|
|||
/* try to move the files.
|
||||
* FIXME: there are still all kinds of nasty cases, like what
|
||||
* if the target directory runs out of space halfway through... */
|
||||
for( i=0; i<tor->info.fileCount; ++i )
|
||||
for( i=0; !err && i<tor->info.fileCount; ++i )
|
||||
{
|
||||
struct stat sb;
|
||||
char * oldpath = tr_buildPath( tor->downloadDir, tor->info.files[i].name, NULL );
|
||||
char * newpath = tr_buildPath( location, tor->info.files[i].name, NULL );
|
||||
|
||||
const tr_file * f = &tor->info.files[i];
|
||||
char * oldpath = tr_buildPath( tor->downloadDir, f->name, NULL );
|
||||
char * newpath = tr_buildPath( location, f->name, NULL );
|
||||
|
||||
if( do_move && !stat( oldpath, &sb ) )
|
||||
if( do_move )
|
||||
{
|
||||
tr_moveFile( oldpath, newpath );
|
||||
errno = 0;
|
||||
tr_torinf( tor, "moving \"%s\" to \"%s\"", oldpath, newpath );
|
||||
if( tr_moveFile( oldpath, newpath ) ) {
|
||||
err = 1;
|
||||
tr_torerr( tor, "error moving \"%s\" to \"%s\": %s",
|
||||
oldpath, newpath, tr_strerror( errno ) );
|
||||
}
|
||||
}
|
||||
else if( !stat( newpath, &sb ) )
|
||||
{
|
||||
tr_torinf( tor, "found \"%s\"", newpath );
|
||||
}
|
||||
|
||||
if( data->setme_progress )
|
||||
{
|
||||
bytesHandled += f->length;
|
||||
*data->setme_progress = bytesHandled / tor->info.totalSize;
|
||||
}
|
||||
|
||||
tr_free( newpath );
|
||||
tr_free( oldpath );
|
||||
}
|
||||
|
||||
/* blow away the leftover subdirectories in the old location */
|
||||
tr_torrentDeleteLocalData( tor, unlink );
|
||||
if( !err )
|
||||
{
|
||||
/* blow away the leftover subdirectories in the old location */
|
||||
tr_torrentDeleteLocalData( tor, unlink );
|
||||
|
||||
/* set the new location and reverify */
|
||||
tr_torrentSetDownloadDir( tor, location );
|
||||
tr_torrentVerify( tor );
|
||||
/* set the new location and reverify */
|
||||
tr_torrentSetDownloadDir( tor, location );
|
||||
tr_torrentVerify( tor );
|
||||
}
|
||||
}
|
||||
|
||||
if( data->setme_done )
|
||||
*data->setme_done = TRUE;
|
||||
if( data->setme_state )
|
||||
*data->setme_state = err ? TR_LOC_ERROR : TR_LOC_DONE;
|
||||
|
||||
/* cleanup */
|
||||
tr_free( data->location );
|
||||
|
@ -2351,24 +2368,28 @@ setLocation( void * vdata )
|
|||
}
|
||||
|
||||
void
|
||||
tr_torrentSetLocation( tr_torrent * tor,
|
||||
const char * location,
|
||||
tr_bool move_from_old_location,
|
||||
tr_bool * setme_done )
|
||||
tr_torrentSetLocation( tr_torrent * tor,
|
||||
const char * location,
|
||||
tr_bool move_from_old_location,
|
||||
double * setme_progress,
|
||||
int * setme_state )
|
||||
{
|
||||
struct LocationData * data;
|
||||
|
||||
assert( tr_isTorrent( tor ) );
|
||||
|
||||
if( setme_done )
|
||||
*setme_done = FALSE;
|
||||
if( setme_state )
|
||||
*setme_state = TR_LOC_MOVING;
|
||||
if( setme_progress )
|
||||
*setme_progress = 0;
|
||||
|
||||
/* run this in the libtransmission thread */
|
||||
data = tr_new( struct LocationData, 1 );
|
||||
data->tor = tor;
|
||||
data->location = tr_strdup( location );
|
||||
data->move_from_old_location = move_from_old_location;
|
||||
data->setme_done = setme_done;
|
||||
data->setme_state = setme_state;
|
||||
data->setme_progress = setme_progress;
|
||||
tr_runInEventThread( tor->session, setLocation, data );
|
||||
}
|
||||
|
||||
|
|
|
@ -937,11 +937,19 @@ void tr_torrentStop( tr_torrent * torrent );
|
|||
|
||||
typedef int tr_fileFunc( const char * filename );
|
||||
|
||||
enum
|
||||
{
|
||||
TR_LOC_MOVING,
|
||||
TR_LOC_DONE,
|
||||
TR_LOC_ERROR
|
||||
};
|
||||
|
||||
/** @brief Tell transmsision where to find this torrent's local data */
|
||||
void tr_torrentSetLocation( tr_torrent * torrent,
|
||||
const char * location,
|
||||
tr_bool move_from_previous_location,
|
||||
tr_bool * setme_done );
|
||||
double * setme_progress,
|
||||
int * setme_state );
|
||||
|
||||
/**
|
||||
* @brief Deletes the torrent's local data.
|
||||
|
|
Loading…
Reference in New Issue