Changeset 8453 for trunk/libtransmission/torrent.c
- Timestamp:
- May 20, 2009, 4:02:12 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/torrent.c
r8433 r8453 2281 2281 { 2282 2282 tr_bool move_from_old_location; 2283 tr_bool * setme_done; 2283 int * setme_state; 2284 double * setme_progress; 2284 2285 char * location; 2285 2286 tr_torrent * tor; … … 2289 2290 setLocation( void * vdata ) 2290 2291 { 2292 int err = 0; 2291 2293 struct LocationData * data = vdata; 2292 2294 tr_torrent * tor = data->tor; 2293 2295 const tr_bool do_move = data->move_from_old_location; 2294 2296 const char * location = data->location; 2297 double bytesHandled = 0; 2295 2298 2296 2299 assert( tr_isTorrent( tor ) ); … … 2314 2317 * FIXME: there are still all kinds of nasty cases, like what 2315 2318 * if the target directory runs out of space halfway through... */ 2316 for( i=0; i<tor->info.fileCount; ++i )2319 for( i=0; !err && i<tor->info.fileCount; ++i ) 2317 2320 { 2318 2321 struct stat sb; 2319 c har * oldpath = tr_buildPath( tor->downloadDir, tor->info.files[i].name, NULL );2320 char * newpath = tr_buildPath( location, tor->info.files[i].name, NULL );2321 2322 const tr_file * f = &tor->info.files[i]; 2323 char * oldpath = tr_buildPath( tor->downloadDir, f->name, NULL ); 2324 char * newpath = tr_buildPath( location, f->name, NULL ); 2322 2325 2323 if( do_move && !stat( oldpath, &sb ))2326 if( do_move ) 2324 2327 { 2325 tr_moveFile( oldpath, newpath );2328 errno = 0; 2326 2329 tr_torinf( tor, "moving \"%s\" to \"%s\"", oldpath, newpath ); 2330 if( tr_moveFile( oldpath, newpath ) ) { 2331 err = 1; 2332 tr_torerr( tor, "error moving \"%s\" to \"%s\": %s", 2333 oldpath, newpath, tr_strerror( errno ) ); 2334 } 2327 2335 } 2328 2336 else if( !stat( newpath, &sb ) ) … … 2331 2339 } 2332 2340 2341 if( data->setme_progress ) 2342 { 2343 bytesHandled += f->length; 2344 *data->setme_progress = bytesHandled / tor->info.totalSize; 2345 } 2346 2333 2347 tr_free( newpath ); 2334 2348 tr_free( oldpath ); 2335 2349 } 2336 2350 2337 /* blow away the leftover subdirectories in the old location */ 2338 tr_torrentDeleteLocalData( tor, unlink ); 2339 2340 /* set the new location and reverify */ 2341 tr_torrentSetDownloadDir( tor, location ); 2342 tr_torrentVerify( tor ); 2343 } 2344 2345 if( data->setme_done ) 2346 *data->setme_done = TRUE; 2351 if( !err ) 2352 { 2353 /* blow away the leftover subdirectories in the old location */ 2354 tr_torrentDeleteLocalData( tor, unlink ); 2355 2356 /* set the new location and reverify */ 2357 tr_torrentSetDownloadDir( tor, location ); 2358 tr_torrentVerify( tor ); 2359 } 2360 } 2361 2362 if( data->setme_state ) 2363 *data->setme_state = err ? TR_LOC_ERROR : TR_LOC_DONE; 2347 2364 2348 2365 /* cleanup */ … … 2352 2369 2353 2370 void 2354 tr_torrentSetLocation( tr_torrent * tor, 2355 const char * location, 2356 tr_bool move_from_old_location, 2357 tr_bool * setme_done ) 2371 tr_torrentSetLocation( tr_torrent * tor, 2372 const char * location, 2373 tr_bool move_from_old_location, 2374 double * setme_progress, 2375 int * setme_state ) 2358 2376 { 2359 2377 struct LocationData * data; … … 2361 2379 assert( tr_isTorrent( tor ) ); 2362 2380 2363 if( setme_done ) 2364 *setme_done = FALSE; 2381 if( setme_state ) 2382 *setme_state = TR_LOC_MOVING; 2383 if( setme_progress ) 2384 *setme_progress = 0; 2365 2385 2366 2386 /* run this in the libtransmission thread */ … … 2369 2389 data->location = tr_strdup( location ); 2370 2390 data->move_from_old_location = move_from_old_location; 2371 data->setme_done = setme_done; 2391 data->setme_state = setme_state; 2392 data->setme_progress = setme_progress; 2372 2393 tr_runInEventThread( tor->session, setLocation, data ); 2373 2394 }
Note: See TracChangeset
for help on using the changeset viewer.