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
@@ -195,200 +195,200 @@ void Ipkg :: removeStatusEntry()
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;