author | drw <drw> | 2004-04-21 15:57:19 (UTC) |
---|---|---|
committer | drw <drw> | 2004-04-21 15:57:19 (UTC) |
commit | 5ac20617216e4592685940ede23f135d86e8d2cd (patch) (side-by-side diff) | |
tree | 17a2ba8adc06eed219b3b77e42d46e5e0c714630 /noncore/settings/packagemanager/oipkg.cpp | |
parent | 4e6c1ec2758d337d772af3af49a1b74f737cd57f (diff) | |
download | opie-5ac20617216e4592685940ede23f135d86e8d2cd.zip opie-5ac20617216e4592685940ede23f135d86e8d2cd.tar.gz opie-5ac20617216e4592685940ede23f135d86e8d2cd.tar.bz2 |
Implement saving of ipkg config information and re-initialization of libipkg after config info changed
Diffstat (limited to 'noncore/settings/packagemanager/oipkg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/packagemanager/oipkg.cpp | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/noncore/settings/packagemanager/oipkg.cpp b/noncore/settings/packagemanager/oipkg.cpp index 5c79ba9..b9c82df 100644 --- a/noncore/settings/packagemanager/oipkg.cpp +++ b/noncore/settings/packagemanager/oipkg.cpp @@ -130,2 +130,71 @@ void OIpkg::setConfigItems( OConfItemList *configList ) m_confInfo = configList; + + // Write out new /etc/ipkg.conf + QFile confFile( IPKG_CONF ); + if ( confFile.open( IO_WriteOnly ) ) + { + QTextStream confStream( &confFile ); + confStream << "# Generated by Opie Package Manager\n\n"; + + OConfItemListIterator it( *m_confInfo ); + for ( ; it.current(); ++it ) + { + OConfItem *item = it.current(); + + // Only write out valid conf items + if ( item->type() != OConfItem::NotDefined ) + { + QString confLine; + if ( !item->active() ) + confLine = "#"; + + switch ( item->type() ) + { + case OConfItem::Source : confLine.append( "src " ); break; + case OConfItem::Destination : confLine.append( "dest " ); break; + case OConfItem::Option : confLine.append( "option " ); break; + case OConfItem::Arch : confLine.append( "arch " ); break; + default : break; + }; + + confStream << confLine << " " << item->name() << " " << item->value() << "\n"; + } + } + + confFile.close(); + } + else + { + // Problem writing to /etc/ipkg.conf, exit before removing other conf files + return; + } + + // Delete /etc/ipkg/*.conf files (/etc/ipkg.conf should now have all settings + QStringList confFiles; + QDir confDir( IPKG_CONF_DIR ); + if ( confDir.exists() ) + { + confDir.setNameFilter( "*.conf" ); + confDir.setFilter( QDir::Files ); + confFiles = confDir.entryList( "*.conf", QDir::Files ); + + QStringList::Iterator lastFile = confFiles.end(); + for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++it ) + { + // Create absolute file path if necessary + QString absFile = (*it); + if ( !absFile.startsWith( "/" ) ) + absFile.prepend( QString( IPKG_CONF_DIR ) + "/" ); + + // Delete file +printf( "Deleting: \'%s\'\n", absFile.latin1() ); + QFile::remove( absFile ); + } + } + + // Reinitialize libipkg to pick up new configuration + ipkg_deinit( &m_ipkgArgs ); + ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ); + m_ipkgArgs.noaction = false; + m_ipkgArgs.force_defaults = true; } @@ -406,3 +475,4 @@ void OIpkg::loadConfiguration() - for ( QStringList::Iterator it = confFiles.begin(); it != confFiles.end(); ++it ) + QStringList::Iterator lastFile = confFiles.end(); + for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++it ) { |