author | erik <erik> | 2007-01-10 17:27:56 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-10 17:27:56 (UTC) |
commit | d8e580a239ab84fbe063b2f3779d417598d5ca0a (patch) (side-by-side diff) | |
tree | a8b215c071088f167f011e51027b0a30ef3a5622 | |
parent | e7d3e1d0f3c75979c01ea6373ed3c80d0c986000 (diff) | |
download | opie-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.
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 2 |
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 @@ -457,257 +457,257 @@ void AdvancedFm::copySameDir() { } rePopulate(); } void AdvancedFm::moveTimer() { QTimer::singleShot(125,this,SLOT(move())); } void AdvancedFm::move() { QStringList curFileList = getPath(); if( curFileList.count() > 0) { QString curFile, destFile, item; QDir *thisDir = CurrentDir(); QDir *thatDir = OtherDir(); for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { item=(*it); QString destFile = thatDir->canonicalPath(); if(destFile.right(1).find("/",0,TRUE) == -1) destFile+="/"; destFile += item; // odebug << "Destination file is "+destFile << oendl; curFile = thisDir->canonicalPath(); if(curFile.right(1).find("/",0,TRUE) == -1) curFile +="/"; curFile+= item; // odebug << "CurrentFile file is " + curFile << oendl; if(QFileInfo(curFile).isDir()) { moveDirectory( curFile, destFile ); rePopulate(); return; } QFile f( destFile); if( f.exists()) { switch ( QMessageBox::warning(this,tr("File Exists!"), tr("<p>%1 already exists. Ok to overwrite?</P>").arg(destFile), tr("Yes"),tr("No"),0,0,1)) { case 0: break; case 1: return; break; default: return; break; }; } if( !copyFile( curFile, destFile) ) { QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg(curFile)); return; } else QFile::remove(curFile); } } rePopulate(); // setOtherTabCurrent(); } bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { int err = 0; if( copyDirectory( src, dest ) ) { QString cmd = "rm -rf " + src; err = system((const char*)cmd); } else err = -1; if(err!=0) { QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg( src)); return false; } return true; } bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { QString cmd = "/bin/cp -fpR " + src + " " + dest; owarn << cmd << oendl; int err = system( (const char *) cmd ); if ( err != 0 ) { QMessageBox::message("AdvancedFm", tr( "<p>Could not copy %1 to %2</p>").arg( src ).arg( dest ) ); return false; } return true; } bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { if(QFileInfo(src).isDir()) { if( copyDirectory( src, dest )) { // setOtherTabCurrent(); rePopulate(); return true; } else return false; } bool success = true; struct stat status; QFile srcFile(src); QFile destFile(dest); int err=0; int read_fd=0; int write_fd=0; struct stat stat_buf; off_t offset = 0; if(!srcFile.open( IO_ReadOnly|IO_Raw)) { // owarn << "open failed" << oendl; return success = false; } read_fd = srcFile.handle(); if(read_fd != -1) { fstat (read_fd, &stat_buf); if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { // owarn << "destfile open failed" << oendl; return success = false; } write_fd = destFile.handle(); if(write_fd != -1) { err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); if( err == -1) { QString msg; - switch(err) { + switch(errno) { case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; case EINVAL: msg = "Descriptor is not valid or locked. "; case ENOMEM: msg = "Insufficient memory to read from in_fd."; case EIO: msg = "Unspecified error while reading from in_fd."; }; success = false; // owarn << msg << oendl; } } else { success = false; } } else { success = false; } srcFile.close(); destFile.close(); // Set file permissions if( stat( QFile::encodeName(src), &status ) == 0 ) { chmod( QFile::encodeName(dest), status.st_mode ); } return success; } void AdvancedFm::runCommand() { if( !CurrentView()->currentItem()) return; QDir *thisDir = CurrentDir(); QString curFile; curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); fileDlg->setInputText(curFile); fileDlg->exec(); //QString command; if( fileDlg->result() == 1 ) { // odebug << fileDlg->LineEdit1->text() << oendl; QStringList command; command << "/bin/sh"; command << "-c"; command << fileDlg->LineEdit1->text(); Output *outDlg; outDlg = new Output( command, this, tr("AdvancedFm Output"), true); QPEApplication::execDialog( outDlg ); qApp->processEvents(); } } void AdvancedFm::runCommandStd() { if( !CurrentView()->currentItem()) return; QString curFile; QDir *thisDir = CurrentDir(); QListView *thisView = CurrentView(); if( thisView->currentItem()) curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); fileDlg->setInputText(curFile); fileDlg->exec(); if( fileDlg->result() == 1 ) { qApp->processEvents(); startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); } } void AdvancedFm::fileStatus() { if( !CurrentView()->currentItem()) return; QString curFile; curFile = CurrentView()->currentItem()->text(0); QFileInfo curFileInfo(curFile); FileInfoDialog *infoDlg = new FileInfoDialog(this); infoDlg->setCaption(tr("Info for %1").arg(curFile)); uint size = curFileInfo.size(); QString sizestr; if( size > 1048576 ) sizestr = tr("%1MB (%2 bytes)").arg(QString().sprintf("%.0f", size / 1048576.0)).arg(size); else if( size > 1024 ) sizestr = tr("%1kB (%2 bytes)").arg(QString().sprintf("%.0f", size / 1024.0)).arg(size); else sizestr = tr("%1 bytes").arg(size); infoDlg->sizeLabel->setText(sizestr); if(curFileInfo.isSymLink()) infoDlg->typeLabel->setText(tr("symbolic link")); else if(curFileInfo.isFile()) { if(curFileInfo.isExecutable()) infoDlg->typeLabel->setText(tr("executable file")); else infoDlg->typeLabel->setText(tr("file")); } else if(curFileInfo.isDir()) infoDlg->typeLabel->setText(tr("directory")); else infoDlg->typeLabel->setText(tr("unknown")); infoDlg->ownerLabel->setText( QString("%1 (%2)").arg(curFileInfo.owner()).arg(curFileInfo.ownerId()) ); infoDlg->groupLabel->setText( QString("%1 (%2)").arg(curFileInfo.group()).arg(curFileInfo.groupId()) ); infoDlg->lastReadLabel->setText( curFileInfo.lastRead().toString() ); infoDlg->lastModifiedLabel->setText( curFileInfo.lastModified().toString() ); QString perms; // User if(curFileInfo.permission(QFileInfo::ReadUser)) perms += "r"; else perms += "-"; if(curFileInfo.permission(QFileInfo::WriteUser)) perms += "w"; else perms += "-"; if(curFileInfo.permission(QFileInfo::ExeUser)) perms += "x"; else perms += "-"; // Group if(curFileInfo.permission(QFileInfo::ReadGroup)) |