-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp index 7afe04f..29bf40d 100644 --- a/noncore/settings/aqpkg/ipkg.cpp +++ b/noncore/settings/aqpkg/ipkg.cpp | |||
@@ -218,192 +218,207 @@ void Ipkg :: removeStatusEntry() | |||
218 | in.getline( line, 1000 ); | 218 | in.getline( line, 1000 ); |
219 | if ( in.eof() ) | 219 | if ( in.eof() ) |
220 | continue; | 220 | continue; |
221 | 221 | ||
222 | k[0] = '\0'; | 222 | k[0] = '\0'; |
223 | v[0] = '\0'; | 223 | v[0] = '\0'; |
224 | 224 | ||
225 | sscanf( line, "%[^:]: %[^\n]", k, v ); | 225 | sscanf( line, "%[^:]: %[^\n]", k, v ); |
226 | key = k; | 226 | key = k; |
227 | value = v; | 227 | value = v; |
228 | key = key.stripWhiteSpace(); | 228 | key = key.stripWhiteSpace(); |
229 | value = value.stripWhiteSpace(); | 229 | value = value.stripWhiteSpace(); |
230 | if ( key == "Package" && value == package ) | 230 | if ( key == "Package" && value == package ) |
231 | { | 231 | { |
232 | // Ignore all lines up to next empty | 232 | // Ignore all lines up to next empty |
233 | do | 233 | do |
234 | { | 234 | { |
235 | in.getline( line, 1000 ); | 235 | in.getline( line, 1000 ); |
236 | if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) | 236 | if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) |
237 | continue; | 237 | continue; |
238 | } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); | 238 | } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); |
239 | } | 239 | } |
240 | 240 | ||
241 | lines.push_back( QString( line ) ); | 241 | lines.push_back( QString( line ) ); |
242 | // out << line << endl; | 242 | // out << line << endl; |
243 | } while ( !in.eof() ); | 243 | } while ( !in.eof() ); |
244 | 244 | ||
245 | // Write lines out | 245 | // Write lines out |
246 | vector<QString>::iterator it; | 246 | vector<QString>::iterator it; |
247 | for ( it = lines.begin() ; it != lines.end() ; ++it ) | 247 | for ( it = lines.begin() ; it != lines.end() ; ++it ) |
248 | { | 248 | { |
249 | cout << "Writing " << (const char *)(*it) << endl; | 249 | cout << "Writing " << (const char *)(*it) << endl; |
250 | out << (const char *)(*it) << endl; | 250 | out << (const char *)(*it) << endl; |
251 | } | 251 | } |
252 | 252 | ||
253 | in.close(); | 253 | in.close(); |
254 | out.close(); | 254 | out.close(); |
255 | 255 | ||
256 | // Remove old status file and put tmp stats file in its place | 256 | // Remove old status file and put tmp stats file in its place |
257 | remove( statusFile ); | 257 | remove( statusFile ); |
258 | rename( outStatusFile, statusFile ); | 258 | rename( outStatusFile, statusFile ); |
259 | } | 259 | } |
260 | 260 | ||
261 | int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString option ) | 261 | int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString option ) |
262 | { | 262 | { |
263 | // If one is already running - should never be but just to be safe | 263 | // If one is already running - should never be but just to be safe |
264 | if ( proc ) | 264 | if ( proc ) |
265 | { | 265 | { |
266 | delete proc; | 266 | delete proc; |
267 | proc = 0; | 267 | proc = 0; |
268 | } | 268 | } |
269 | 269 | ||
270 | // OK we're gonna use OProcess to run this thing | 270 | // OK we're gonna use OProcess to run this thing |
271 | proc = new OProcess(); | 271 | proc = new OProcess(); |
272 | aborted = false; | 272 | aborted = false; |
273 | 273 | ||
274 | 274 | ||
275 | // Connect up our slots | 275 | // Connect up our slots |
276 | connect(proc, SIGNAL(processExited(OProcess *)), | 276 | connect(proc, SIGNAL(processExited(OProcess *)), |
277 | this, SLOT( processFinished())); | 277 | this, SLOT( processFinished())); |
278 | 278 | ||
279 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), | 279 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), |
280 | this, SLOT(commandStdout(OProcess *, char *, int))); | 280 | this, SLOT(commandStdout(OProcess *, char *, int))); |
281 | 281 | ||
282 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), | 282 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), |
283 | this, SLOT(commandStderr(OProcess *, char *, int))); | 283 | this, SLOT(commandStderr(OProcess *, char *, int))); |
284 | 284 | ||
285 | for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) | 285 | for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) |
286 | { | 286 | { |
287 | qDebug( "%s ", (*it).latin1() ); | 287 | qDebug( "%s ", (*it).latin1() ); |
288 | *proc << (*it).latin1(); | 288 | *proc << (*it).latin1(); |
289 | } | 289 | } |
290 | cout << endl; | 290 | cout << endl; |
291 | 291 | ||
292 | // Start the process going | 292 | // Start the process going |
293 | finished = false; | 293 | finished = false; |
294 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) | 294 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) |
295 | { | 295 | { |
296 | emit outputText( QString( "Couldn't start ipkg process" ) ); | 296 | emit outputText( QString( "Couldn't start ipkg process" ) ); |
297 | qDebug( "Couldn't start ipkg process!" ); | 297 | qDebug( "Couldn't start ipkg process!" ); |
298 | } | 298 | } |
299 | 299 | ||
300 | // Now wait for it to finish | 300 | // Now wait for it to finish |
301 | while ( !finished ) | 301 | while ( !finished ) |
302 | qApp->processEvents(); | 302 | qApp->processEvents(); |
303 | } | 303 | } |
304 | 304 | ||
305 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) | 305 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) |
306 | { | 306 | { |
307 | qDebug("received stdout %d bytes", buflen); | 307 | qDebug("received stdout %d bytes", buflen); |
308 | 308 | ||
309 | QString lineStr = buffer; | 309 | QString lineStr = buffer; |
310 | if ( lineStr[buflen-1] == '\n' ) | 310 | if ( lineStr[buflen-1] == '\n' ) |
311 | buflen --; | 311 | buflen --; |
312 | lineStr = lineStr.left( buflen ); | 312 | lineStr = lineStr.left( buflen ); |
313 | emit outputText( lineStr ); | 313 | emit outputText( lineStr ); |
314 | |||
315 | // check if we are installing dependant packages | ||
316 | if ( option == "install" || option == "reinstall" ) | ||
317 | { | ||
318 | // Need to keep track of any dependant packages that get installed | ||
319 | // so that we can create links to them as necessary | ||
320 | if ( lineStr.startsWith( "Installing " ) ) | ||
321 | { | ||
322 | int start = lineStr.find( " " ) + 1; | ||
323 | int end = lineStr.find( " ", start ); | ||
324 | QString *package = new QString( lineStr.mid( start, end-start ) ); | ||
325 | dependantPackages->append( package ); | ||
326 | } | ||
327 | } | ||
328 | |||
314 | qDebug(lineStr); | 329 | qDebug(lineStr); |
315 | buffer[0] = '\0'; | 330 | buffer[0] = '\0'; |
316 | } | 331 | } |
317 | 332 | ||
318 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) | 333 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) |
319 | { | 334 | { |
320 | qDebug("received stderrt %d bytes", buflen); | 335 | qDebug("received stderrt %d bytes", buflen); |
321 | 336 | ||
322 | QString lineStr = buffer; | 337 | QString lineStr = buffer; |
323 | if ( lineStr[buflen-1] == '\n' ) | 338 | if ( lineStr[buflen-1] == '\n' ) |
324 | buflen --; | 339 | buflen --; |
325 | lineStr=lineStr.left( buflen ); | 340 | lineStr=lineStr.left( buflen ); |
326 | emit outputText( lineStr ); | 341 | emit outputText( lineStr ); |
327 | buffer[0] = '\0'; | 342 | buffer[0] = '\0'; |
328 | } | 343 | } |
329 | 344 | ||
330 | void Ipkg::processFinished() | 345 | void Ipkg::processFinished() |
331 | { | 346 | { |
332 | delete proc; | 347 | delete proc; |
333 | proc = 0; | 348 | proc = 0; |
334 | finished = true; | 349 | finished = true; |
335 | } | 350 | } |
336 | 351 | ||
337 | 352 | ||
338 | void Ipkg :: abort() | 353 | void Ipkg :: abort() |
339 | { | 354 | { |
340 | if ( proc ) | 355 | if ( proc ) |
341 | { | 356 | { |
342 | proc->kill(); | 357 | proc->kill(); |
343 | aborted = true; | 358 | aborted = true; |
344 | } | 359 | } |
345 | } | 360 | } |
346 | 361 | ||
347 | /* | 362 | /* |
348 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) | 363 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) |
349 | { | 364 | { |
350 | FILE *fp = NULL; | 365 | FILE *fp = NULL; |
351 | char line[130]; | 366 | char line[130]; |
352 | QString lineStr, lineStrOld; | 367 | QString lineStr, lineStrOld; |
353 | int ret = false; | 368 | int ret = false; |
354 | 369 | ||
355 | fp = popen( (const char *) cmd, "r"); | 370 | fp = popen( (const char *) cmd, "r"); |
356 | if ( fp == NULL ) | 371 | if ( fp == NULL ) |
357 | { | 372 | { |
358 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; | 373 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; |
359 | QString text; | 374 | QString text; |
360 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); | 375 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); |
361 | emit outputText( text ); | 376 | emit outputText( text ); |
362 | } | 377 | } |
363 | else | 378 | else |
364 | { | 379 | { |
365 | while ( fgets( line, sizeof line, fp) != NULL ) | 380 | while ( fgets( line, sizeof line, fp) != NULL ) |
366 | { | 381 | { |
367 | lineStr = line; | 382 | lineStr = line; |
368 | lineStr=lineStr.left( lineStr.length()-1 ); | 383 | lineStr=lineStr.left( lineStr.length()-1 ); |
369 | 384 | ||
370 | if ( lineStr != lineStrOld ) | 385 | if ( lineStr != lineStrOld ) |
371 | { | 386 | { |
372 | //See if we're finished | 387 | //See if we're finished |
373 | if ( option == "install" || option == "reinstall" ) | 388 | if ( option == "install" || option == "reinstall" ) |
374 | { | 389 | { |
375 | // Need to keep track of any dependant packages that get installed | 390 | // Need to keep track of any dependant packages that get installed |
376 | // so that we can create links to them as necessary | 391 | // so that we can create links to them as necessary |
377 | if ( lineStr.startsWith( "Installing " ) ) | 392 | if ( lineStr.startsWith( "Installing " ) ) |
378 | { | 393 | { |
379 | int start = lineStr.find( " " ) + 1; | 394 | int start = lineStr.find( " " ) + 1; |
380 | int end = lineStr.find( " ", start ); | 395 | int end = lineStr.find( " ", start ); |
381 | QString *package = new QString( lineStr.mid( start, end-start ) ); | 396 | QString *package = new QString( lineStr.mid( start, end-start ) ); |
382 | dependantPackages->append( package ); | 397 | dependantPackages->append( package ); |
383 | } | 398 | } |
384 | } | 399 | } |
385 | 400 | ||
386 | if ( option == "update" ) | 401 | if ( option == "update" ) |
387 | { | 402 | { |
388 | if (lineStr.contains("Updated list")) | 403 | if (lineStr.contains("Updated list")) |
389 | ret = true; | 404 | ret = true; |
390 | } | 405 | } |
391 | else if ( option == "download" ) | 406 | else if ( option == "download" ) |
392 | { | 407 | { |
393 | if (lineStr.contains("Downloaded")) | 408 | if (lineStr.contains("Downloaded")) |
394 | ret = true; | 409 | ret = true; |
395 | } | 410 | } |
396 | else | 411 | else |
397 | { | 412 | { |
398 | if (lineStr.contains("Done")) | 413 | if (lineStr.contains("Done")) |
399 | ret = true; | 414 | ret = true; |
400 | } | 415 | } |
401 | 416 | ||
402 | emit outputText( lineStr ); | 417 | emit outputText( lineStr ); |
403 | } | 418 | } |
404 | lineStrOld = lineStr; | 419 | lineStrOld = lineStr; |
405 | qApp->processEvents(); | 420 | qApp->processEvents(); |
406 | } | 421 | } |
407 | pclose(fp); | 422 | pclose(fp); |
408 | } | 423 | } |
409 | 424 | ||