Skip to content

Commit 3d2e621

Browse files
committed
Don't pre-allocate magnet download storage
1 parent 99172e7 commit 3d2e621

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

core/src/com/biglybt/plugin/magnet/MagnetPluginMDDownloader.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import java.io.RandomAccessFile;
2626
import java.net.InetSocketAddress;
2727
import java.net.URL;
28+
import java.nio.channels.FileChannel;
29+
import java.nio.file.OpenOption;
30+
import java.nio.file.StandardOpenOption;
2831
import java.util.*;
2932

3033
import com.biglybt.core.category.Category;
@@ -329,9 +332,27 @@ protected Boolean initialValue(){
329332

330333
if ( !data_file.exists() || data_file.length() != MD_TORRENT_SIZE ){
331334

335+
if ( !data_file.exists()){
336+
337+
try{
338+
Set<OpenOption> options = new HashSet<>();
339+
340+
options.add( StandardOpenOption.WRITE );
341+
options.add( StandardOpenOption.CREATE_NEW );
342+
options.add( StandardOpenOption.SPARSE );
343+
344+
FileChannel fc = FileChannel.open( data_file.toPath(), options );
345+
346+
fc.close();
347+
348+
}catch( Throwable e ){
349+
}
350+
}
351+
332352
RandomAccessFile raf = new RandomAccessFile( data_file, "rw" );
333353

334354
try{
355+
/*
335356
byte[] buffer = new byte[512*1024];
336357
337358
Arrays.fill( buffer, (byte)0xff );
@@ -340,6 +361,11 @@ protected Boolean initialValue(){
340361
341362
raf.write( buffer );
342363
}
364+
*/
365+
366+
367+
raf.setLength( MD_TORRENT_SIZE );
368+
343369
}finally{
344370

345371
raf.close();
@@ -371,8 +397,7 @@ protected Boolean initialValue(){
371397

372398
meta_torrent = creator.create( true );
373399
}
374-
375-
400+
376401
List<String> extras = plugin.getExtraTrackers();
377402

378403
for ( String extra: extras ){
@@ -520,6 +545,7 @@ protected Boolean initialValue(){
520545
download_manager.addDownloadWillBeAddedListener(dwbal);
521546

522547
try{
548+
data_file.delete();
523549

524550
download = download_manager.addNonPersistentDownloadStopped( PluginCoreUtils.wrap( meta_torrent ), torrent_file, data_file);
525551

0 commit comments

Comments
 (0)