summaryrefslogtreecommitdiff
path: root/noncore/settings/aqpkg/ipkg.cpp
Unidiff
Diffstat (limited to 'noncore/settings/aqpkg/ipkg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/ipkg.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp
index 3761b67..866afed 100644
--- a/noncore/settings/aqpkg/ipkg.cpp
+++ b/noncore/settings/aqpkg/ipkg.cpp
@@ -99,392 +99,392 @@ void Ipkg :: runIpkg()
99 if ( flags & MAKE_LINKS ) 99 if ( flags & MAKE_LINKS )
100 { 100 {
101 // If destDir == / turn off make links as package is being insalled 101 // If destDir == / turn off make links as package is being insalled
102 // to root already. 102 // to root already.
103 if ( destDir == "/" ) 103 if ( destDir == "/" )
104 flags ^= MAKE_LINKS; 104 flags ^= MAKE_LINKS;
105 } 105 }
106 } 106 }
107 107
108#ifdef X86 108#ifdef X86
109 commands << "-f"; 109 commands << "-f";
110 commands << IPKG_CONF; 110 commands << IPKG_CONF;
111#endif 111#endif
112 112
113 113
114 if ( option == "reinstall" ) 114 if ( option == "reinstall" )
115 commands << "install"; 115 commands << "install";
116 else 116 else
117 commands << option; 117 commands << option;
118 if ( package != "" ) 118 if ( package != "" )
119 commands << package; 119 commands << package;
120 120
121 121
122 if ( package != "" ) 122 if ( package != "" )
123 emit outputText( tr( "Dealing with package %1" ).arg( package) ); 123 emit outputText( tr( "Dealing with package %1" ).arg( package) );
124 124
125 qApp->processEvents(); 125 qApp->processEvents();
126 126
127 // If we are removing, reinstalling or upgrading packages and make links option is selected 127 // If we are removing, reinstalling or upgrading packages and make links option is selected
128 // create the links 128 // create the links
129 if ( option == "remove" || option == "reinstall" || option == "upgrade" ) 129 if ( option == "remove" || option == "reinstall" || option == "upgrade" )
130 { 130 {
131 createLinks = false; 131 createLinks = false;
132 if ( flags & MAKE_LINKS ) 132 if ( flags & MAKE_LINKS )
133 { 133 {
134 emit outputText( tr( "Removing symbolic links...\n" ) ); 134 emit outputText( tr( "Removing symbolic links...\n" ) );
135 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 135 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
136 emit outputText( QString( " " ) ); 136 emit outputText( QString( " " ) );
137 } 137 }
138 } 138 }
139 139
140 // Execute command 140 // Execute command
141 dependantPackages = new QList<QString>; 141 dependantPackages = new QList<QString>;
142 dependantPackages->setAutoDelete( true ); 142 dependantPackages->setAutoDelete( true );
143 143
144 executeIpkgCommand( commands, option ); 144 executeIpkgCommand( commands, option );
145 145
146} 146}
147 147
148void Ipkg :: createSymLinks() 148void Ipkg :: createSymLinks()
149{ 149{
150 if ( option == "install" || option == "reinstall" || option == "upgrade" ) 150 if ( option == "install" || option == "reinstall" || option == "upgrade" )
151 { 151 {
152 // If we are not removing packages and make links option is selected 152 // If we are not removing packages and make links option is selected
153 // create the links 153 // create the links
154 createLinks = true; 154 createLinks = true;
155 if ( flags & MAKE_LINKS ) 155 if ( flags & MAKE_LINKS )
156 { 156 {
157 emit outputText( " " ); 157 emit outputText( " " );
158 emit outputText( tr( "Creating symbolic links for %1." ).arg( package) ); 158 emit outputText( tr( "Creating symbolic links for %1." ).arg( package) );
159 159
160 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 160 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
161 161
162 // link dependant packages that were installed with this release 162 // link dependant packages that were installed with this release
163 QString *pkg; 163 QString *pkg;
164 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) 164 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() )
165 { 165 {
166 if ( *pkg == package ) 166 if ( *pkg == package )
167 continue; 167 continue;
168 emit outputText( " " ); 168 emit outputText( " " );
169 emit outputText( tr( "Creating symbolic links for %1" ).arg( *pkg ) ); 169 emit outputText( tr( "Creating symbolic links for %1" ).arg( *pkg ) );
170 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); 170 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir );
171 } 171 }
172 } 172 }
173 } 173 }
174 174
175 delete dependantPackages; 175 delete dependantPackages;
176 176
177 emit outputText( tr("Finished") ); 177 emit outputText( tr("Finished") );
178 emit outputText( "" ); 178 emit outputText( "" );
179} 179}
180 180
181void Ipkg :: removeStatusEntry() 181void Ipkg :: removeStatusEntry()
182{ 182{
183 QString statusFile = destDir; 183 QString statusFile = destDir;
184 if ( statusFile.right( 1 ) != "/" ) 184 if ( statusFile.right( 1 ) != "/" )
185 statusFile.append( "/" ); 185 statusFile.append( "/" );
186 statusFile.append( "usr/lib/ipkg/status" ); 186 statusFile.append( "usr/lib/ipkg/status" );
187 QString outStatusFile = statusFile; 187 QString outStatusFile = statusFile;
188 outStatusFile.append( ".tmp" ); 188 outStatusFile.append( ".tmp" );
189 189
190 emit outputText( "" ); 190 emit outputText( "" );
191 emit outputText( tr("Removing status entry...") ); 191 emit outputText( tr("Removing status entry...") );
192 QString tempstr = tr("status file - "); 192 QString tempstr = tr("status file - ");
193 tempstr.append( statusFile ); 193 tempstr.append( statusFile );
194 emit outputText( tempstr ); 194 emit outputText( tempstr );
195 tempstr = tr("package - "); 195 tempstr = tr("package - ");
196 tempstr.append( package ); 196 tempstr.append( package );
197 emit outputText( tempstr ); 197 emit outputText( tempstr );
198 198
199 QFile readFile( statusFile ); 199 QFile readFile( statusFile );
200 QFile writeFile( outStatusFile ); 200 QFile writeFile( outStatusFile );
201 201
202 if ( !readFile.open( IO_ReadOnly ) ) 202 if ( !readFile.open( IO_ReadOnly ) )
203 { 203 {
204 tempstr = tr("Couldn't open status file - "); 204 tempstr = tr("Couldn't open status file - ");
205 tempstr.append( statusFile ); 205 tempstr.append( statusFile );
206 emit outputText( tempstr ); 206 emit outputText( tempstr );
207 return; 207 return;
208 } 208 }
209 209
210 if ( !writeFile.open( IO_WriteOnly ) ) 210 if ( !writeFile.open( IO_WriteOnly ) )
211 { 211 {
212 tempstr = tr("Couldn't create tempory status file - "); 212 tempstr = tr("Couldn't create tempory status file - ");
213 tempstr.append( outStatusFile ); 213 tempstr.append( outStatusFile );
214 emit outputText( tempstr ); 214 emit outputText( tempstr );
215 return; 215 return;
216 } 216 }
217 217
218 int i = 0; 218 int i = 0;
219 219
220 QTextStream readStream( &readFile ); 220 QTextStream readStream( &readFile );
221 QTextStream writeStream( &writeFile ); 221 QTextStream writeStream( &writeFile );
222 QString line; 222 QString line;
223 223
224 char k[21]; 224 char k[21];
225 char v[1001]; 225 char v[1001];
226 QString key; 226 QString key;
227 QString value; 227 QString value;
228 228
229 while ( !readStream.atEnd() ) 229 while ( !readStream.atEnd() )
230 { 230 {
231 //read new line 231 //read new line
232 line = readStream.readLine(); 232 line = readStream.readLine();
233 233
234 if ( line.contains( ":", TRUE ) ) 234 if ( line.contains( ":", TRUE ) )
235 { 235 {
236 //grep key and value from line 236 //grep key and value from line
237 k[0] = '\0'; 237 k[0] = '\0';
238 v[0] = '\0'; 238 v[0] = '\0';
239 sscanf( line, "%[^:]: %[^\n]", k, v ); 239 sscanf( line, "%[^:]: %[^\n]", k, v );
240 key = k; 240 key = k;
241 value = v; 241 value = v;
242 key = key.stripWhiteSpace(); 242 key = key.stripWhiteSpace();
243 value = value.stripWhiteSpace(); 243 value = value.stripWhiteSpace();
244 } else { 244 } else {
245 key = ""; 245 key = "";
246 value = ""; 246 value = "";
247 } 247 }
248 248
249 if ( key == "Package" && value == package ) 249 if ( key == "Package" && value == package )
250 { 250 {
251 //skip lines from the deleted package 251 //skip lines from the deleted package
252 while ( ( !readStream.atEnd() ) && ( line.stripWhiteSpace() != "" ) ) 252 while ( ( !readStream.atEnd() ) && ( line.stripWhiteSpace() != "" ) )
253 { 253 {
254 line = readStream.readLine(); 254 line = readStream.readLine();
255 } 255 }
256 } else { 256 } else {
257 257
258 //write other lines into the tempfile 258 //write other lines into the tempfile
259 writeStream << line << "\n"; 259 writeStream << line << "\n";
260 260
261 // Improve UI responsiveness 261 // Improve UI responsiveness
262 i++; 262 i++;
263 if ( ( i % 50 ) == 0 ) 263 if ( ( i % 50 ) == 0 )
264 qApp->processEvents(); 264 qApp->processEvents();
265 } 265 }
266 } 266 }
267 267
268 readFile.close(); 268 readFile.close();
269 writeFile.close(); 269 writeFile.close();
270 270
271 // Remove old status file and put tmp stats file in its place 271 // Remove old status file and put tmp stats file in its place
272 remove( statusFile ); 272 remove( statusFile );
273 rename( outStatusFile, statusFile ); 273 rename( outStatusFile, statusFile );
274 } 274 }
275 275
276int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ ) 276int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ )
277{ 277{
278 // If one is already running - should never be but just to be safe 278 // If one is already running - should never be but just to be safe
279 if ( proc ) 279 if ( proc )
280 { 280 {
281 delete proc; 281 delete proc;
282 proc = 0; 282 proc = 0;
283 } 283 }
284 284
285 // OK we're gonna use OProcess to run this thing 285 // OK we're gonna use OProcess to run this thing
286 proc = new OProcess(); 286 proc = new OProcess();
287 aborted = false; 287 aborted = false;
288 288
289 289
290 // Connect up our slots 290 // Connect up our slots
291 connect(proc, SIGNAL(processExited(OProcess *)), 291 connect(proc, SIGNAL(processExited(OProcess*)),
292 this, SLOT( processFinished())); 292 this, SLOT( processFinished()));
293 293
294 connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), 294 connect(proc, SIGNAL(receivedStdout(OProcess*,char*,int)),
295 this, SLOT(commandStdout(OProcess *, char *, int))); 295 this, SLOT(commandStdout(OProcess*,char*,int)));
296 296
297 connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), 297 connect(proc, SIGNAL(receivedStderr(OProcess*,char*,int)),
298 this, SLOT(commandStderr(OProcess *, char *, int))); 298 this, SLOT(commandStderr(OProcess*,char*,int)));
299 299
300 for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) 300 for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it )
301 { 301 {
302 *proc << (*it).latin1(); 302 *proc << (*it).latin1();
303 } 303 }
304 304
305 // Start the process going 305 // Start the process going
306 finished = false; 306 finished = false;
307 if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) 307 if(!proc->start(OProcess::NotifyOnExit, OProcess::All))
308 { 308 {
309 emit outputText( tr("Couldn't start ipkg process" ) ); 309 emit outputText( tr("Couldn't start ipkg process" ) );
310 } 310 }
311} 311}
312 312
313void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) 313void Ipkg::commandStdout(OProcess*, char *buffer, int buflen)
314{ 314{
315 QString lineStr = buffer; 315 QString lineStr = buffer;
316 if ( lineStr[buflen-1] == '\n' ) 316 if ( lineStr[buflen-1] == '\n' )
317 buflen --; 317 buflen --;
318 lineStr = lineStr.left( buflen ); 318 lineStr = lineStr.left( buflen );
319 emit outputText( lineStr ); 319 emit outputText( lineStr );
320 320
321 // check if we are installing dependant packages 321 // check if we are installing dependant packages
322 if ( option == "install" || option == "reinstall" ) 322 if ( option == "install" || option == "reinstall" )
323 { 323 {
324 // Need to keep track of any dependant packages that get installed 324 // Need to keep track of any dependant packages that get installed
325 // so that we can create links to them as necessary 325 // so that we can create links to them as necessary
326 if ( lineStr.startsWith( "Installing " ) ) 326 if ( lineStr.startsWith( "Installing " ) )
327 { 327 {
328 int start = lineStr.find( " " ) + 1; 328 int start = lineStr.find( " " ) + 1;
329 int end = lineStr.find( " ", start ); 329 int end = lineStr.find( " ", start );
330 QString *package = new QString( lineStr.mid( start, end-start ) ); 330 QString *package = new QString( lineStr.mid( start, end-start ) );
331 dependantPackages->append( package ); 331 dependantPackages->append( package );
332 } 332 }
333 } 333 }
334 else if ( option == "remove" && !( flags & FORCE_DEPENDS ) && 334 else if ( option == "remove" && !( flags & FORCE_DEPENDS ) &&
335 lineStr.find( "is depended upon by packages:" ) != -1 ) 335 lineStr.find( "is depended upon by packages:" ) != -1 )
336 { 336 {
337 // Ipkg should send this to STDERR, but doesn't - so trap here 337 // Ipkg should send this to STDERR, but doesn't - so trap here
338 error = true; 338 error = true;
339 } 339 }
340 340
341 buffer[0] = '\0'; 341 buffer[0] = '\0';
342} 342}
343 343
344void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) 344void Ipkg::commandStderr(OProcess*, char *buffer, int buflen)
345{ 345{
346 QString lineStr = buffer; 346 QString lineStr = buffer;
347 if ( lineStr[buflen-1] == '\n' ) 347 if ( lineStr[buflen-1] == '\n' )
348 buflen --; 348 buflen --;
349 lineStr=lineStr.left( buflen ); 349 lineStr=lineStr.left( buflen );
350 emit outputText( lineStr ); 350 emit outputText( lineStr );
351 buffer[0] = '\0'; 351 buffer[0] = '\0';
352 error = true; 352 error = true;
353} 353}
354 354
355void Ipkg::processFinished() 355void Ipkg::processFinished()
356{ 356{
357 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file 357 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file
358 // to workaround an ipkg bug which stops reinstall to a different location 358 // to workaround an ipkg bug which stops reinstall to a different location
359 359
360 if ( !error && option == "remove" ) 360 if ( !error && option == "remove" )
361 removeStatusEntry(); 361 removeStatusEntry();
362 362
363 delete proc; 363 delete proc;
364 proc = 0; 364 proc = 0;
365 finished = true; 365 finished = true;
366 366
367 emit ipkgFinished(); 367 emit ipkgFinished();
368} 368}
369 369
370 370
371void Ipkg :: abort() 371void Ipkg :: abort()
372{ 372{
373 if ( proc ) 373 if ( proc )
374 { 374 {
375 proc->kill(); 375 proc->kill();
376 aborted = true; 376 aborted = true;
377 } 377 }
378} 378}
379 379
380void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) 380void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir )
381{ 381{
382 if ( dest == "root" || dest == "/" ) 382 if ( dest == "root" || dest == "/" )
383 return; 383 return;
384 384
385 qApp->processEvents(); 385 qApp->processEvents();
386 QStringList *fileList = getList( packFileName, destDir ); 386 QStringList *fileList = getList( packFileName, destDir );
387 qApp->processEvents(); 387 qApp->processEvents();
388 processFileList( fileList, destDir ); 388 processFileList( fileList, destDir );
389 delete fileList; 389 delete fileList;
390} 390}
391 391
392QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) 392QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir )
393{ 393{
394 QString packageFileDir = destDir; 394 QString packageFileDir = destDir;
395 packageFileDir.append( "/usr/lib/ipkg/info/" ); 395 packageFileDir.append( "/usr/lib/ipkg/info/" );
396 packageFileDir.append( packageFilename ); 396 packageFileDir.append( packageFilename );
397 packageFileDir.append( ".list" ); 397 packageFileDir.append( ".list" );
398 QFile f( packageFileDir ); 398 QFile f( packageFileDir );
399 399
400 if ( !f.open(IO_ReadOnly) ) 400 if ( !f.open(IO_ReadOnly) )
401 { 401 {
402 // Couldn't open from dest, try from / 402 // Couldn't open from dest, try from /
403 f.close(); 403 f.close();
404 404
405 packageFileDir = "/usr/lib/ipkg/info/"; 405 packageFileDir = "/usr/lib/ipkg/info/";
406 packageFileDir.append( packageFilename ); 406 packageFileDir.append( packageFilename );
407 packageFileDir.append( ".list" ); 407 packageFileDir.append( ".list" );
408 f.setName( packageFileDir ); 408 f.setName( packageFileDir );
409 if ( ! f.open(IO_ReadOnly) ) 409 if ( ! f.open(IO_ReadOnly) )
410 { 410 {
411 QString tempstr = tr("Could not open :"); 411 QString tempstr = tr("Could not open :");
412 tempstr.append( packageFileDir ); 412 tempstr.append( packageFileDir );
413 emit outputText( tempstr ); 413 emit outputText( tempstr );
414 return (QStringList*)0; 414 return (QStringList*)0;
415 } 415 }
416 } 416 }
417 QStringList *fileList = new QStringList(); 417 QStringList *fileList = new QStringList();
418 QTextStream t( &f ); 418 QTextStream t( &f );
419 while ( !t.eof() ) 419 while ( !t.eof() )
420 *fileList += t.readLine(); 420 *fileList += t.readLine();
421 421
422 f.close(); 422 f.close();
423 return fileList; 423 return fileList;
424} 424}
425 425
426void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) 426void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir )
427{ 427{
428 if ( !fileList || fileList->isEmpty() ) 428 if ( !fileList || fileList->isEmpty() )
429 return; 429 return;
430 430
431 QString baseDir = ROOT; 431 QString baseDir = ROOT;
432 432
433 if ( createLinks == true ) 433 if ( createLinks == true )
434 { 434 {
435 for ( uint i=0; i < fileList->count(); i++ ) 435 for ( uint i=0; i < fileList->count(); i++ )
436 { 436 {
437 processLinkDir( (*fileList)[i], baseDir, destDir ); 437 processLinkDir( (*fileList)[i], baseDir, destDir );
438 qApp->processEvents(); 438 qApp->processEvents();
439 } 439 }
440 } 440 }
441 else 441 else
442 { 442 {
443 for ( int i = fileList->count()-1; i >= 0 ; i-- ) 443 for ( int i = fileList->count()-1; i >= 0 ; i-- )
444 { 444 {
445 processLinkDir( (*fileList)[i], baseDir, destDir ); 445 processLinkDir( (*fileList)[i], baseDir, destDir );
446 qApp->processEvents(); 446 qApp->processEvents();
447 } 447 }
448 } 448 }
449} 449}
450 450
451void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) 451void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir )
452{ 452{
453 453
454 QString sourceFile = baseDir; 454 QString sourceFile = baseDir;
455 sourceFile.append( file ); 455 sourceFile.append( file );
456 456
457 QString linkFile = destDir; 457 QString linkFile = destDir;
458 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) 458 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" )
459 { 459 {
460 linkFile.append( file.mid( 1 ) ); 460 linkFile.append( file.mid( 1 ) );
461 } 461 }
462 else 462 else
463 { 463 {
464 linkFile.append( file ); 464 linkFile.append( file );
465 } 465 }
466 QString text; 466 QString text;
467 if ( createLinks ) 467 if ( createLinks )
468 { 468 {
469 // If this file is a directory (ends with a /) and it doesn't exist, 469 // If this file is a directory (ends with a /) and it doesn't exist,
470 // we need to create it 470 // we need to create it
471 if ( file.right(1) == "/" ) 471 if ( file.right(1) == "/" )
472 { 472 {
473 QFileInfo f( linkFile ); 473 QFileInfo f( linkFile );
474 if ( !f.exists() ) 474 if ( !f.exists() )
475 { 475 {
476 QString tempstr = tr("Creating directory "); 476 QString tempstr = tr("Creating directory ");
477 tempstr.append( linkFile ); 477 tempstr.append( linkFile );
478 emit outputText( tempstr ); 478 emit outputText( tempstr );
479 QDir d; 479 QDir d;
480 d.mkdir( linkFile, true ); 480 d.mkdir( linkFile, true );
481 } 481 }
482// else 482// else
483// emit outputText( QString( "Directory " ) + linkFile + " already exists" ); 483// emit outputText( QString( "Directory " ) + linkFile + " already exists" );
484 484
485 } 485 }
486 else 486 else
487 { 487 {
488 int rc = symlink( sourceFile, linkFile ); 488 int rc = symlink( sourceFile, linkFile );
489 text = ( rc == 0 ? tr( "Linked %1 to %2" ) : tr( "Failed to link %1 to %2" ) ). 489 text = ( rc == 0 ? tr( "Linked %1 to %2" ) : tr( "Failed to link %1 to %2" ) ).
490 arg( sourceFile ). 490 arg( sourceFile ).