author | llornkcor <llornkcor> | 2004-07-28 04:04:02 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-07-28 04:04:02 (UTC) |
commit | 3237660c06d9920e4323cf6f1ea624a4f102892d (patch) (unidiff) | |
tree | f8f1f3adfb4d42b2f9ca1ddfd2b87a7a0664970d | |
parent | e98e9106df225b9e19a45a6f0e44193b1d018461 (diff) | |
download | opie-3237660c06d9920e4323cf6f1ea624a4f102892d.zip opie-3237660c06d9920e4323cf6f1ea624a4f102892d.tar.gz opie-3237660c06d9920e4323cf6f1ea624a4f102892d.tar.bz2 |
use safer method to set file perms after copy
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index d34f330..4628170 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp | |||
@@ -436,258 +436,258 @@ void AdvancedFm::move() { | |||
436 | QStringList curFileList = getPath(); | 436 | QStringList curFileList = getPath(); |
437 | if( curFileList.count() > 0) { | 437 | if( curFileList.count() > 0) { |
438 | QString curFile, destFile, item; | 438 | QString curFile, destFile, item; |
439 | 439 | ||
440 | QDir *thisDir = CurrentDir(); | 440 | QDir *thisDir = CurrentDir(); |
441 | QDir *thatDir = OtherDir(); | 441 | QDir *thatDir = OtherDir(); |
442 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 442 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
443 | item=(*it); | 443 | item=(*it); |
444 | QString destFile = thatDir->canonicalPath(); | 444 | QString destFile = thatDir->canonicalPath(); |
445 | 445 | ||
446 | if(destFile.right(1).find("/",0,TRUE) == -1) | 446 | if(destFile.right(1).find("/",0,TRUE) == -1) |
447 | destFile+="/"; | 447 | destFile+="/"; |
448 | destFile += item; | 448 | destFile += item; |
449 | // odebug << "Destination file is "+destFile << oendl; | 449 | // odebug << "Destination file is "+destFile << oendl; |
450 | 450 | ||
451 | curFile = thisDir->canonicalPath(); | 451 | curFile = thisDir->canonicalPath(); |
452 | if(curFile.right(1).find("/",0,TRUE) == -1) | 452 | if(curFile.right(1).find("/",0,TRUE) == -1) |
453 | curFile +="/"; | 453 | curFile +="/"; |
454 | curFile+= item; | 454 | curFile+= item; |
455 | // odebug << "CurrentFile file is " + curFile << oendl; | 455 | // odebug << "CurrentFile file is " + curFile << oendl; |
456 | 456 | ||
457 | if(QFileInfo(curFile).isDir()) { | 457 | if(QFileInfo(curFile).isDir()) { |
458 | moveDirectory( curFile, destFile ); | 458 | moveDirectory( curFile, destFile ); |
459 | rePopulate(); | 459 | rePopulate(); |
460 | return; | 460 | return; |
461 | } | 461 | } |
462 | 462 | ||
463 | QFile f( curFile); | 463 | QFile f( curFile); |
464 | if( f.exists()) { | 464 | if( f.exists()) { |
465 | if( !copyFile( curFile, destFile) ) { | 465 | if( !copyFile( curFile, destFile) ) { |
466 | QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); | 466 | QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); |
467 | return; | 467 | return; |
468 | } else | 468 | } else |
469 | QFile::remove(curFile); | 469 | QFile::remove(curFile); |
470 | } | 470 | } |
471 | } | 471 | } |
472 | 472 | ||
473 | } | 473 | } |
474 | rePopulate(); | 474 | rePopulate(); |
475 | setOtherTabCurrent(); | 475 | setOtherTabCurrent(); |
476 | } | 476 | } |
477 | 477 | ||
478 | bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { | 478 | bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { |
479 | int err = 0; | 479 | int err = 0; |
480 | if( copyDirectory( src, dest ) ) { QString cmd = "rm -rf " + src; | 480 | if( copyDirectory( src, dest ) ) { QString cmd = "rm -rf " + src; |
481 | err = system((const char*)cmd); | 481 | err = system((const char*)cmd); |
482 | } else | 482 | } else |
483 | err = -1; | 483 | err = -1; |
484 | 484 | ||
485 | if(err!=0) { | 485 | if(err!=0) { |
486 | QMessageBox::message(tr("Note"),tr("Could not move\n") + src); | 486 | QMessageBox::message(tr("Note"),tr("Could not move\n") + src); |
487 | return false; | 487 | return false; |
488 | } | 488 | } |
489 | return true; | 489 | return true; |
490 | } | 490 | } |
491 | 491 | ||
492 | bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { | 492 | bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { |
493 | 493 | ||
494 | QString cmd = "/bin/cp -fpR " + src + " " + dest; | 494 | QString cmd = "/bin/cp -fpR " + src + " " + dest; |
495 | owarn << cmd << oendl; | 495 | owarn << cmd << oendl; |
496 | int err = system( (const char *) cmd ); | 496 | int err = system( (const char *) cmd ); |
497 | if ( err != 0 ) { | 497 | if ( err != 0 ) { |
498 | QMessageBox::message("AdvancedFm", | 498 | QMessageBox::message("AdvancedFm", |
499 | tr( "Could not copy \n%1 \nto \n%2").arg( src ).arg( dest ) ); | 499 | tr( "Could not copy \n%1 \nto \n%2").arg( src ).arg( dest ) ); |
500 | return false; | 500 | return false; |
501 | } | 501 | } |
502 | 502 | ||
503 | return true; | 503 | return true; |
504 | } | 504 | } |
505 | 505 | ||
506 | 506 | ||
507 | bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { | 507 | bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { |
508 | 508 | ||
509 | 509 | ||
510 | if(QFileInfo(src).isDir()) { | 510 | if(QFileInfo(src).isDir()) { |
511 | if( copyDirectory( src, dest )) { | 511 | if( copyDirectory( src, dest )) { |
512 | setOtherTabCurrent(); | 512 | setOtherTabCurrent(); |
513 | populateView(); | 513 | populateView(); |
514 | return true; | 514 | return true; |
515 | } | 515 | } |
516 | else | 516 | else |
517 | return false; | 517 | return false; |
518 | } | 518 | } |
519 | 519 | ||
520 | 520 | ||
521 | bool success = true; | 521 | bool success = true; |
522 | struct stat status; | 522 | struct stat status; |
523 | QFile srcFile(src); | 523 | QFile srcFile(src); |
524 | QFile destFile(dest); | 524 | QFile destFile(dest); |
525 | int err=0; | 525 | int err=0; |
526 | int read_fd=0; | 526 | int read_fd=0; |
527 | int write_fd=0; | 527 | int write_fd=0; |
528 | struct stat stat_buf; | 528 | struct stat stat_buf; |
529 | off_t offset = 0; | 529 | off_t offset = 0; |
530 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { | 530 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { |
531 | // owarn << "open failed" << oendl; | 531 | // owarn << "open failed" << oendl; |
532 | return success = false; | 532 | return success = false; |
533 | } | 533 | } |
534 | read_fd = srcFile.handle(); | 534 | read_fd = srcFile.handle(); |
535 | if(read_fd != -1) { | 535 | if(read_fd != -1) { |
536 | fstat (read_fd, &stat_buf); | 536 | fstat (read_fd, &stat_buf); |
537 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { | 537 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { |
538 | // owarn << "destfile open failed" << oendl; | 538 | // owarn << "destfile open failed" << oendl; |
539 | return success = false; | 539 | return success = false; |
540 | } | 540 | } |
541 | write_fd = destFile.handle(); | 541 | write_fd = destFile.handle(); |
542 | if(write_fd != -1) { | 542 | if(write_fd != -1) { |
543 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); | 543 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); |
544 | if( err == -1) { | 544 | if( err == -1) { |
545 | QString msg; | 545 | QString msg; |
546 | switch(err) { | 546 | switch(err) { |
547 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; | 547 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; |
548 | case EINVAL: msg = "Descriptor is not valid or locked. "; | 548 | case EINVAL: msg = "Descriptor is not valid or locked. "; |
549 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; | 549 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; |
550 | case EIO: msg = "Unspecified error while reading from in_fd."; | 550 | case EIO: msg = "Unspecified error while reading from in_fd."; |
551 | }; | 551 | }; |
552 | success = false; | 552 | success = false; |
553 | // owarn << msg << oendl; | 553 | // owarn << msg << oendl; |
554 | } | 554 | } |
555 | } else { | 555 | } else { |
556 | success = false; | 556 | success = false; |
557 | } | 557 | } |
558 | } else { | 558 | } else { |
559 | success = false; | 559 | success = false; |
560 | } | 560 | } |
561 | srcFile.close(); | 561 | srcFile.close(); |
562 | destFile.close(); | 562 | destFile.close(); |
563 | // Set file permissions | 563 | // Set file permissions |
564 | if( stat( (const char *) src, &status ) == 0 ) { | 564 | if( stat( QFile::encodeName(src), &status ) == 0 ) { |
565 | chmod( (const char *) dest, status.st_mode ); | 565 | chmod( QFile::encodeName(dest), status.st_mode ); |
566 | } | 566 | } |
567 | 567 | ||
568 | return success; | 568 | return success; |
569 | } | 569 | } |
570 | 570 | ||
571 | void AdvancedFm::runCommand() { | 571 | void AdvancedFm::runCommand() { |
572 | if( !CurrentView()->currentItem()) return; | 572 | if( !CurrentView()->currentItem()) return; |
573 | QDir *thisDir = CurrentDir(); | 573 | QDir *thisDir = CurrentDir(); |
574 | 574 | ||
575 | QString curFile; | 575 | QString curFile; |
576 | curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); | 576 | curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); |
577 | 577 | ||
578 | InputDialog *fileDlg; | 578 | InputDialog *fileDlg; |
579 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | 579 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); |
580 | fileDlg->setInputText(curFile); | 580 | fileDlg->setInputText(curFile); |
581 | fileDlg->exec(); | 581 | fileDlg->exec(); |
582 | //QString command; | 582 | //QString command; |
583 | 583 | ||
584 | if( fileDlg->result() == 1 ) { | 584 | if( fileDlg->result() == 1 ) { |
585 | // odebug << fileDlg->LineEdit1->text() << oendl; | 585 | // odebug << fileDlg->LineEdit1->text() << oendl; |
586 | QStringList command; | 586 | QStringList command; |
587 | 587 | ||
588 | command << "/bin/sh"; | 588 | command << "/bin/sh"; |
589 | command << "-c"; | 589 | command << "-c"; |
590 | command << fileDlg->LineEdit1->text(); | 590 | command << fileDlg->LineEdit1->text(); |
591 | Output *outDlg; | 591 | Output *outDlg; |
592 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); | 592 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); |
593 | QPEApplication::execDialog( outDlg ); | 593 | QPEApplication::execDialog( outDlg ); |
594 | qApp->processEvents(); | 594 | qApp->processEvents(); |
595 | 595 | ||
596 | } | 596 | } |
597 | } | 597 | } |
598 | 598 | ||
599 | void AdvancedFm::runCommandStd() { | 599 | void AdvancedFm::runCommandStd() { |
600 | if( !CurrentView()->currentItem()) return; | 600 | if( !CurrentView()->currentItem()) return; |
601 | QString curFile; | 601 | QString curFile; |
602 | QDir *thisDir = CurrentDir(); | 602 | QDir *thisDir = CurrentDir(); |
603 | QListView *thisView = CurrentView(); | 603 | QListView *thisView = CurrentView(); |
604 | if( thisView->currentItem()) | 604 | if( thisView->currentItem()) |
605 | curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); | 605 | curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); |
606 | 606 | ||
607 | InputDialog *fileDlg; | 607 | InputDialog *fileDlg; |
608 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | 608 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); |
609 | fileDlg->setInputText(curFile); | 609 | fileDlg->setInputText(curFile); |
610 | fileDlg->exec(); | 610 | fileDlg->exec(); |
611 | 611 | ||
612 | if( fileDlg->result() == 1 ) { | 612 | if( fileDlg->result() == 1 ) { |
613 | qApp->processEvents(); | 613 | qApp->processEvents(); |
614 | startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); | 614 | startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); |
615 | } | 615 | } |
616 | } | 616 | } |
617 | 617 | ||
618 | void AdvancedFm::fileStatus() { | 618 | void AdvancedFm::fileStatus() { |
619 | if( !CurrentView()->currentItem()) return; | 619 | if( !CurrentView()->currentItem()) return; |
620 | QString curFile; | 620 | QString curFile; |
621 | curFile = CurrentView()->currentItem()->text(0); | 621 | curFile = CurrentView()->currentItem()->text(0); |
622 | 622 | ||
623 | QStringList command; | 623 | QStringList command; |
624 | command << "/bin/sh"; | 624 | command << "/bin/sh"; |
625 | command << "-c"; | 625 | command << "-c"; |
626 | command << "stat -l "+ curFile; | 626 | command << "stat -l "+ curFile; |
627 | 627 | ||
628 | Output *outDlg; | 628 | Output *outDlg; |
629 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); | 629 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); |
630 | QPEApplication::execDialog( outDlg ); | 630 | QPEApplication::execDialog( outDlg ); |
631 | qApp->processEvents(); | 631 | qApp->processEvents(); |
632 | } | 632 | } |
633 | 633 | ||
634 | 634 | ||
635 | void AdvancedFm::mkDir() { | 635 | void AdvancedFm::mkDir() { |
636 | makeDir(); | 636 | makeDir(); |
637 | } | 637 | } |
638 | 638 | ||
639 | void AdvancedFm::rn() { | 639 | void AdvancedFm::rn() { |
640 | renameIt(); | 640 | renameIt(); |
641 | } | 641 | } |
642 | 642 | ||
643 | void AdvancedFm::del() { | 643 | void AdvancedFm::del() { |
644 | doDelete(); | 644 | doDelete(); |
645 | } | 645 | } |
646 | 646 | ||
647 | void AdvancedFm::mkSym() { | 647 | void AdvancedFm::mkSym() { |
648 | QString cmd; | 648 | QString cmd; |
649 | QStringList curFileList = getPath(); | 649 | QStringList curFileList = getPath(); |
650 | if( curFileList.count() > 0) { | 650 | if( curFileList.count() > 0) { |
651 | QDir *thisDir = CurrentDir(); | 651 | QDir *thisDir = CurrentDir(); |
652 | QDir * thatDir = OtherDir(); | 652 | QDir * thatDir = OtherDir(); |
653 | 653 | ||
654 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 654 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
655 | 655 | ||
656 | QString destName = thatDir->canonicalPath()+"/"+(*it); | 656 | QString destName = thatDir->canonicalPath()+"/"+(*it); |
657 | if(destName.right(1) == "/") { | 657 | if(destName.right(1) == "/") { |
658 | destName = destName.left( destName.length() -1); | 658 | destName = destName.left( destName.length() -1); |
659 | } | 659 | } |
660 | 660 | ||
661 | QString curFile = thisDir->canonicalPath()+"/"+(*it); | 661 | QString curFile = thisDir->canonicalPath()+"/"+(*it); |
662 | 662 | ||
663 | if( curFile.right(1) == "/") { | 663 | if( curFile.right(1) == "/") { |
664 | curFile = curFile.left( curFile.length() -1); | 664 | curFile = curFile.left( curFile.length() -1); |
665 | } | 665 | } |
666 | 666 | ||
667 | cmd = "ln -s "+curFile+" "+destName; | 667 | cmd = "ln -s "+curFile+" "+destName; |
668 | // odebug << cmd << oendl; | 668 | // odebug << cmd << oendl; |
669 | startProcess( (const QString)cmd ); | 669 | startProcess( (const QString)cmd ); |
670 | } | 670 | } |
671 | rePopulate(); | 671 | rePopulate(); |
672 | setOtherTabCurrent(); | 672 | setOtherTabCurrent(); |
673 | } | 673 | } |
674 | } | 674 | } |
675 | 675 | ||
676 | void AdvancedFm::doBeam() { | 676 | void AdvancedFm::doBeam() { |
677 | Ir ir; | 677 | Ir ir; |
678 | if(!ir.supported()) { | 678 | if(!ir.supported()) { |
679 | } else { | 679 | } else { |
680 | QStringList curFileList = getPath(); | 680 | QStringList curFileList = getPath(); |
681 | if( curFileList.count() > 0) { | 681 | if( curFileList.count() > 0) { |
682 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 682 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
683 | QString curFile = (*it); | 683 | QString curFile = (*it); |
684 | QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile; | 684 | QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile; |
685 | if( curFilePath.right(1) == "/") { | 685 | if( curFilePath.right(1) == "/") { |
686 | curFilePath = curFilePath.left( curFilePath.length() -1); | 686 | curFilePath = curFilePath.left( curFilePath.length() -1); |
687 | } | 687 | } |
688 | Ir *file = new Ir(this, "IR"); | 688 | Ir *file = new Ir(this, "IR"); |
689 | connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished(Ir*))); | 689 | connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished(Ir*))); |
690 | file->send( curFilePath, curFile ); | 690 | file->send( curFilePath, curFile ); |
691 | } | 691 | } |
692 | } | 692 | } |
693 | } | 693 | } |