aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/opie-packagemanager/files/split-config.patch
blob: 5abe5433aa99d935da7e22a6c0b16b6d5e9197b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# NOTE: This patch has been applied upstream and will be included in 1.2.5
#  - Paul Eggleton <bluelightning@bluelightning.org>
--- packagemanager/oipkg.cpp	2009-05-11 23:06:48.000000000 +0100
+++ packagemanager/oipkg.cpp	2009-05-11 23:06:50.000000000 +0100
@@ -30,6 +30,8 @@
 
 #include "oipkg.h"
 
+#include <opie2/odebug.h>
+
 #include <qdir.h>
 #include <qfile.h>
 #include <qtextstream.h>
@@ -133,6 +135,26 @@
     return filterConfItems( OConfItem::Option );
 }
 
+void OIpkg::defaultConfItemFile( OConfItem *item )
+{
+    if( item->file().isNull() )
+    {
+        switch ( item->type() )
+        {
+            case OConfItem::Source :
+            case OConfItem::Destination : 
+                item->setFile( IPKG_CONF_DIR + "/" + item->name() + ".conf" );
+                break;
+            case OConfItem::Arch : 
+                item->setFile( IPKG_CONF_DIR + "/arch.conf" );
+                break;
+            default : 
+                item->setFile( IPKG_CONF );
+                break;
+        };
+    }
+}
+
 void OIpkg::setConfigItems( OConfItemList *configList )
 {
     if ( m_confInfo )
@@ -140,84 +162,78 @@
 
     m_confInfo = configList;
 
-    // Write out new /etc/ipkg.conf
-    QFile confFile( IPKG_CONF );
-    if ( confFile.open( IO_WriteOnly ) )
+    // Write out new config files
+    QString lastFile = "";
+    QFile *confFile = NULL;
+    QTextStream *confStream = NULL;
+    OConfItemListIterator it( *m_confInfo );
+    for ( ; it.current(); ++it )
     {
-        QTextStream confStream( &confFile );
-        confStream << "# Generated by Opie Package Manager\n\n";
+        OConfItem *item = it.current();
 
-        OConfItemListIterator it( *m_confInfo );
-        for ( ; it.current(); ++it )
+        // Only write out valid conf items
+        if ( item->type() != OConfItem::NotDefined )
         {
-            OConfItem *item = it.current();
+            if ( lastFile != item->file() ) {
+                if ( confFile ) {
+                    confFile->close();
+                    delete confStream;
+                    delete confFile;
+                }
+                odebug << "Opening " << item->file() << oendl;
+                confFile = new QFile( item->file() );
+                if ( ! confFile->open( IO_WriteOnly ) ) {
+                    owarn << "Failed to open " << item->file() << oendl;
+                    delete confFile;
+                    confFile = NULL;
+                    break;
+                }
+                lastFile = item->file();
+                
+                confStream = new QTextStream( confFile );
+//                (*confStream) << "# Generated by Opie Package Manager\n\n";
+            }
 
-            // Only write out valid conf items
-            if ( item->type() != OConfItem::NotDefined )
-            {
-                QString confLine;
-                QString name = item->name();
-                if ( !item->active() )
-                    confLine = "#";
+            QString confLine;
+            QString name = item->name();
+            if ( !item->active() )
+                confLine = "#";
 
-                switch ( item->type() )
+            switch ( item->type() )
+            {
+                case OConfItem::Source :
                 {
-                    case OConfItem::Source :
-                    {
-                        if ( item->features().contains( "Compressed" ) )
-                            confLine.append( "src/gz" );
-                        else
-                            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;
-                    case OConfItem::Other :
-                    {
-                        // For options w/type = Other, the mapping is as follows:
-                        //    name = typeStr (e.g. "lists_dir")
-                        //    value = value
-                        //    features = name (from configuration file)
-                        confLine.append( item->name() );
-                        name = item->features();
-                    }
-                    break;
-                    default : break;
-                };
+                    if ( item->features().contains( "Compressed" ) )
+                        confLine.append( "src/gz" );
+                    else
+                        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;
+                case OConfItem::Other :
+                {
+                    // For options w/type = Other, the mapping is as follows:
+                    //    name = typeStr (e.g. "lists_dir")
+                    //    value = value
+                    //    features = name (from configuration file)
+                    confLine.append( item->name() );
+                    name = item->features();
+                }
+                break;
+                default : break;
+            };
 
-                confStream << confLine << " " << name << " " << item->value() << "\n";
-            }
+            (*confStream) << confLine << " " << 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
-            QFile::remove( absFile );
-        }
+    if ( confFile ) {
+        confFile->close();
+        delete confStream;
+        delete confFile;
     }
 
     // Reinitialize libipkg to pick up new configuration
@@ -638,7 +654,7 @@
 
                     // Add to list
                     if ( recognizedOption )
-                        m_confInfo->append( new OConfItem( type, name, value, features, active ) );
+                        m_confInfo->append( new OConfItem( type, name, value, features, absFile, active ) );
                 }
             }
 
--- packagemanager/oconfitem.cpp	2009-05-11 23:09:00.000000000 +0100
+++ packagemanager/oconfitem.cpp	2009-05-11 23:09:02.000000000 +0100
@@ -31,11 +31,12 @@
 #include "oconfitem.h"
 
 OConfItem::OConfItem( Type type, const QString &name, const QString &value,
-                      const QString &features, bool active )
+                      const QString &features, const QString &file, bool active )
     : m_type( type )
     , m_name( name )
     , m_value( value )
     , m_features( features )
+    , m_file( file )
     , m_active( active )
 {
 }
--- packagemanager/oconfitem.h	2009-05-11 23:08:43.000000000 +0100
+++ packagemanager/oconfitem.h	2009-05-11 23:08:45.000000000 +0100
@@ -41,18 +41,20 @@
 
     OConfItem( Type type = NotDefined, const QString &name = QString::null,
                const QString &value = QString::null, const QString &features = QString::null,
-               bool active = true );
+               const QString &file = QString::null, bool active = true );
 
     Type           type()     { return m_type; }
     const QString &name()     { return m_name; }
     const QString &value()    { return m_value; }
     const QString &features() { return m_features; }
+    const QString &file()     { return m_file; }
     bool           active()   { return m_active; }
 
     void setType( Type type )                   { m_type = type; }
     void setName( const QString &name )         { m_name = name; }
     void setValue( const QString &value )       { m_value = value; }
     void setFeatures( const QString &features ) { m_features = features; }
+    void setFile( const QString &file )         { m_file = file; }
     void setActive( bool active )               { m_active = active; }
 
 private:
@@ -60,6 +62,7 @@
     QString m_name;     // Name of item
     QString m_value;    // Value of item
     QString m_features; // Comma-deliminated list of features this item supports
+    QString m_file;     // File this item came from
     bool    m_active;   // Indicates whether item is currently active
 };
 
@@ -69,23 +72,32 @@
 
     int compareItems( QCollection::Item item1, QCollection::Item item2 )
     {
-        // Sort by OConfItem location then by type
-        OConfItem::Type type1 = reinterpret_cast<OConfItem*>(item1)->type();
-        OConfItem::Type type2 = reinterpret_cast<OConfItem*>(item2)->type();
-        if ( type1 < type2 )
+        // Sort by OConfItem file, name, then by type
+        QString file1 = reinterpret_cast<OConfItem*>(item1)->file();
+        QString file2 = reinterpret_cast<OConfItem*>(item2)->file();
+        if ( file1 < file2 )
             return -1;
-        else if ( type1 == type2 )
+        else if ( file1 == file2 )
         {
-            QString name1 = reinterpret_cast<OConfItem*>(item1)->name();
-            QString name2 = reinterpret_cast<OConfItem*>(item2)->name();
-            if ( name1 < name2 )
+            OConfItem::Type type1 = reinterpret_cast<OConfItem*>(item1)->type();
+            OConfItem::Type type2 = reinterpret_cast<OConfItem*>(item2)->type();
+            if ( type1 < type2 )
                 return -1;
-            else if ( name1 == name2 )
-                return 0;
-            else /*if ( name1 > name2 )*/
+            else if ( type1 == type2 )
+            {
+                QString name1 = reinterpret_cast<OConfItem*>(item1)->name();
+                QString name2 = reinterpret_cast<OConfItem*>(item2)->name();
+                if ( name1 < name2 )
+                    return -1;
+                else if ( name1 == name2 )
+                    return 0;
+                else /*if ( name1 > name2 )*/
+                    return 1;
+            }
+            else /*if ( type1 > type2 )*/
                 return 1;
         }
-        else /*if ( type1 > type2 )*/
+        else /*if ( file1 > file2 )*/
             return 1;
     }
 };
--- packagemanager/oipkgconfigdlg.cpp	2009-05-11 23:08:21.000000000 +0100
+++ packagemanager/oipkgconfigdlg.cpp	2009-05-11 23:08:23.000000000 +0100
@@ -99,7 +99,7 @@
         }
         else
             m_configs->append( new OConfItem( OConfItem::Option, "http_proxy",
-                               m_proxyHttpServer->text(), QString::null,
+                               m_proxyHttpServer->text(), QString::null, QString::null,
                                m_proxyHttpActive->isChecked() ) );
 
         confItem = m_ipkg->findConfItem( OConfItem::Option, "ftp_proxy" );
@@ -110,7 +110,7 @@
         }
         else
             m_configs->append( new OConfItem( OConfItem::Option, "ftp_proxy",
-                               m_proxyFtpServer->text(), QString::null,
+                               m_proxyFtpServer->text(), QString::null, QString::null,
                                m_proxyFtpActive->isChecked() ) );
 
         confItem = m_ipkg->findConfItem( OConfItem::Option, "proxy_username" );
@@ -472,6 +472,7 @@
     if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted )
     {
         // Add to configuration option list
+        m_ipkg->defaultConfItemFile( server );
         m_configs->append( server );
         m_configs->sort();
 
@@ -532,6 +533,7 @@
     if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted )
     {
         // Add to configuration option list
+        m_ipkg->defaultConfItemFile( dest );
         m_configs->append( dest );
         m_configs->sort();
 
--- packagemanager/oipkg.h	16 Jan 2006 15:07:35 -0000	1.9
+++ packagemanager/oipkg.h	17 May 2009 21:26:55 -0000
@@ -76,6 +76,7 @@
 
     OConfItem    *findConfItem( OConfItem::Type type = OConfItem::NotDefined,
                                 const QString &name = QString::null );
+    void defaultConfItemFile( OConfItem *item );
 
     bool executeCommand( OPackage::Command command = OPackage::NotDefined,
                          const QStringList &parameters = QStringList(),