summaryrefslogtreecommitdiff
authordrw <drw>2004-07-31 16:57:09 (UTC)
committer drw <drw>2004-07-31 16:57:09 (UTC)
commitbc85059dbd265feb3424215a2c1a4818af7d069e (patch) (unidiff)
tree6200d0188ac374741fdcd0019e68227a5a966892
parentb099a3dd18571fcbd5b1211f18ac111ec39f9ce8 (diff)
downloadopie-bc85059dbd265feb3424215a2c1a4818af7d069e.zip
opie-bc85059dbd265feb3424215a2c1a4818af7d069e.tar.gz
opie-bc85059dbd265feb3424215a2c1a4818af7d069e.tar.bz2
Read ipkg.conf even when /etc/ipkg does not exist, found by Bernardo...thanks\!
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/packagemanager/oipkg.cpp114
1 files changed, 57 insertions, 57 deletions
diff --git a/noncore/settings/packagemanager/oipkg.cpp b/noncore/settings/packagemanager/oipkg.cpp
index 87a30bb..eca5861 100644
--- a/noncore/settings/packagemanager/oipkg.cpp
+++ b/noncore/settings/packagemanager/oipkg.cpp
@@ -280,295 +280,295 @@ OPackageList *OIpkg::installedPackages( const QString &destName, const QString &
280 280
281 // Build new server list (caller is responsible for deleting) 281 // Build new server list (caller is responsible for deleting)
282 OPackageList *pl = new OPackageList; 282 OPackageList *pl = new OPackageList;
283 283
284 // Open status file 284 // Open status file
285 QString path = destPath; 285 QString path = destPath;
286 if ( path.right( 1 ) != "/" ) 286 if ( path.right( 1 ) != "/" )
287 path.append( "/" ); 287 path.append( "/" );
288 path.append( IPKG_STATUS_PATH ); 288 path.append( IPKG_STATUS_PATH );
289 289
290 QFile f( path ); 290 QFile f( path );
291 if ( !f.open( IO_ReadOnly ) ) 291 if ( !f.open( IO_ReadOnly ) )
292 return NULL; 292 return NULL;
293 QTextStream t( &f ); 293 QTextStream t( &f );
294 294
295 // Process all information in status file 295 // Process all information in status file
296 bool newPackage = false; 296 bool newPackage = false;
297 QString line = t.readLine(); 297 QString line = t.readLine();
298 QString name; 298 QString name;
299 QString version; 299 QString version;
300 QString status; 300 QString status;
301 301
302 while ( !t.eof() ) 302 while ( !t.eof() )
303 { 303 {
304 // Determine key/value pair 304 // Determine key/value pair
305 int pos = line.find( ':', 0 ); 305 int pos = line.find( ':', 0 );
306 QString key; 306 QString key;
307 if ( pos > -1 ) 307 if ( pos > -1 )
308 key = line.mid( 0, pos ); 308 key = line.mid( 0, pos );
309 else 309 else
310 key = QString::null; 310 key = QString::null;
311 QString value = line.mid( pos+2, line.length()-pos ); 311 QString value = line.mid( pos+2, line.length()-pos );
312 312
313 // Allocate new package and insert into list 313 // Allocate new package and insert into list
314 if ( newPackage && !key.isEmpty() ) 314 if ( newPackage && !key.isEmpty() )
315 { 315 {
316 // Add to list only if it has a valid name and is installed 316 // Add to list only if it has a valid name and is installed
317 if ( !name.isNull() && status.contains( " installed" ) ) 317 if ( !name.isNull() && status.contains( " installed" ) )
318 { 318 {
319 pl->append( new OPackage( name, QString::null, version, QString::null, destName ) ); 319 pl->append( new OPackage( name, QString::null, version, QString::null, destName ) );
320 name = QString::null; 320 name = QString::null;
321 version = QString::null; 321 version = QString::null;
322 status = QString::null; 322 status = QString::null;
323 323
324 newPackage = false; 324 newPackage = false;
325 } 325 }
326 } 326 }
327 327
328 // Update package data 328 // Update package data
329 if ( key == "Package" ) 329 if ( key == "Package" )
330 name = value; 330 name = value;
331 else if ( key == "Version" ) 331 else if ( key == "Version" )
332 version = value; 332 version = value;
333 else if ( key == "Status" ) 333 else if ( key == "Status" )
334 status = value; 334 status = value;
335 else if ( key.isEmpty() && value.isEmpty() ) 335 else if ( key.isEmpty() && value.isEmpty() )
336 newPackage = true; 336 newPackage = true;
337 337
338 // Skip past all description lines 338 // Skip past all description lines
339 if ( key == "Description" ) 339 if ( key == "Description" )
340 { 340 {
341 line = t.readLine(); 341 line = t.readLine();
342 while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) 342 while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() )
343 line = t.readLine(); 343 line = t.readLine();
344 } 344 }
345 else 345 else
346 line = t.readLine(); 346 line = t.readLine();
347 } 347 }
348 348
349 f.close(); 349 f.close();
350 350
351 return pl; 351 return pl;
352} 352}
353 353
354bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, const QString &destination, 354bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, const QString &destination,
355 const QObject *receiver, const char *slotOutput, bool rawOutput ) 355 const QObject *receiver, const char *slotOutput, bool rawOutput )
356{ 356{
357 if ( command == OPackage::NotDefined ) 357 if ( command == OPackage::NotDefined )
358 return false; 358 return false;
359 359
360 // Set ipkg run-time options/arguments 360 // Set ipkg run-time options/arguments
361 m_ipkgArgs.force_depends = ( m_ipkgExecOptions & FORCE_DEPENDS ); 361 m_ipkgArgs.force_depends = ( m_ipkgExecOptions & FORCE_DEPENDS );
362 m_ipkgArgs.force_reinstall = ( m_ipkgExecOptions & FORCE_REINSTALL ); 362 m_ipkgArgs.force_reinstall = ( m_ipkgExecOptions & FORCE_REINSTALL );
363 // TODO m_ipkgArgs.force_remove = ( m_ipkgExecOptions & FORCE_REMOVE ); 363 // TODO m_ipkgArgs.force_remove = ( m_ipkgExecOptions & FORCE_REMOVE );
364 m_ipkgArgs.force_overwrite = ( m_ipkgExecOptions & FORCE_OVERWRITE ); 364 m_ipkgArgs.force_overwrite = ( m_ipkgExecOptions & FORCE_OVERWRITE );
365 m_ipkgArgs.verbosity = m_ipkgExecVerbosity; 365 m_ipkgArgs.verbosity = m_ipkgExecVerbosity;
366 if ( m_ipkgArgs.dest ) 366 if ( m_ipkgArgs.dest )
367 free( m_ipkgArgs.dest ); 367 free( m_ipkgArgs.dest );
368 if ( !destination.isNull() ) 368 if ( !destination.isNull() )
369 { 369 {
370 int len = destination.length() + 1; 370 int len = destination.length() + 1;
371 m_ipkgArgs.dest = (char *)malloc( len ); 371 m_ipkgArgs.dest = (char *)malloc( len );
372 strncpy( m_ipkgArgs.dest, destination, destination.length() ); 372 strncpy( m_ipkgArgs.dest, destination, destination.length() );
373 m_ipkgArgs.dest[ len - 1 ] = '\0'; 373 m_ipkgArgs.dest[ len - 1 ] = '\0';
374 } 374 }
375 else 375 else
376 m_ipkgArgs.dest = 0x0; 376 m_ipkgArgs.dest = 0x0;
377 377
378 // Connect output signal to widget 378 // Connect output signal to widget
379 379
380 if ( rawOutput ) 380 if ( rawOutput )
381 { 381 {
382// if ( slotOutput ) 382// if ( slotOutput )
383// connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); 383// connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput );
384 } 384 }
385 else 385 else
386 { 386 {
387 // TODO - connect to local slot and parse output before emitting signalIpkgMessage 387 // TODO - connect to local slot and parse output before emitting signalIpkgMessage
388 } 388 }
389 389
390 switch( command ) 390 switch( command )
391 { 391 {
392 case OPackage::Update : { 392 case OPackage::Update : {
393 connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); 393 connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput );
394 ipkg_lists_update( &m_ipkgArgs ); 394 ipkg_lists_update( &m_ipkgArgs );
395 }; 395 };
396 break; 396 break;
397 case OPackage::Upgrade : { 397 case OPackage::Upgrade : {
398 connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); 398 connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput );
399 ipkg_packages_upgrade( &m_ipkgArgs ); 399 ipkg_packages_upgrade( &m_ipkgArgs );
400 }; 400 };
401 break; 401 break;
402 case OPackage::Install : { 402 case OPackage::Install : {
403 connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); 403 connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput );
404 for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) 404 for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it )
405 { 405 {
406 ipkg_packages_install( &m_ipkgArgs, (*it) ); 406 ipkg_packages_install( &m_ipkgArgs, (*it) );
407 } 407 }
408 }; 408 };
409 break; 409 break;
410 case OPackage::Remove : { 410 case OPackage::Remove : {
411 connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); 411 connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput );
412 for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) 412 for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it )
413 { 413 {
414 ipkg_packages_remove( &m_ipkgArgs, (*it), true ); 414 ipkg_packages_remove( &m_ipkgArgs, (*it), true );
415 } 415 }
416 }; 416 };
417 break; 417 break;
418 case OPackage::Download : { 418 case OPackage::Download : {
419 connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); 419 connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput );
420 for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) 420 for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it )
421 { 421 {
422 ipkg_packages_download( &m_ipkgArgs, (*it) ); 422 ipkg_packages_download( &m_ipkgArgs, (*it) );
423 } 423 }
424 }; 424 };
425 break; 425 break;
426 case OPackage::Info : { 426 case OPackage::Info : {
427 connect( this, SIGNAL(signalIpkgStatus(char*)), receiver, slotOutput ); 427 connect( this, SIGNAL(signalIpkgStatus(char*)), receiver, slotOutput );
428 ipkg_packages_info( &m_ipkgArgs, (*parameters->begin()), &fIpkgStatus, 0x0 ); 428 ipkg_packages_info( &m_ipkgArgs, (*parameters->begin()), &fIpkgStatus, 0x0 );
429 }; 429 };
430 break; 430 break;
431 case OPackage::Files : { 431 case OPackage::Files : {
432 connect( this, SIGNAL(signalIpkgList(char*)), receiver, slotOutput ); 432 connect( this, SIGNAL(signalIpkgList(char*)), receiver, slotOutput );
433 ipkg_package_files( &m_ipkgArgs, (*parameters->begin()), &fIpkgFiles, 0x0 ); 433 ipkg_package_files( &m_ipkgArgs, (*parameters->begin()), &fIpkgFiles, 0x0 );
434 }; 434 };
435 break; 435 break;
436 default : break; 436 default : break;
437 }; 437 };
438 438
439 return true; 439 return true;
440} 440}
441 441
442void OIpkg::ipkgMessage( char *msg ) 442void OIpkg::ipkgMessage( char *msg )
443{ 443{
444 emit signalIpkgMessage( msg ); 444 emit signalIpkgMessage( msg );
445} 445}
446 446
447void OIpkg::ipkgStatus( char *status ) 447void OIpkg::ipkgStatus( char *status )
448{ 448{
449 emit signalIpkgStatus( status ); 449 emit signalIpkgStatus( status );
450} 450}
451 451
452void OIpkg::ipkgList( char *filelist ) 452void OIpkg::ipkgList( char *filelist )
453{ 453{
454 emit signalIpkgList( filelist ); 454 emit signalIpkgList( filelist );
455} 455}
456 456
457void OIpkg::loadConfiguration() 457void OIpkg::loadConfiguration()
458{ 458{
459 if ( m_confInfo ) 459 if ( m_confInfo )
460 delete m_confInfo; 460 delete m_confInfo;
461 461
462 // Load configuration item list 462 // Load configuration item list
463 m_confInfo = new OConfItemList(); 463 m_confInfo = new OConfItemList();
464 464
465 QStringList confFiles; 465 QStringList confFiles;
466 QDir confDir( IPKG_CONF_DIR ); 466 QDir confDir( IPKG_CONF_DIR );
467 if ( confDir.exists() ) 467 if ( confDir.exists() )
468 { 468 {
469 confDir.setNameFilter( "*.conf" ); 469 confDir.setNameFilter( "*.conf" );
470 confDir.setFilter( QDir::Files ); 470 confDir.setFilter( QDir::Files );
471 confFiles = confDir.entryList( "*.conf", QDir::Files ); 471 confFiles = confDir.entryList( "*.conf", QDir::Files );
472 confFiles << IPKG_CONF; 472 }
473 confFiles << IPKG_CONF;
473 474
474 QStringList::Iterator lastFile = confFiles.end(); 475 QStringList::Iterator lastFile = confFiles.end();
475 for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++it ) 476 for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++it )
477 {
478 // Create absolute file path if necessary
479 QString absFile = (*it);
480 if ( !absFile.startsWith( "/" ) )
481 absFile.prepend( QString( IPKG_CONF_DIR ) + "/" );
482
483 // Read in file
484 QFile f( absFile );
485 if ( f.open( IO_ReadOnly ) )
476 { 486 {
477 // Create absolute file path if necessary 487 QTextStream s( &f );
478 QString absFile = (*it); 488 while ( !s.eof() )
479 if ( !absFile.startsWith( "/" ) )
480 absFile.prepend( QString( IPKG_CONF_DIR ) + "/" );
481
482 // Read in file
483 QFile f( absFile );
484 if ( f.open( IO_ReadOnly ) )
485 { 489 {
486 QTextStream s( &f );
487 while ( !s.eof() )
488 {
489 490
490 QString line = s.readLine().simplifyWhiteSpace(); 491 QString line = s.readLine().simplifyWhiteSpace();
491 492
492 // Parse line and save info to the conf options list 493 // Parse line and save info to the conf options list
493 if ( !line.isEmpty() ) 494 if ( !line.isEmpty() )
495 {
496 if ( !line.startsWith( "#" ) ||
497 line.startsWith( "#src" ) ||
498 line.startsWith( "#dest" ) ||
499 line.startsWith( "#arch" ) ||
500 line.startsWith( "#option" ) )
494 { 501 {
495 if ( !line.startsWith( "#" ) || 502 int pos = line.find( ' ', 1 );
496 line.startsWith( "#src" ) || 503
497 line.startsWith( "#dest" ) || 504 // Type
498 line.startsWith( "#arch" ) || 505 QString typeStr = line.left( pos );
499 line.startsWith( "#option" ) ) 506 OConfItem::Type type;
500 { 507 if ( typeStr == "src" || typeStr == "#src" )
501 int pos = line.find( ' ', 1 ); 508 type = OConfItem::Source;
502 509 else if ( typeStr == "dest" || typeStr == "#dest" )
503 // Type 510 type = OConfItem::Destination;
504 QString typeStr = line.left( pos ); 511 else if ( typeStr == "option" || typeStr == "#option" )
505 OConfItem::Type type; 512 type = OConfItem::Option;
506 if ( typeStr == "src" || typeStr == "#src" ) 513 else if ( typeStr == "arch" || typeStr == "#arch" )
507 type = OConfItem::Source; 514 type = OConfItem::Arch;
508 else if ( typeStr == "dest" || typeStr == "#dest" ) 515 else
509 type = OConfItem::Destination; 516 type = OConfItem::NotDefined;
510 else if ( typeStr == "option" || typeStr == "#option" ) 517 ++pos;
511 type = OConfItem::Option; 518 int endpos = line.find( ' ', pos );
512 else if ( typeStr == "arch" || typeStr == "#arch" ) 519
513 type = OConfItem::Arch; 520 // Name
514 else 521 QString name = line.mid( pos, endpos - pos );
515 type = OConfItem::NotDefined; 522
516 ++pos; 523 // Value
517 int endpos = line.find( ' ', pos ); 524 QString value = "";
518 525 if ( endpos > -1 )
519 // Name 526 value = line.right( line.length() - endpos - 1 );
520 QString name = line.mid( pos, endpos - pos ); 527
521 528 // Active
522 // Value 529 bool active = !line.startsWith( "#" );
523 QString value = ""; 530
524 if ( endpos > -1 ) 531 // Add to list
525 value = line.right( line.length() - endpos - 1 ); 532 m_confInfo->append( new OConfItem( type, name, value, active ) );
526
527 // Active
528 bool active = !line.startsWith( "#" );
529
530 // Add to list
531 m_confInfo->append( new OConfItem( type, name, value, active ) );
532 }
533 } 533 }
534 } 534 }
535
536 f.close();
537 } 535 }
536
537 f.close();
538 } 538 }
539 } 539 }
540 540
541 // Load Ipkg execution options from application configuration file 541 // Load Ipkg execution options from application configuration file
542 if ( m_config ) 542 if ( m_config )
543 { 543 {
544 m_config->setGroup( "Ipkg" ); 544 m_config->setGroup( "Ipkg" );
545 m_ipkgExecOptions = m_config->readNumEntry( "ExecOptions", m_ipkgExecOptions ); 545 m_ipkgExecOptions = m_config->readNumEntry( "ExecOptions", m_ipkgExecOptions );
546 m_ipkgExecVerbosity = m_config->readNumEntry( "Verbosity", m_ipkgExecVerbosity ); 546 m_ipkgExecVerbosity = m_config->readNumEntry( "Verbosity", m_ipkgExecVerbosity );
547 } 547 }
548} 548}
549 549
550OConfItemList *OIpkg::filterConfItems( OConfItem::Type typefilter ) 550OConfItemList *OIpkg::filterConfItems( OConfItem::Type typefilter )
551{ 551{
552 // Load Ipkg configuration info if not already cached 552 // Load Ipkg configuration info if not already cached
553 if ( !m_confInfo ) 553 if ( !m_confInfo )
554 loadConfiguration(); 554 loadConfiguration();
555 555
556 // Build new server list (caller is responsible for deleting) 556 // Build new server list (caller is responsible for deleting)
557 OConfItemList *sl = new OConfItemList; 557 OConfItemList *sl = new OConfItemList;
558 558
559 // If typefilter is empty, retrieve all items 559 // If typefilter is empty, retrieve all items
560 bool retrieveAll = ( typefilter == OConfItem::NotDefined ); 560 bool retrieveAll = ( typefilter == OConfItem::NotDefined );
561 561
562 // Parse configuration info for servers 562 // Parse configuration info for servers
563 OConfItemListIterator it( *m_confInfo ); 563 OConfItemListIterator it( *m_confInfo );
564 for ( ; it.current(); ++it ) 564 for ( ; it.current(); ++it )
565 { 565 {
566 OConfItem *item = it.current(); 566 OConfItem *item = it.current();
567 if ( retrieveAll || item->type() == typefilter ) 567 if ( retrieveAll || item->type() == typefilter )
568 { 568 {
569 sl->append( item ); 569 sl->append( item );
570 } 570 }
571 } 571 }
572 572
573 return sl; 573 return sl;
574} 574}