author | llornkcor <llornkcor> | 2003-04-15 12:11:22 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-04-15 12:11:22 (UTC) |
commit | d1b5bf7eeb365282356db49f49331c82f234086c (patch) (unidiff) | |
tree | 476c3a1bc4c19ab25c3820619e1fa55e8ce8f0a2 | |
parent | d0de397e46581f6ed5fcfad320b2b61be3858c5d (diff) | |
download | opie-d1b5bf7eeb365282356db49f49331c82f234086c.zip opie-d1b5bf7eeb365282356db49f49331c82f234086c.tar.gz opie-d1b5bf7eeb365282356db49f49331c82f234086c.tar.bz2 |
changed copy method from clunky to using sendfile(). should be 1. faster and 2. require less memory
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 71 |
1 files changed, 48 insertions, 23 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index 93203cd..eae86a4 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp | |||
@@ -41,13 +41,14 @@ | |||
41 | #include <qlistview.h> | 41 | #include <qlistview.h> |
42 | 42 | ||
43 | #include <stdlib.h> | 43 | #include <stdlib.h> |
44 | #include <unistd.h> | 44 | #include <unistd.h> |
45 | #include <sys/stat.h> | 45 | #include <sys/stat.h> |
46 | #include <dirent.h> | 46 | #include <dirent.h> |
47 | 47 | #include <sys/sendfile.h> | |
48 | #include <fcntl.h> | ||
48 | 49 | ||
49 | void AdvancedFm::doDirChange() | 50 | void AdvancedFm::doDirChange() |
50 | { | 51 | { |
51 | ListClicked( CurrentView()->currentItem()); | 52 | ListClicked( CurrentView()->currentItem()); |
52 | } | 53 | } |
53 | 54 | ||
@@ -309,13 +310,13 @@ void AdvancedFm::copy() | |||
309 | bool doMsg=true; | 310 | bool doMsg=true; |
310 | int count=curFileList.count(); | 311 | int count=curFileList.count(); |
311 | if( count > 0) { | 312 | if( count > 0) { |
312 | if(count > 1 ){ | 313 | if(count > 1 ){ |
313 | QString msg; | 314 | QString msg; |
314 | msg=tr("Really copy\n%1 files?").arg(count); | 315 | msg=tr("Really copy\n%1 files?").arg(count); |
315 | switch ( QMessageBox::warning(this,tr("Delete"),msg | 316 | switch ( QMessageBox::warning(this,tr("Copy"),msg |
316 | ,tr("Yes"),tr("No"),0,0,1) ) | 317 | ,tr("Yes"),tr("No"),0,0,1) ) |
317 | { | 318 | { |
318 | case 0: | 319 | case 0: |
319 | doMsg=false; | 320 | doMsg=false; |
320 | break; | 321 | break; |
321 | case 1: | 322 | case 1: |
@@ -517,39 +518,63 @@ void AdvancedFm::move() | |||
517 | populateView(); | 518 | populateView(); |
518 | // populateLocalView(); | 519 | // populateLocalView(); |
519 | } | 520 | } |
520 | 521 | ||
521 | bool AdvancedFm::copyFile( const QString & src, const QString & dest ) | 522 | bool AdvancedFm::copyFile( const QString & src, const QString & dest ) |
522 | { | 523 | { |
523 | char bf[ 50000 ]; | 524 | // char bf[ 50000 ]; |
524 | int bytesRead; | 525 | // int bytesRead; |
525 | bool success = TRUE; | 526 | bool success = true; |
526 | struct stat status; | 527 | struct stat status; |
527 | 528 | ||
528 | QFile s( src ); | 529 | // QFile s( src ); |
529 | QFile d( dest ); | 530 | // QFile d( dest ); |
530 | 531 | ||
531 | if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) ) | 532 | int read_fd=0; |
532 | { | 533 | int write_fd=0; |
533 | while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) ) | 534 | struct stat stat_buf; |
534 | { | 535 | off_t offset = 0; |
535 | if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ | 536 | read_fd = ::open(src.latin1(), O_RDONLY); |
536 | success = FALSE; | 537 | if(read_fd != -1) { |
537 | break; | 538 | fstat (read_fd, &stat_buf); |
538 | } | 539 | write_fd = ::open(dest.latin1(), O_WRONLY | O_CREAT, stat_buf.st_mode); |
539 | } | 540 | if(write_fd != -1) { |
540 | if( success && (bytesRead > 0) ) | 541 | if(sendfile(write_fd, read_fd, &offset, stat_buf.st_size) == -1) { |
541 | { | 542 | success = false; |
542 | d.writeBlock( bf, bytesRead ); | ||
543 | } | 543 | } |
544 | } else { | ||
545 | success = false; | ||
544 | } | 546 | } |
545 | else | 547 | } else { |
546 | { | 548 | success = false; |
547 | success = FALSE; | ||
548 | } | 549 | } |
549 | 550 | ||
551 | ::close (read_fd); | ||
552 | ::close (write_fd); | ||
553 | |||
554 | |||
555 | // if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) ) | ||
556 | // { | ||
557 | // while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) ) | ||
558 | // { | ||
559 | // if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ | ||
560 | // success = FALSE; | ||
561 | // break; | ||
562 | // } | ||
563 | // } | ||
564 | // if( success && (bytesRead > 0) ) | ||
565 | // { | ||
566 | // d.writeBlock( bf, bytesRead ); | ||
567 | // } | ||
568 | |||
569 | // } | ||
570 | // else | ||
571 | // { | ||
572 | // success = FALSE; | ||
573 | // } | ||
574 | |||
550 | // Set file permissions | 575 | // Set file permissions |
551 | if( stat( (const char *) src, &status ) == 0 ) | 576 | if( stat( (const char *) src, &status ) == 0 ) |
552 | { | 577 | { |
553 | chmod( (const char *) dest, status.st_mode ); | 578 | chmod( (const char *) dest, status.st_mode ); |
554 | } | 579 | } |
555 | 580 | ||