summaryrefslogtreecommitdiff
authorerik <erik>2007-01-10 17:27:56 (UTC)
committer erik <erik>2007-01-10 17:27:56 (UTC)
commitd8e580a239ab84fbe063b2f3779d417598d5ca0a (patch) (unidiff)
treea8b215c071088f167f011e51027b0a30ef3a5622
parente7d3e1d0f3c75979c01ea6373ed3c80d0c986000 (diff)
downloadopie-d8e580a239ab84fbe063b2f3779d417598d5ca0a.zip
opie-d8e580a239ab84fbe063b2f3779d417598d5ca0a.tar.gz
opie-d8e580a239ab84fbe063b2f3779d417598d5ca0a.tar.bz2
BUG: The case statement was using err to figure out what to say about
why sendfile didn't work. Since err is only the return value of sendfile this meant that it never reported the right thing because it can only be -1 at this point. What the author probably wanted to do was look at errno since that is what the man page says will have the real error info. FIX: Switch the case statement to use errno.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/advancedfm/advancedfmMenu.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp
index 9181810..3986b1f 100644
--- a/noncore/apps/advancedfm/advancedfmMenu.cpp
+++ b/noncore/apps/advancedfm/advancedfmMenu.cpp
@@ -489,193 +489,193 @@ void AdvancedFm::move() {
489 moveDirectory( curFile, destFile ); 489 moveDirectory( curFile, destFile );
490 rePopulate(); 490 rePopulate();
491 return; 491 return;
492 } 492 }
493 QFile f( destFile); 493 QFile f( destFile);
494 if( f.exists()) { 494 if( f.exists()) {
495 switch ( QMessageBox::warning(this,tr("File Exists!"), 495 switch ( QMessageBox::warning(this,tr("File Exists!"),
496 tr("<p>%1 already exists. Ok to overwrite?</P>").arg(destFile), 496 tr("<p>%1 already exists. Ok to overwrite?</P>").arg(destFile),
497 tr("Yes"),tr("No"),0,0,1)) { 497 tr("Yes"),tr("No"),0,0,1)) {
498 case 0: 498 case 0:
499 break; 499 break;
500 case 1: 500 case 1:
501 return; 501 return;
502 break; 502 break;
503 default: 503 default:
504 return; 504 return;
505 break; 505 break;
506 }; 506 };
507 } 507 }
508 if( !copyFile( curFile, destFile) ) { 508 if( !copyFile( curFile, destFile) ) {
509 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg(curFile)); 509 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg(curFile));
510 return; 510 return;
511 } else 511 } else
512 QFile::remove(curFile); 512 QFile::remove(curFile);
513 } 513 }
514 } 514 }
515 rePopulate(); 515 rePopulate();
516 //setOtherTabCurrent(); 516 //setOtherTabCurrent();
517} 517}
518 518
519bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { 519bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) {
520 int err = 0; 520 int err = 0;
521 if( copyDirectory( src, dest ) ) { 521 if( copyDirectory( src, dest ) ) {
522 QString cmd = "rm -rf " + src; 522 QString cmd = "rm -rf " + src;
523 err = system((const char*)cmd); 523 err = system((const char*)cmd);
524 } else 524 } else
525 err = -1; 525 err = -1;
526 526
527 if(err!=0) { 527 if(err!=0) {
528 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg( src)); 528 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg( src));
529 return false; 529 return false;
530 } 530 }
531 return true; 531 return true;
532} 532}
533 533
534bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { 534bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) {
535 535
536 QString cmd = "/bin/cp -fpR " + src + " " + dest; 536 QString cmd = "/bin/cp -fpR " + src + " " + dest;
537 owarn << cmd << oendl; 537 owarn << cmd << oendl;
538 int err = system( (const char *) cmd ); 538 int err = system( (const char *) cmd );
539 if ( err != 0 ) { 539 if ( err != 0 ) {
540 QMessageBox::message("AdvancedFm", tr( "<p>Could not copy %1 to %2</p>").arg( src ).arg( dest ) ); 540 QMessageBox::message("AdvancedFm", tr( "<p>Could not copy %1 to %2</p>").arg( src ).arg( dest ) );
541 return false; 541 return false;
542 } 542 }
543 543
544 return true; 544 return true;
545} 545}
546 546
547 547
548bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { 548bool AdvancedFm::copyFile( const QString & src, const QString & dest ) {
549 if(QFileInfo(src).isDir()) { 549 if(QFileInfo(src).isDir()) {
550 if( copyDirectory( src, dest )) { 550 if( copyDirectory( src, dest )) {
551 // setOtherTabCurrent(); 551 // setOtherTabCurrent();
552 rePopulate(); 552 rePopulate();
553 return true; 553 return true;
554 } 554 }
555 else 555 else
556 return false; 556 return false;
557 } 557 }
558 558
559 559
560 bool success = true; 560 bool success = true;
561 struct stat status; 561 struct stat status;
562 QFile srcFile(src); 562 QFile srcFile(src);
563 QFile destFile(dest); 563 QFile destFile(dest);
564 int err=0; 564 int err=0;
565 int read_fd=0; 565 int read_fd=0;
566 int write_fd=0; 566 int write_fd=0;
567 struct stat stat_buf; 567 struct stat stat_buf;
568 off_t offset = 0; 568 off_t offset = 0;
569 if(!srcFile.open( IO_ReadOnly|IO_Raw)) { 569 if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
570// owarn << "open failed" << oendl; 570// owarn << "open failed" << oendl;
571 return success = false; 571 return success = false;
572 } 572 }
573 read_fd = srcFile.handle(); 573 read_fd = srcFile.handle();
574 if(read_fd != -1) { 574 if(read_fd != -1) {
575 fstat (read_fd, &stat_buf); 575 fstat (read_fd, &stat_buf);
576 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { 576 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) {
577// owarn << "destfile open failed" << oendl; 577// owarn << "destfile open failed" << oendl;
578 return success = false; 578 return success = false;
579 } 579 }
580 write_fd = destFile.handle(); 580 write_fd = destFile.handle();
581 if(write_fd != -1) { 581 if(write_fd != -1) {
582 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); 582 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
583 if( err == -1) { 583 if( err == -1) {
584 QString msg; 584 QString msg;
585 switch(err) { 585 switch(errno) {
586 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; 586 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
587 case EINVAL: msg = "Descriptor is not valid or locked. "; 587 case EINVAL: msg = "Descriptor is not valid or locked. ";
588 case ENOMEM: msg = "Insufficient memory to read from in_fd."; 588 case ENOMEM: msg = "Insufficient memory to read from in_fd.";
589 case EIO: msg = "Unspecified error while reading from in_fd."; 589 case EIO: msg = "Unspecified error while reading from in_fd.";
590 }; 590 };
591 success = false; 591 success = false;
592// owarn << msg << oendl; 592// owarn << msg << oendl;
593 } 593 }
594 } else { 594 } else {
595 success = false; 595 success = false;
596 } 596 }
597 } else { 597 } else {
598 success = false; 598 success = false;
599 } 599 }
600 srcFile.close(); 600 srcFile.close();
601 destFile.close(); 601 destFile.close();
602 // Set file permissions 602 // Set file permissions
603 if( stat( QFile::encodeName(src), &status ) == 0 ) { 603 if( stat( QFile::encodeName(src), &status ) == 0 ) {
604 chmod( QFile::encodeName(dest), status.st_mode ); 604 chmod( QFile::encodeName(dest), status.st_mode );
605 } 605 }
606 606
607 return success; 607 return success;
608} 608}
609 609
610void AdvancedFm::runCommand() { 610void AdvancedFm::runCommand() {
611 if( !CurrentView()->currentItem()) return; 611 if( !CurrentView()->currentItem()) return;
612 QDir *thisDir = CurrentDir(); 612 QDir *thisDir = CurrentDir();
613 613
614 QString curFile; 614 QString curFile;
615 curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); 615 curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0);
616 616
617 InputDialog *fileDlg; 617 InputDialog *fileDlg;
618 fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); 618 fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0);
619 fileDlg->setInputText(curFile); 619 fileDlg->setInputText(curFile);
620 fileDlg->exec(); 620 fileDlg->exec();
621 //QString command; 621 //QString command;
622 622
623 if( fileDlg->result() == 1 ) { 623 if( fileDlg->result() == 1 ) {
624// odebug << fileDlg->LineEdit1->text() << oendl; 624// odebug << fileDlg->LineEdit1->text() << oendl;
625 QStringList command; 625 QStringList command;
626 626
627 command << "/bin/sh"; 627 command << "/bin/sh";
628 command << "-c"; 628 command << "-c";
629 command << fileDlg->LineEdit1->text(); 629 command << fileDlg->LineEdit1->text();
630 Output *outDlg; 630 Output *outDlg;
631 outDlg = new Output( command, this, tr("AdvancedFm Output"), true); 631 outDlg = new Output( command, this, tr("AdvancedFm Output"), true);
632 QPEApplication::execDialog( outDlg ); 632 QPEApplication::execDialog( outDlg );
633 qApp->processEvents(); 633 qApp->processEvents();
634 634
635 } 635 }
636} 636}
637 637
638void AdvancedFm::runCommandStd() { 638void AdvancedFm::runCommandStd() {
639 if( !CurrentView()->currentItem()) return; 639 if( !CurrentView()->currentItem()) return;
640 QString curFile; 640 QString curFile;
641 QDir *thisDir = CurrentDir(); 641 QDir *thisDir = CurrentDir();
642 QListView *thisView = CurrentView(); 642 QListView *thisView = CurrentView();
643 if( thisView->currentItem()) 643 if( thisView->currentItem())
644 curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); 644 curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0);
645 645
646 InputDialog *fileDlg; 646 InputDialog *fileDlg;
647 fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); 647 fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0);
648 fileDlg->setInputText(curFile); 648 fileDlg->setInputText(curFile);
649 fileDlg->exec(); 649 fileDlg->exec();
650 650
651 if( fileDlg->result() == 1 ) { 651 if( fileDlg->result() == 1 ) {
652 qApp->processEvents(); 652 qApp->processEvents();
653 startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); 653 startProcess( (const QString)fileDlg->LineEdit1->text().latin1());
654 } 654 }
655} 655}
656 656
657void AdvancedFm::fileStatus() { 657void AdvancedFm::fileStatus() {
658 if( !CurrentView()->currentItem()) return; 658 if( !CurrentView()->currentItem()) return;
659 659
660 QString curFile; 660 QString curFile;
661 curFile = CurrentView()->currentItem()->text(0); 661 curFile = CurrentView()->currentItem()->text(0);
662 662
663 QFileInfo curFileInfo(curFile); 663 QFileInfo curFileInfo(curFile);
664 664
665 FileInfoDialog *infoDlg = new FileInfoDialog(this); 665 FileInfoDialog *infoDlg = new FileInfoDialog(this);
666 infoDlg->setCaption(tr("Info for %1").arg(curFile)); 666 infoDlg->setCaption(tr("Info for %1").arg(curFile));
667 667
668 uint size = curFileInfo.size(); 668 uint size = curFileInfo.size();
669 QString sizestr; 669 QString sizestr;
670 if( size > 1048576 ) 670 if( size > 1048576 )
671 sizestr = tr("%1MB (%2 bytes)").arg(QString().sprintf("%.0f", size / 1048576.0)).arg(size); 671 sizestr = tr("%1MB (%2 bytes)").arg(QString().sprintf("%.0f", size / 1048576.0)).arg(size);
672 else if( size > 1024 ) 672 else if( size > 1024 )
673 sizestr = tr("%1kB (%2 bytes)").arg(QString().sprintf("%.0f", size / 1024.0)).arg(size); 673 sizestr = tr("%1kB (%2 bytes)").arg(QString().sprintf("%.0f", size / 1024.0)).arg(size);
674 else 674 else
675 sizestr = tr("%1 bytes").arg(size); 675 sizestr = tr("%1 bytes").arg(size);
676 676
677 infoDlg->sizeLabel->setText(sizestr); 677 infoDlg->sizeLabel->setText(sizestr);
678 678
679 if(curFileInfo.isSymLink()) 679 if(curFileInfo.isSymLink())
680 infoDlg->typeLabel->setText(tr("symbolic link")); 680 infoDlg->typeLabel->setText(tr("symbolic link"));
681 else if(curFileInfo.isFile()) { 681 else if(curFileInfo.isFile()) {