author | drw <drw> | 2003-04-23 01:04:02 (UTC) |
---|---|---|
committer | drw <drw> | 2003-04-23 01:04:02 (UTC) |
commit | 43b2c74f7d32ce9c744e4d79e62a92e0181604c3 (patch) (unidiff) | |
tree | 894049bfdc5724ea167f3dbc437cf0d18b93f3c1 | |
parent | 509ac60dfd2e0829f56fb65407ddbe57f7668d70 (diff) | |
download | opie-43b2c74f7d32ce9c744e4d79e62a92e0181604c3.zip opie-43b2c74f7d32ce9c744e4d79e62a92e0181604c3.tar.gz opie-43b2c74f7d32ce9c744e4d79e62a92e0181604c3.tar.bz2 |
Fix for bug #864 and some other code tweaks to reduce executable size
-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 80 |
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 | |||
@@ -169,39 +169,47 @@ bool Ipkg :: runIpkg( ) | |||
169 | 169 | ||
170 | delete dependantPackages; | 170 | delete dependantPackages; |
171 | 171 | ||
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 | ||
178 | void Ipkg :: removeStatusEntry() | 177 | void 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 | ||
205 | char line[1001]; | 213 | char line[1001]; |
206 | char k[21]; | 214 | char k[21]; |
207 | char v[1001]; | 215 | char v[1001]; |
@@ -231,20 +239,19 @@ void Ipkg :: removeStatusEntry() | |||
231 | if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) | 239 | if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) |
232 | continue; | 240 | continue; |
233 | } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); | 241 | } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); |
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 | ||
248 | in.close(); | 255 | in.close(); |
249 | out.close(); | 256 | out.close(); |
250 | 257 | ||
@@ -276,34 +283,29 @@ int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ ) | |||
276 | 283 | ||
277 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), | 284 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), |
278 | this, SLOT(commandStderr(OProcess *, char *, int))); | 285 | this, SLOT(commandStderr(OProcess *, char *, int))); |
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 |
296 | while ( !finished ) | 300 | while ( !finished ) |
297 | qApp->processEvents(); | 301 | qApp->processEvents(); |
298 | } | 302 | } |
299 | 303 | ||
300 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) | 304 | void 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 --; |
307 | lineStr = lineStr.left( buflen ); | 309 | lineStr = lineStr.left( buflen ); |
308 | emit outputText( lineStr ); | 310 | emit outputText( lineStr ); |
309 | 311 | ||
@@ -317,21 +319,24 @@ void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) | |||
317 | int start = lineStr.find( " " ) + 1; | 319 | int start = lineStr.find( " " ) + 1; |
318 | int end = lineStr.find( " ", start ); | 320 | int end = lineStr.find( " ", start ); |
319 | QString *package = new QString( lineStr.mid( start, end-start ) ); | 321 | QString *package = new QString( lineStr.mid( start, end-start ) ); |
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 | ||
328 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) | 335 | void 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 --; |
335 | lineStr=lineStr.left( buflen ); | 340 | lineStr=lineStr.left( buflen ); |
336 | emit outputText( lineStr ); | 341 | emit outputText( lineStr ); |
337 | buffer[0] = '\0'; | 342 | buffer[0] = '\0'; |
@@ -339,12 +344,13 @@ void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) | |||
339 | } | 344 | } |
340 | 345 | ||
341 | void Ipkg::processFinished() | 346 | 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 | ||
348 | delete proc; | 354 | delete proc; |
349 | proc = 0; | 355 | proc = 0; |
350 | finished = true; | 356 | finished = true; |
@@ -368,13 +374,12 @@ int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) | |||
368 | QString lineStr, lineStrOld; | 374 | QString lineStr, lineStrOld; |
369 | int ret = false; | 375 | int ret = false; |
370 | 376 | ||
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 ); |
378 | } | 383 | } |
379 | else | 384 | else |
380 | { | 385 | { |
@@ -438,29 +443,32 @@ void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, cons | |||
438 | processFileList( fileList, destDir ); | 443 | processFileList( fileList, destDir ); |
439 | delete fileList; | 444 | delete fileList; |
440 | } | 445 | } |
441 | 446 | ||
442 | QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) | 447 | QStringList* 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 | } |
464 | QStringList *fileList = new QStringList(); | 472 | QStringList *fileList = new QStringList(); |
465 | QTextStream t( &f ); | 473 | QTextStream t( &f ); |
466 | while ( !t.eof() ) | 474 | while ( !t.eof() ) |
@@ -495,46 +503,51 @@ void Ipkg :: processFileList( const QStringList *fileList, const QString &destDi | |||
495 | } | 503 | } |
496 | } | 504 | } |
497 | 505 | ||
498 | void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) | 506 | void 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 ) |
514 | { | 523 | { |
515 | // If this file is a directory (ends with a /) and it doesn't exist, | 524 | // If this file is a directory (ends with a /) and it doesn't exist, |
516 | // we need to create it | 525 | // we need to create it |
517 | if ( file.right(1) == "/" ) | 526 | if ( file.right(1) == "/" ) |
518 | { | 527 | { |
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 | } |
526 | // else | 537 | // else |
527 | // emit outputText( QString( "Directory " ) + linkFile + " already exists" ); | 538 | // emit outputText( QString( "Directory " ) + linkFile + " already exists" ); |
528 | 539 | ||
529 | } | 540 | } |
530 | else | 541 | else |
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 | } |
538 | else | 551 | else |
539 | { | 552 | { |
540 | QFileInfo f( linkFile ); | 553 | QFileInfo f( linkFile ); |
@@ -543,24 +556,23 @@ void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const | |||
543 | if ( f.isFile() ) | 556 | if ( f.isFile() ) |
544 | { | 557 | { |
545 | QFile f( linkFile ); | 558 | QFile f( linkFile ); |
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() ) |
553 | { | 566 | { |
554 | QDir d; | 567 | QDir d; |
555 | bool rc = d.rmdir( linkFile, true ); | 568 | bool rc = d.rmdir( linkFile, true ); |
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 | } |