summaryrefslogtreecommitdiff
path: root/apps/plugins/splitedit.c
diff options
context:
space:
mode:
authorDan Everton <dan@iocaine.org>2006-03-28 17:01:02 +0000
committerDan Everton <dan@iocaine.org>2006-03-28 17:01:02 +0000
commit6246242155105526602096d94753aec8d43453c9 (patch)
tree3228e15c133437c802ffccb634b14565d0e4c3a1 /apps/plugins/splitedit.c
parentcd88582478749aa09000361b9f4e48e73b5b307e (diff)
downloadrockbox-6246242155105526602096d94753aec8d43453c9.tar.gz
rockbox-6246242155105526602096d94753aec8d43453c9.zip
Fail gracefully if write fails (i.e. disk space runs out) during copy in splitedit plugin. Users can now also press the 'quit' button to abort splitting.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9317 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/splitedit.c')
-rw-r--r--apps/plugins/splitedit.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/apps/plugins/splitedit.c b/apps/plugins/splitedit.c
index d0fd4e161b..de7e2380a9 100644
--- a/apps/plugins/splitedit.c
+++ b/apps/plugins/splitedit.c
@@ -562,13 +562,14 @@ static void generateFileName(char* file_name, int part_no)
562 * Copy bytes from src to dest while displaying a progressbar. 562 * Copy bytes from src to dest while displaying a progressbar.
563 * The files must be already open. 563 * The files must be already open.
564 */ 564 */
565static void copy_file( 565static int copy_file(
566 int dest, 566 int dest,
567 int src, 567 int src,
568 unsigned int bytes, 568 unsigned int bytes,
569 int prg_y, 569 int prg_y,
570 int prg_h) 570 int prg_h)
571{ 571{
572 long button;
572 unsigned char *buffer; 573 unsigned char *buffer;
573 unsigned int i = 0; 574 unsigned int i = 0;
574 ssize_t bytes_read = 1; /* ensure the for loop is executed */ 575 ssize_t bytes_read = 1; /* ensure the for loop is executed */
@@ -583,9 +584,27 @@ static void copy_file(
583 bytes_read = rb->read(src, buffer, bytes_to_read); 584 bytes_read = rb->read(src, buffer, bytes_to_read);
584 bytes_written = rb->write(dest, buffer, bytes_read); 585 bytes_written = rb->write(dest, buffer, bytes_read);
585 586
587 if (bytes_written < 0) {
588 rb->splash(0, true, "Write failed in copy. Error %d", errno);
589 rb->button_get(true);
590 rb->button_get(true);
591 return -1;
592 }
593
594 button = rb->button_get(false);
595
596 if (button == SPLITEDIT_QUIT) {
597 rb->splash(0, true, "Aborting copy.");
598 rb->button_get(true);
599 rb->button_get(true);
600 return -1;
601 }
602
586 rb->scrollbar(0, prg_y, LCD_WIDTH, prg_h, bytes, 0, i, HORIZONTAL); 603 rb->scrollbar(0, prg_y, LCD_WIDTH, prg_h, bytes, 0, i, HORIZONTAL);
587 rb->lcd_update_rect(0, prg_y, LCD_WIDTH, prg_h); 604 rb->lcd_update_rect(0, prg_y, LCD_WIDTH, prg_h);
588 } 605 }
606
607 return 0;
589} 608}
590 609
591/** 610/**
@@ -659,7 +678,7 @@ static int save(
659 file1 = rb->open (file_name1, O_WRONLY | O_CREAT); 678 file1 = rb->open (file_name1, O_WRONLY | O_CREAT);
660 if (file1 >= 0) 679 if (file1 >= 0)
661 { 680 {
662 copy_file(file1, src_file, end, y*2 + 1, y -1); 681 int rc = copy_file(file1, src_file, end, y*2 + 1, y -1);
663 close_stat = rb->close(file1); 682 close_stat = rb->close(file1);
664 683
665 if (close_stat != 0) 684 if (close_stat != 0)
@@ -668,6 +687,11 @@ static int save(
668 "failed closing file1: error %d", close_stat); 687 "failed closing file1: error %d", close_stat);
669 rb->button_get(true); 688 rb->button_get(true);
670 rb->button_get(true); 689 rb->button_get(true);
690 } else {
691 /* If there was an error, cleanup */
692 if (rc) {
693 rb->remove(file_name1);
694 }
671 } 695 }
672 } 696 }
673 else 697 else
@@ -707,6 +731,11 @@ static int save(
707 "failed: closing file2: error %d", close_stat); 731 "failed: closing file2: error %d", close_stat);
708 rb->button_get(true); 732 rb->button_get(true);
709 rb->button_get(true); 733 rb->button_get(true);
734 } else {
735 /* If there was an error, cleanup */
736 if (rc) {
737 rb->remove(file_name2);
738 }
710 } 739 }
711 } 740 }
712 else 741 else