summaryrefslogtreecommitdiff
authorharlekin <harlekin>2002-08-30 10:31:09 (UTC)
committer harlekin <harlekin>2002-08-30 10:31:09 (UTC)
commit40bac3f8b24cd8b02c685dae3efa57c6de09452b (patch) (unidiff)
treeb294e82541b26cacb10389b53b228e32bb12dee1
parent57e4c1b05208650eaac76268eb9bb25a1caa2184 (diff)
downloadopie-40bac3f8b24cd8b02c685dae3efa57c6de09452b.zip
opie-40bac3f8b24cd8b02c685dae3efa57c6de09452b.tar.gz
opie-40bac3f8b24cd8b02c685dae3efa57c6de09452b.tar.bz2
blind fix by robert to make it work with new ipkg format too
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/oipkg/package.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/noncore/unsupported/oipkg/package.cpp b/noncore/unsupported/oipkg/package.cpp
index 7aaa240..1054a1d 100644
--- a/noncore/unsupported/oipkg/package.cpp
+++ b/noncore/unsupported/oipkg/package.cpp
@@ -1,217 +1,217 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9// (c) 2002 Patrick S. Vogt <tille@handhelds.org> 9// (c) 2002 Patrick S. Vogt <tille@handhelds.org>
10#include "package.h" 10#include "package.h"
11 11
12#include <qpe/process.h> 12#include <qpe/process.h>
13#include <qpe/stringutil.h> 13#include <qpe/stringutil.h>
14#include <qfile.h> 14#include <qfile.h>
15#include <qtextstream.h> 15#include <qtextstream.h>
16#include <stdlib.h> 16#include <stdlib.h>
17#include <unistd.h> 17#include <unistd.h>
18 18
19#include "debug.h" 19#include "debug.h"
20 20
21Package::Package( QObject *parent, const char *name ) 21Package::Package( QObject *parent, const char *name )
22 : QObject(parent,name) 22 : QObject(parent,name)
23{ 23{
24 24
25} 25}
26 26
27Package::~Package() 27Package::~Package()
28{ 28{
29} 29}
30 30
31Package::Package( PackageManagerSettings *s, QObject *parent, const char *name ) 31Package::Package( PackageManagerSettings *s, QObject *parent, const char *name )
32 : QObject(parent,name) 32 : QObject(parent,name)
33{ 33{
34 Package(parent,name); 34 Package(parent,name);
35 init(s); 35 init(s);
36} 36}
37 37
38void Package::init( PackageManagerSettings *s ) 38void Package::init( PackageManagerSettings *s )
39{ 39{
40 settings = s; 40 settings = s;
41 _size = ""; 41 _size = "";
42 _section = ""; 42 _section = "";
43 _subsection = ""; 43 _subsection = "";
44 _shortDesc = ""; 44 _shortDesc = "";
45 _desc = ""; 45 _desc = "";
46 _name = ""; 46 _name = "";
47 _toProcess = false; 47 _toProcess = false;
48 _useFileName = false; 48 _useFileName = false;
49 _old = false; 49 _old = false;
50 _status = ""; 50 _status = "";
51 _dest = settings->getDestinationName(); 51 _dest = settings->getDestinationName();
52 _link = settings->createLinks(); 52 _link = settings->createLinks();
53 _versions=0; 53 _versions=0;
54 _version=""; 54 _version="";
55} 55}
56 56
57Package::Package( QStringList pack, PackageManagerSettings *s , QObject *parent, const char *name ) 57Package::Package( QStringList pack, PackageManagerSettings *s , QObject *parent, const char *name )
58 : QObject(parent,name) 58 : QObject(parent,name)
59 { 59{
60 init(s); 60 init(s);
61 parsePackage( pack ); 61 parsePackage( pack );
62} 62}
63 63
64Package::Package( QString n, PackageManagerSettings *s, QObject *parent, const char *name ) 64Package::Package( QString n, PackageManagerSettings *s, QObject *parent, const char *name )
65 : QObject(parent,name) 65 : QObject(parent,name)
66 { 66{
67 init(s); 67 init(s);
68 if ( !QFile::exists( n ) ) 68 if ( !QFile::exists( n ) )
69 { 69 {
70 _name = QString( n ); 70 _name = QString( n );
71 }else{ 71 }else{
72 pvDebug(4,"remote file: "+n); 72 pvDebug(4,"remote file: "+n);
73 parseIpkgFile( n ); 73 parseIpkgFile( n );
74 _useFileName = true; 74 _useFileName = true;
75 _fileName = QString( n ); 75 _fileName = QString( n );
76 } 76 }
77} 77}
78 78
79Package::Package( Package *pi, QObject *parent, const char *name ) 79Package::Package( Package *pi, QObject *parent, const char *name )
80 : QObject(parent,name) 80 : QObject(parent,name)
81{ 81{
82 init(pi->settings); 82 init(pi->settings);
83 copyValues( pi ); 83 copyValues( pi );
84} 84}
85 85
86 86
87void Package::setValue( QString n, QString t ) 87void Package::setValue( QString n, QString t )
88{ 88{
89 if ( n == "Package" ) 89 if ( n == "Package" )
90 { 90 {
91 _name = QString( t ); 91 _name = QString( t );
92 }else if ( n == "Installed-Size" ) 92 }else if ( n == "Installed-Size" )
93 { 93 {
94 _size = t; 94 _size = t;
95// }else if ( n == "Priority") 95// }else if ( n == "Priority")
96// { 96// {
97 97
98 }else if ( n == "Section") 98 }else if ( n == "Section")
99 { 99 {
100 setSection( t ); 100 setSection( t );
101// }else if ( n == "Maintainer") 101// }else if ( n == "Maintainer")
102// { 102// {
103// 103//
104// }else if ( n == "Architecture") 104// }else if ( n == "Architecture")
105// { 105// {
106 106
107 }else if ( n == "Version") 107 }else if ( n == "Version")
108 { 108 {
109 _version = t; 109 _version = t;
110// }else if ( n == "Pre-Depends") 110// }else if ( n == "Pre-Depends")
111// { 111// {
112// 112//
113// }else if ( n == "Depends") 113// }else if ( n == "Depends")
114// { 114// {
115 115
116 }else if ( n == "Filename") 116 }else if ( n == "Filename")
117 { 117 {
118 _fileName = t; 118 _fileName = t;
119// }else if ( n == "Size") 119// }else if ( n == "Size")
120 // { 120 // {
121 // 121//
122 //}else if ( n == "MD5Sum") 122 //}else if ( n == "MD5Sum")
123 //{ 123 //{
124 124
125 }else if ( n == "Description") 125 }else if ( n == "Description")
126 { 126 {
127 setDesc( t ); 127 setDesc( t );
128 }else if ( n == "Status") 128 }else if ( n == "Status")
129 { 129 {
130 if ( installed() ) return; 130 if ( installed() ) return;
131 _status = t; 131 _status = t;
132// }else if ( n == "Essential") 132// }else if ( n == "Essential")
133// { 133// {
134 134
135 }else{ 135 }else{
136 _values.insert(n,new QString(t)); 136 _values.insert(n,new QString(t));
137 } 137 }
138} 138}
139 139
140QString Package::name() 140QString Package::name()
141{ 141{
142 if (_displayName.isEmpty() ) return _name; 142 if (_displayName.isEmpty() ) return _name;
143 else return _displayName; 143 else return _displayName;
144} 144}
145 145
146 146
147QString Package::installName() 147QString Package::installName()
148{ 148{
149 if (_useFileName) return _fileName; 149 if (_useFileName) return _fileName;
150 else return _name; 150 else return _name;
151} 151}
152 152
153QString Package::packageName() 153QString Package::packageName()
154{ 154{
155 QString pn = installName(); 155 QString pn = installName();
156 pn = pn.right(pn.length()-pn.findRev("/")); 156 pn = pn.right(pn.length()-pn.findRev("/"));
157 pn = pn.left(pn.find("_")); 157 pn = pn.left(pn.find("_"));
158 return pn; 158 return pn;
159} 159}
160 160
161bool Package::installed() 161bool Package::installed()
162{ 162{
163 if (_status.contains("installed")) 163 if (_status.contains("installed"))
164 { 164 {
165 if (_status.contains("not-installed")) 165 if (_status.contains("not-installed"))
166 { 166 {
167 _toProcess = true; 167 _toProcess = true;
168 return false; 168 return false;
169 } 169 }
170 else return true; 170 else return true;
171 } 171 }
172 else 172 else
173 if (_versions) 173 if (_versions)
174 { 174 {
175 QDictIterator<Package> other( *_versions ); 175 QDictIterator<Package> other( *_versions );
176 while ( other.current() ) 176 while ( other.current() )
177 { 177 {
178 if (other.current()->status().contains("installed") 178 if (other.current()->status().contains("installed")
179 && other.current()->version() == version()) 179 && other.current()->version() == version())
180 return true; 180 return true;
181 ++other; 181 ++other;
182 } 182 }
183 } 183 }
184 return false; 184 return false;
185} 185}
186 186
187bool Package::otherInstalled() 187bool Package::otherInstalled()
188{ 188{
189 if (_versions) 189 if (_versions)
190 { 190 {
191 QDictIterator<Package> other( *_versions ); 191 QDictIterator<Package> other( *_versions );
192 while ( other.current() ) 192 while ( other.current() )
193 { 193 {
194 if (other.current()->installed()) return true; 194 if (other.current()->installed()) return true;
195 ++other; 195 ++other;
196 } 196 }
197 } 197 }
198 return false; 198 return false;
199} 199}
200 200
201void Package::setDesc( QString s ) 201void Package::setDesc( QString s )
202{ 202{
203 _desc = s; 203 _desc = s;
204 _shortDesc = s.left( s.find("\n") ); 204 _shortDesc = s.left( s.find("\n") );
205} 205}
206 206
207QString Package::desc() 207QString Package::desc()
208{ 208{
209 return _desc; 209 return _desc;
210} 210}
211 211
212QString Package::shortDesc() 212QString Package::shortDesc()
213{ 213{
214 return _shortDesc; 214 return _shortDesc;
215} 215}
216 216
217QString Package::size() 217QString Package::size()
@@ -292,181 +292,188 @@ void Package::setSection( QString s)
292 if ( i > 0 ) 292 if ( i > 0 )
293 { 293 {
294 _section = s.left(i); 294 _section = s.left(i);
295 _subsection = s.mid(i+1); 295 _subsection = s.mid(i+1);
296 }else{ 296 }else{
297 _section = s; 297 _section = s;
298 _subsection = ""; 298 _subsection = "";
299 } 299 }
300} 300}
301 301
302QString Package::subSection() 302QString Package::subSection()
303{ 303{
304 return _subsection; 304 return _subsection;
305} 305}
306 306
307void Package::parsePackage( QStringList pack ) 307void Package::parsePackage( QStringList pack )
308{ 308{
309 if ( pack.isEmpty() ) return; 309 if ( pack.isEmpty() ) return;
310 int count = pack.count(); 310 int count = pack.count();
311 for( int i = 0; i < count; i++ ) 311 for( int i = 0; i < count; i++ )
312 { 312 {
313 QString line = pack[i]; 313 QString line = pack[i];
314 int sep = line.find( QRegExp(":[\t ]+") ); 314 int sep = line.find( QRegExp(":[\t ]+") );
315 if ( sep >= 0 ) 315 if ( sep >= 0 )
316 { 316 {
317 QString tag = line.left(sep); 317 QString tag = line.left(sep);
318 QString value = line.mid(sep+2).simplifyWhiteSpace(); 318 QString value = line.mid(sep+2).simplifyWhiteSpace();
319 setValue( tag, value ); 319 setValue( tag, value );
320 }else{ 320 }else{
321 } 321 }
322 } 322 }
323 return; 323 return;
324} 324}
325 325
326QString Package::details() 326QString Package::details()
327{ 327{
328 QString status; 328 QString status;
329 Process ipkg_status(QStringList() << "ipkg" << "info" << name() ); 329 Process ipkg_status(QStringList() << "ipkg" << "info" << name() );
330 QString description; 330 QString description;
331 if ( ipkg_status.exec("",status) ) 331 if ( ipkg_status.exec("",status) )
332 { 332 {
333 QStringList lines = QStringList::split('\n',status,TRUE); 333 QStringList lines = QStringList::split('\n',status,TRUE);
334 for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) { 334 for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) {
335 QString line = *it; 335 QString line = *it;
336 if ( line == " ." ) 336 if ( line == " ." )
337 { 337 {
338 description.append("<p>"); 338 description.append("<p>");
339 } else 339 } else
340 if ( line[0] == ' ' || line[0] == '\t' ) 340 if ( line[0] == ' ' || line[0] == '\t' )
341 { 341 {
342 // continuation 342 // continuation
343 description.append(" "); 343 description.append(" ");
344 description.append(Qtopia::escapeString(line)); 344 description.append(Qtopia::escapeString(line));
345 } else { 345 } else {
346 int sep = line.find(QRegExp(":[\t ]+")); 346 int sep = line.find(QRegExp(":[\t ]+"));
347 if ( sep >= 0 ) 347 if ( sep >= 0 )
348 { 348 {
349 QString tag = line.left(sep); 349 QString tag = line.left(sep);
350 description.append("<br>"); 350 description.append("<br>");
351 description.append("<b>"); 351 description.append("<b>");
352 description.append(Qtopia::escapeString(tag)); 352 description.append(Qtopia::escapeString(tag));
353 description.append(":</b> "); 353 description.append(":</b> ");
354 description.append(Qtopia::escapeString(line.mid(sep+2))); 354 description.append(Qtopia::escapeString(line.mid(sep+2)));
355 } else { 355 } else {
356 description.append(" "); 356 description.append(" ");
357 description.append(Qtopia::escapeString(line)); 357 description.append(Qtopia::escapeString(line));
358 } 358 }
359 } 359 }
360 } 360 }
361 } 361 }
362 return description; 362 return description;
363} 363}
364 364
365void Package::processed() 365void Package::processed()
366{ 366{
367 _toProcess = false; 367 _toProcess = false;
368 //hack, but we're not writing status anyway... 368 //hack, but we're not writing status anyway...
369 if ( installed() ) _status = "install"; 369 if ( installed() ) _status = "install";
370 else _status = "installed"; 370 else _status = "installed";
371} 371}
372 372
373QString Package::dest() 373QString Package::dest()
374{ 374{
375 if ( installed()||(!installed() && _toProcess) ) 375 if ( installed()||(!installed() && _toProcess) )
376 return _dest!=""?_dest:settings->getDestinationName(); 376 return _dest!=""?_dest:settings->getDestinationName();
377 else return ""; 377 else return "";
378} 378}
379 379
380void Package::setDest( QString d ) 380void Package::setDest( QString d )
381{ 381{
382 if ( d == "remote") _useFileName = true; 382 if ( d == "remote") _useFileName = true;
383 else _dest = d; 383 else _dest = d;
384} 384}
385 385
386void Package::setOn() 386void Package::setOn()
387{ 387{
388 _toProcess = true; 388 _toProcess = true;
389} 389}
390 390
391bool Package::link() 391bool Package::link()
392{ 392{
393 if ( _dest == "root" || (!installed() && !_toProcess) ) return false; 393 if ( _dest == "root" || (!installed() && !_toProcess) ) return false;
394 return _link; 394 return _link;
395} 395}
396 396
397void Package::setLink(bool b) 397void Package::setLink(bool b)
398{ 398{
399 _link = b; 399 _link = b;
400} 400}
401 401
402void Package::parseIpkgFile( QString file) 402void Package::parseIpkgFile( QString file)
403{ 403{
404 system("tar xzf "+file+" -C /tmp"); 404// 20020830
405 system("tar xzf /tmp/control.tar.gz -C /tmp"); 405// a quick hack to make oipkg understand the new ipk format
406// neu: ar pf PACKAGE control.tar.gz | tar xfOz - ./control > /tmp/control
407 if (! system("ar pf "+file+" control.tar.gz | tar xfOz - ./control > /tmp/control") )
408 {
409//#old tar ipk format
410 system("tar xzf "+file+" -C /tmp");
411 system("tar xzf /tmp/control.tar.gz -C /tmp");
412 }
406 QFile f("/tmp/control"); 413 QFile f("/tmp/control");
407 if ( f.open(IO_ReadOnly) ) 414 if ( f.open(IO_ReadOnly) )
408 { 415 {
409 QTextStream t( &f ); 416 QTextStream t( &f );
410 QStringList pack; 417 QStringList pack;
411 while ( !t.eof() ) 418 while ( !t.eof() )
412 { 419 {
413 pack << t.readLine(); 420 pack << t.readLine();
414 } 421 }
415 f.close(); 422 f.close();
416 parsePackage( pack ); 423 parsePackage( pack );
417 } 424 }
418 425
419} 426}
420 427
421//QString Package::getPackageName() 428//QString Package::getPackageName()
422//{ 429//{
423 //if ( _packageName.isEmpty() ) return _name; 430 //if ( _packageName.isEmpty() ) return _name;
424 //else return _packageName; 431 //else return _packageName;
425//} 432//}
426 433
427void Package::instalFromFile(bool iff) 434void Package::instalFromFile(bool iff)
428{ 435{
429 _useFileName = iff; 436 _useFileName = iff;
430} 437}
431 438
432void Package::setName(QString n) 439void Package::setName(QString n)
433{ 440{
434 _displayName = n; 441 _displayName = n;
435} 442}
436 443
437QDict<QString>* Package::getFields() 444QDict<QString>* Package::getFields()
438{ 445{
439 return &_values; 446 return &_values;
440} 447}
441 448
442QString Package::status() 449QString Package::status()
443{ 450{
444 return _status; 451 return _status;
445} 452}
446 453
447bool Package::isOld() 454bool Package::isOld()
448{ 455{
449 if (!_versions) return false; 456 if (!_versions) return false;
450 QDictIterator<Package> other( *_versions ); 457 QDictIterator<Package> other( *_versions );
451 while ( other.current() ) { 458 while ( other.current() ) {
452 if (other.current()->version() > version() ) return true; 459 if (other.current()->version() > version() ) return true;
453 ++other; 460 ++other;
454 } 461 }
455 return false; 462 return false;
456} 463}
457 464
458bool Package::hasVersions() 465bool Package::hasVersions()
459{ 466{
460 if (!_versions) return false; 467 if (!_versions) return false;
461 else return true; 468 else return true;
462} 469}
463 470
464QDict<Package>* Package::getOtherVersions() 471QDict<Package>* Package::getOtherVersions()
465{ 472{
466 return _versions; 473 return _versions;
467} 474}
468 475
469void Package::setOtherVersions(QDict<Package> *v) 476void Package::setOtherVersions(QDict<Package> *v)
470{ 477{
471 _versions=v; 478 _versions=v;
472} 479}