summaryrefslogtreecommitdiff
authordrw <drw>2003-04-23 01:04:02 (UTC)
committer drw <drw>2003-04-23 01:04:02 (UTC)
commit43b2c74f7d32ce9c744e4d79e62a92e0181604c3 (patch) (unidiff)
tree894049bfdc5724ea167f3dbc437cf0d18b93f3c1
parent509ac60dfd2e0829f56fb65407ddbe57f7668d70 (diff)
downloadopie-43b2c74f7d32ce9c744e4d79e62a92e0181604c3.zip
opie-43b2c74f7d32ce9c744e4d79e62a92e0181604c3.tar.gz
opie-43b2c74f7d32ce9c744e4d79e62a92e0181604c3.tar.bz2
Fix for bug #864 and some other code tweaks to reduce executable size
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/aqpkg/ipkg.cpp80
1 files changed, 46 insertions, 34 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp
index 7df643e..e906653 100644
--- a/noncore/settings/aqpkg/ipkg.cpp
+++ b/noncore/settings/aqpkg/ipkg.cpp
@@ -172,33 +172,41 @@ bool Ipkg :: runIpkg( )
172 emit outputText( "Finished" ); 172 emit outputText( "Finished" );
173 emit outputText( "" ); 173 emit outputText( "" );
174 return ret; 174 return ret;
175
176} 175}
177 176
178void Ipkg :: removeStatusEntry() 177void Ipkg :: removeStatusEntry()
179{ 178{
180 QString statusFile = destDir; 179 QString statusFile = destDir;
181 if ( statusFile.right( 1 ) != "/" ) 180 if ( statusFile.right( 1 ) != "/" )
182 statusFile += "/"; 181 statusFile.append( "/" );
183 statusFile += "usr/lib/ipkg/status"; 182 statusFile.append( "usr/lib/ipkg/status" );
184 QString outStatusFile = statusFile + ".tmp"; 183 QString outStatusFile = statusFile;
184 outStatusFile.append( ".tmp" );
185 185
186 emit outputText( "" ); 186 emit outputText( "" );
187 emit outputText( "Removing status entry..." ); 187 emit outputText( "Removing status entry..." );
188 emit outputText( QString( "status file - " )+ statusFile ); 188 QString tempstr = "status file - ";
189 emit outputText( QString( "package - " )+ package ); 189 tempstr.append( statusFile );
190 emit outputText( tempstr );
191 tempstr = "package - ";
192 tempstr.append( package );
193 emit outputText( tempstr );
190 194
191 ifstream in( statusFile ); 195 ifstream in( statusFile );
192 ofstream out( outStatusFile ); 196 ofstream out( outStatusFile );
193 if ( !in.is_open() ) 197 if ( !in.is_open() )
194 { 198 {
195 emit outputText( QString( "Couldn't open status file - " )+ statusFile ); 199 tempstr = "Couldn't open status file - ";
200 tempstr.append( statusFile );
201 emit outputText( tempstr );
196 return; 202 return;
197 } 203 }
198 204
199 if ( !out.is_open() ) 205 if ( !out.is_open() )
200 { 206 {
201 emit outputText( QString( "Couldn't create tempory status file - " )+ outStatusFile ); 207 tempstr = "Couldn't create tempory status file - ";
208 tempstr.append( outStatusFile );
209 emit outputText( tempstr );
202 return; 210 return;
203 } 211 }
204 212
@@ -234,14 +242,13 @@ void Ipkg :: removeStatusEntry()
234 } 242 }
235 243
236 lines.push_back( QString( line ) ); 244 lines.push_back( QString( line ) );
237// out << line << endl; 245 out << line << endl;
238 } while ( !in.eof() ); 246 } while ( !in.eof() );
239 247
240 // Write lines out 248 // Write lines out
241 vector<QString>::iterator it; 249 vector<QString>::iterator it;
242 for ( it = lines.begin() ; it != lines.end() ; ++it ) 250 for ( it = lines.begin() ; it != lines.end() ; ++it )
243 { 251 {
244 cout << "Writing " << (const char *)(*it) << endl;
245 out << (const char *)(*it) << endl; 252 out << (const char *)(*it) << endl;
246 } 253 }
247 254
@@ -279,17 +286,14 @@ int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ )
279 286
280 for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) 287 for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it )
281 { 288 {
282 qDebug( "%s ", (*it).latin1() );
283 *proc << (*it).latin1(); 289 *proc << (*it).latin1();
284 } 290 }
285 cout << endl;
286 291
287 // Start the process going 292 // Start the process going
288 finished = false; 293 finished = false;
289 if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) 294 if(!proc->start(OProcess::NotifyOnExit, OProcess::All))
290 { 295 {
291 emit outputText( QString( "Couldn't start ipkg process" ) ); 296 emit outputText( QString( "Couldn't start ipkg process" ) );
292 qDebug( "Couldn't start ipkg process!" );
293 } 297 }
294 298
295 // Now wait for it to finish 299 // Now wait for it to finish
@@ -299,8 +303,6 @@ int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ )
299 303
300void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) 304void Ipkg::commandStdout(OProcess*, char *buffer, int buflen)
301{ 305{
302 qDebug("received stdout %d bytes", buflen);
303
304 QString lineStr = buffer; 306 QString lineStr = buffer;
305 if ( lineStr[buflen-1] == '\n' ) 307 if ( lineStr[buflen-1] == '\n' )
306 buflen --; 308 buflen --;
@@ -320,15 +322,18 @@ void Ipkg::commandStdout(OProcess*, char *buffer, int buflen)
320 dependantPackages->append( package ); 322 dependantPackages->append( package );
321 } 323 }
322 } 324 }
325 else if ( option == "remove" && !( flags & FORCE_DEPENDS ) &&
326 lineStr.find( "is depended upon by packages:" ) != -1 )
327 {
328 // Ipkg should send this to STDERR, but doesn't - so trap here
329 error = true;
330 }
323 331
324 qDebug(lineStr);
325 buffer[0] = '\0'; 332 buffer[0] = '\0';
326} 333}
327 334
328void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) 335void Ipkg::commandStderr(OProcess*, char *buffer, int buflen)
329{ 336{
330 qDebug("received stderrt %d bytes", buflen);
331
332 QString lineStr = buffer; 337 QString lineStr = buffer;
333 if ( lineStr[buflen-1] == '\n' ) 338 if ( lineStr[buflen-1] == '\n' )
334 buflen --; 339 buflen --;
@@ -342,6 +347,7 @@ void Ipkg::processFinished()
342{ 347{
343 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file 348 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file
344 // to workaround an ipkg bug which stops reinstall to a different location 349 // to workaround an ipkg bug which stops reinstall to a different location
350
345 if ( !error && option == "remove" ) 351 if ( !error && option == "remove" )
346 removeStatusEntry(); 352 removeStatusEntry();
347 353
@@ -371,7 +377,6 @@ int Ipkg :: executeIpkgCommand( QString &cmd, const QString option )
371 fp = popen( (const char *) cmd, "r"); 377 fp = popen( (const char *) cmd, "r");
372 if ( fp == NULL ) 378 if ( fp == NULL )
373 { 379 {
374 cout << "Couldn't execute " << cmd << "! err = " << fp << endl;
375 QString text; 380 QString text;
376 text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); 381 text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd );
377 emit outputText( text ); 382 emit outputText( text );
@@ -441,23 +446,26 @@ void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, cons
441 446
442QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) 447QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir )
443{ 448{
444 QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list"; 449 QString packageFileDir = destDir;
450 packageFileDir.append( "/usr/lib/ipkg/info/" );
451 packageFileDir.append( packageFilename );
452 packageFileDir.append( ".list" );
445 QFile f( packageFileDir ); 453 QFile f( packageFileDir );
446 454
447 cout << "Try to open " << packageFileDir << endl;
448 if ( !f.open(IO_ReadOnly) ) 455 if ( !f.open(IO_ReadOnly) )
449 { 456 {
450 // Couldn't open from dest, try from / 457 // Couldn't open from dest, try from /
451 cout << "Could not open:" << packageFileDir << endl;
452 f.close(); 458 f.close();
453 459
454 packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; 460 packageFileDir = "/usr/lib/ipkg/info/";
461 packageFileDir.append( packageFilename );
462 packageFileDir.append( ".list" );
455 f.setName( packageFileDir ); 463 f.setName( packageFileDir );
456 qDebug( "Try to open %s", packageFileDir.latin1() );
457 if ( ! f.open(IO_ReadOnly) ) 464 if ( ! f.open(IO_ReadOnly) )
458 { 465 {
459 qDebug( "Could not open: %s", packageFileDir.latin1() ); 466 QString tempstr = "Could not open :";
460 emit outputText( QString( "Could not open :" ) + packageFileDir ); 467 tempstr.append( packageFileDir );
468 emit outputText( tempstr );
461 return (QStringList*)0; 469 return (QStringList*)0;
462 } 470 }
463 } 471 }
@@ -498,16 +506,17 @@ void Ipkg :: processFileList( const QStringList *fileList, const QString &destDi
498void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) 506void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir )
499{ 507{
500 508
501 QString sourceFile = baseDir + file; 509 QString sourceFile = baseDir;
510 sourceFile.append( file );
502 511
503 QString linkFile = destDir; 512 QString linkFile = destDir;
504 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) 513 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" )
505 { 514 {
506 linkFile += file.mid( 1 ); 515 linkFile.append( file.mid( 1 ) );
507 } 516 }
508 else 517 else
509 { 518 {
510 linkFile += file; 519 linkFile.append( file );
511 } 520 }
512 QString text; 521 QString text;
513 if ( createLinks ) 522 if ( createLinks )
@@ -519,7 +528,9 @@ void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const
519 QFileInfo f( linkFile ); 528 QFileInfo f( linkFile );
520 if ( !f.exists() ) 529 if ( !f.exists() )
521 { 530 {
522 emit outputText( QString( "Creating directory " ) + linkFile ); 531 QString tempstr = "Creating directory ";
532 tempstr.append( linkFile );
533 emit outputText( tempstr );
523 QDir d; 534 QDir d;
524 d.mkdir( linkFile, true ); 535 d.mkdir( linkFile, true );
525 } 536 }
@@ -531,7 +542,9 @@ void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const
531 { 542 {
532 int rc = symlink( sourceFile, linkFile ); 543 int rc = symlink( sourceFile, linkFile );
533 text = (rc == 0 ? "Linked " : "Failed to link "); 544 text = (rc == 0 ? "Linked " : "Failed to link ");
534 text += sourceFile + " to " + linkFile; 545 text.append( sourceFile );
546 text.append( " to " );
547 text.append( linkFile );
535 emit outputText( text ); 548 emit outputText( text );
536 } 549 }
537 } 550 }
@@ -546,7 +559,7 @@ void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const
546 bool rc = f.remove(); 559 bool rc = f.remove();
547 560
548 text = (rc ? "Removed " : "Failed to remove "); 561 text = (rc ? "Removed " : "Failed to remove ");
549 text += linkFile; 562 text.append( linkFile );
550 emit outputText( text ); 563 emit outputText( text );
551 } 564 }
552 else if ( f.isDir() ) 565 else if ( f.isDir() )
@@ -556,11 +569,10 @@ void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const
556 if ( rc ) 569 if ( rc )
557 { 570 {
558 text = (rc ? "Removed " : "Failed to remove "); 571 text = (rc ? "Removed " : "Failed to remove ");
559 text += linkFile; 572 text.append( linkFile );
560 emit outputText( text ); 573 emit outputText( text );
561 } 574 }
562 } 575 }
563 } 576 }
564 } 577 }
565
566} 578}