@@ -401,36 +401,41 @@ public boolean isSkipped() {
401
401
@ Override
402
402
public void setSkipped (boolean skipped ) {
403
403
404
- try {
405
- skipping = skipped ;
406
-
407
- int existing_st = getStorageType ();
408
-
409
- // currently a non-skipped file must be linear
410
-
411
- if ( !skipped && existing_st == ST_COMPACT ){
412
- if ( !setStorageType ( ST_LINEAR )){
413
- return ;
404
+ synchronized ( DiskManagerUtil .skip_lock ){
405
+
406
+ try {
407
+ skipping = skipped ;
408
+
409
+ int existing_st = getStorageType ();
410
+
411
+ // currently a non-skipped file must be linear
412
+
413
+ if ( !skipped && existing_st == ST_COMPACT ){
414
+ if ( !setStorageType ( ST_LINEAR )){
415
+ return ;
416
+ }
414
417
}
415
- }
416
-
417
- if ( !skipped && existing_st == ST_REORDER_COMPACT ){
418
- if ( ! setStorageType ( ST_REORDER )){
419
- return ;
418
+
419
+ if ( ! skipped && existing_st == ST_REORDER_COMPACT ){
420
+ if ( !setStorageType ( ST_REORDER ) ){
421
+ return ;
422
+ }
420
423
}
421
- }
422
-
423
- setSkippedInternal ( skipped );
424
424
425
- diskManager . skippedFileSetChanged ( this );
425
+ setSkippedInternal ( skipped );
426
426
427
- boolean [] toCheck = new boolean [diskManager .getFileSet ().nbFiles ()];
427
+ diskManager .skippedFileSetChanged ( this );
428
+
429
+ boolean [] toCheck = new boolean [diskManager .getFileSet ().nbFiles ()];
430
+
431
+ toCheck [file_index ] = true ;
432
+
433
+ DiskManagerUtil .doFileExistenceChecksAfterSkipChange (diskManager .getFileSet (), toCheck , skipped , diskManager .getDownloadState ().getDownloadManager ());
428
434
429
- toCheck [file_index ] = true ;
430
-
431
- DiskManagerUtil .doFileExistenceChecksAfterSkipChange (diskManager .getFileSet (), toCheck , skipped , diskManager .getDownloadState ().getDownloadManager ());
432
- }finally {
433
- skipping = null ;
435
+ }finally {
436
+
437
+ skipping = null ;
438
+ }
434
439
}
435
440
}
436
441
@@ -442,168 +447,171 @@ public Boolean isSkipping(){
442
447
setSkippedInternal (
443
448
boolean _skipped )
444
449
{
445
- skipped_internal = _skipped ;
446
-
447
- DownloadManager dm = getDownloadManager ();
448
-
449
- if ( dm != null && !dm .isDestroyed ()){
450
-
451
- DownloadManagerState dm_state = diskManager .getDownloadState ();
452
-
453
- String dnd_sf = dm_state .getAttribute ( DownloadManagerState .AT_DND_SUBFOLDER );
454
-
455
- if ( dnd_sf != null ){
456
-
457
- File link = getLink ();
458
-
459
- File file = getFile ( false );
460
-
461
- if ( _skipped ){
462
-
463
- if ( link == null || link .equals ( file )){
464
-
465
- File parent = file .getParentFile ();
466
-
467
- if ( parent != null ){
468
-
469
- File new_parent = FileUtil .newFile ( parent , dnd_sf );
470
-
471
- // add prefix if not already present
472
-
473
- String prefix = dm_state .getAttribute ( DownloadManagerState .AT_DND_PREFIX );
474
-
475
- String file_name = file .getName ();
476
-
477
- if ( prefix != null && !file_name .startsWith ( prefix )){
478
-
479
- file_name = prefix + file_name ;
480
- }
481
-
482
- File new_file = FileUtil .newFile ( new_parent , file_name );
483
-
484
- if ( !new_file .exists ()){
485
-
486
- if ( !new_parent .exists ()){
487
-
488
- new_parent .mkdirs ();
489
- }
490
-
491
- if ( new_parent .canWrite ()){
492
-
493
- boolean ok ;
494
-
495
- try {
496
- dm_state .setFileLink ( file_index , file , new_file );
497
-
498
- cache_file .moveFile ( new_file , null );
499
-
450
+ synchronized ( DiskManagerUtil .skip_lock ){
451
+
452
+ skipped_internal = _skipped ;
453
+
454
+ DownloadManager dm = getDownloadManager ();
455
+
456
+ if ( dm != null && !dm .isDestroyed ()){
457
+
458
+ DownloadManagerState dm_state = diskManager .getDownloadState ();
459
+
460
+ String dnd_sf = dm_state .getAttribute ( DownloadManagerState .AT_DND_SUBFOLDER );
461
+
462
+ if ( dnd_sf != null ){
463
+
464
+ File link = getLink ();
465
+
466
+ File file = getFile ( false );
467
+
468
+ if ( _skipped ){
469
+
470
+ if ( link == null || link .equals ( file )){
471
+
472
+ File parent = file .getParentFile ();
473
+
474
+ if ( parent != null ){
475
+
476
+ File new_parent = FileUtil .newFile ( parent , dnd_sf );
477
+
478
+ // add prefix if not already present
479
+
480
+ String prefix = dm_state .getAttribute ( DownloadManagerState .AT_DND_PREFIX );
481
+
482
+ String file_name = file .getName ();
483
+
484
+ if ( prefix != null && !file_name .startsWith ( prefix )){
485
+
486
+ file_name = prefix + file_name ;
487
+ }
488
+
489
+ File new_file = FileUtil .newFile ( new_parent , file_name );
490
+
491
+ if ( !new_file .exists ()){
492
+
493
+ if ( !new_parent .exists ()){
494
+
495
+ new_parent .mkdirs ();
496
+ }
497
+
498
+ if ( new_parent .canWrite ()){
499
+
500
+ boolean ok ;
501
+
502
+ try {
503
+ dm_state .setFileLink ( file_index , file , new_file );
504
+
505
+ cache_file .moveFile ( new_file , null );
506
+
507
+ ok = true ;
508
+
509
+ }catch ( Throwable e ){
510
+
511
+ ok = false ;
512
+
513
+ Debug .out ( e );
514
+ }
515
+
516
+ if ( !ok ){
517
+
518
+ dm_state .setFileLink ( file_index , file , link );
519
+ }
520
+ }
521
+ }
522
+ }
523
+ }
524
+ }else {
525
+
526
+ if ( link != null && !file .exists ()){
527
+
528
+ File parent = file .getParentFile ();
529
+
530
+ if ( parent != null && parent .canWrite ()){
531
+
532
+ File new_parent = parent .getName ().equals ( dnd_sf )?parent :FileUtil .newFile ( parent , dnd_sf );
533
+
534
+ // use link name to handle incomplete file suffix if set
535
+
536
+ File new_file = FileUtil .newFile ( new_parent , link .getName ());
537
+
538
+ if ( new_file .equals ( link )){
539
+
540
+ boolean ok ;
541
+
542
+ try {
543
+ String file_name = file .getName ();
544
+
545
+ String prefix = dm_state .getAttribute ( DownloadManagerState .AT_DND_PREFIX );
546
+
547
+ boolean prefix_removed = false ;
548
+
549
+ if ( prefix != null && file_name .startsWith (prefix )){
550
+
551
+ file_name = file_name .substring ( prefix .length ());
552
+
553
+ prefix_removed = true ;
554
+ }
555
+
556
+ String incomp_ext = dm_state .getAttribute ( DownloadManagerState .AT_INCOMP_FILE_SUFFIX );
557
+
558
+ if ( incomp_ext != null && incomp_ext .length () > 0 &&
559
+ getDownloaded () != getLength ()){
560
+
561
+ // retain the prefix if enabled and we have a suffix
562
+
563
+ if ( prefix == null ){
564
+
565
+ prefix = "" ;
566
+ }
567
+
568
+ File new_link = FileUtil .newFile ( file .getParentFile (), prefix + file_name + incomp_ext );
569
+
570
+ dm_state .setFileLink ( file_index , file , new_link );
571
+
572
+ cache_file .moveFile ( new_link , null );
573
+
574
+ }else if ( prefix_removed ){
575
+
576
+ File new_link = FileUtil .newFile ( file .getParentFile (), file_name );
577
+
578
+ dm_state .setFileLink ( file_index , file , new_link );
579
+
580
+ cache_file .moveFile ( new_link , null );
581
+
582
+ }else {
583
+
584
+ dm_state .setFileLink ( file_index , file , null );
585
+
586
+ cache_file .moveFile ( file , null );
587
+ }
588
+
589
+ File [] files = new_parent .listFiles ();
590
+
591
+ if ( files != null && files .length == 0 ){
592
+
593
+ new_parent .delete ();
594
+ }
595
+
500
596
ok = true ;
501
-
597
+
502
598
}catch ( Throwable e ){
503
-
599
+
504
600
ok = false ;
505
-
601
+
506
602
Debug .out ( e );
507
603
}
508
-
509
- if ( !ok ){
510
-
511
- dm_state .setFileLink ( file_index , file , link );
604
+
605
+ if ( !ok ){
606
+
607
+ dm_state .setFileLink ( file_index , file , link );
512
608
}
513
- }
514
- }
515
- }
516
- }
517
- }else {
518
-
519
- if ( link != null && !file .exists ()){
520
-
521
- File parent = file .getParentFile ();
522
-
523
- if ( parent != null && parent .canWrite ()){
524
-
525
- File new_parent = parent .getName ().equals ( dnd_sf )?parent :FileUtil .newFile ( parent , dnd_sf );
526
-
527
- // use link name to handle incomplete file suffix if set
528
-
529
- File new_file = FileUtil .newFile ( new_parent , link .getName ());
530
-
531
- if ( new_file .equals ( link )){
532
-
533
- boolean ok ;
534
-
535
- try {
536
- String file_name = file .getName ();
537
-
538
- String prefix = dm_state .getAttribute ( DownloadManagerState .AT_DND_PREFIX );
539
-
540
- boolean prefix_removed = false ;
541
-
542
- if ( prefix != null && file_name .startsWith (prefix )){
543
-
544
- file_name = file_name .substring ( prefix .length ());
545
-
546
- prefix_removed = true ;
547
- }
548
-
549
- String incomp_ext = dm_state .getAttribute ( DownloadManagerState .AT_INCOMP_FILE_SUFFIX );
550
-
551
- if ( incomp_ext != null && incomp_ext .length () > 0 &&
552
- getDownloaded () != getLength ()){
553
-
554
- // retain the prefix if enabled and we have a suffix
555
-
556
- if ( prefix == null ){
557
-
558
- prefix = "" ;
559
- }
560
-
561
- File new_link = FileUtil .newFile ( file .getParentFile (), prefix + file_name + incomp_ext );
562
-
563
- dm_state .setFileLink ( file_index , file , new_link );
564
-
565
- cache_file .moveFile ( new_link , null );
566
-
567
- }else if ( prefix_removed ){
568
-
569
- File new_link = FileUtil .newFile ( file .getParentFile (), file_name );
570
-
571
- dm_state .setFileLink ( file_index , file , new_link );
572
-
573
- cache_file .moveFile ( new_link , null );
574
-
575
- }else {
576
-
577
- dm_state .setFileLink ( file_index , file , null );
578
-
579
- cache_file .moveFile ( file , null );
580
- }
581
-
582
- File [] files = new_parent .listFiles ();
583
-
584
- if ( files != null && files .length == 0 ){
585
-
586
- new_parent .delete ();
587
- }
588
-
589
- ok = true ;
590
-
591
- }catch ( Throwable e ){
592
-
593
- ok = false ;
594
-
595
- Debug .out ( e );
596
- }
597
-
598
- if ( !ok ){
599
-
600
- dm_state .setFileLink ( file_index , file , link );
601
- }
602
- }
603
- }
604
- }
605
- }
606
- }
609
+ }
610
+ }
611
+ }
612
+ }
613
+ }
614
+ }
607
615
}
608
616
}
609
617
0 commit comments