author | drw <drw> | 2003-04-23 01:04:02 (UTC) |
---|---|---|
committer | drw <drw> | 2003-04-23 01:04:02 (UTC) |
commit | 43b2c74f7d32ce9c744e4d79e62a92e0181604c3 (patch) (unidiff) | |
tree | 894049bfdc5724ea167f3dbc437cf0d18b93f3c1 | |
parent | 509ac60dfd2e0829f56fb65407ddbe57f7668d70 (diff) | |
download | opie-43b2c74f7d32ce9c744e4d79e62a92e0181604c3.zip opie-43b2c74f7d32ce9c744e4d79e62a92e0181604c3.tar.gz opie-43b2c74f7d32ce9c744e4d79e62a92e0181604c3.tar.bz2 |
Fix for bug #864 and some other code tweaks to reduce executable size
-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 80 |
1 files changed, 46 insertions, 34 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp index 7df643e..e906653 100644 --- a/noncore/settings/aqpkg/ipkg.cpp +++ b/noncore/settings/aqpkg/ipkg.cpp | |||
@@ -143,264 +143,269 @@ bool Ipkg :: runIpkg( ) | |||
143 | return false; | 143 | return false; |
144 | 144 | ||
145 | if ( option == "install" || option == "reinstall" || option == "upgrade" ) | 145 | if ( option == "install" || option == "reinstall" || option == "upgrade" ) |
146 | { | 146 | { |
147 | // If we are not removing packages and make links option is selected | 147 | // If we are not removing packages and make links option is selected |
148 | // create the links | 148 | // create the links |
149 | createLinks = true; | 149 | createLinks = true; |
150 | if ( flags & MAKE_LINKS ) | 150 | if ( flags & MAKE_LINKS ) |
151 | { | 151 | { |
152 | emit outputText( " " ); | 152 | emit outputText( " " ); |
153 | emit outputText( QString( "Creating symbolic links for " )+ package ); | 153 | emit outputText( QString( "Creating symbolic links for " )+ package ); |
154 | 154 | ||
155 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 155 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
156 | 156 | ||
157 | // link dependant packages that were installed with this release | 157 | // link dependant packages that were installed with this release |
158 | QString *pkg; | 158 | QString *pkg; |
159 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) | 159 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) |
160 | { | 160 | { |
161 | if ( *pkg == package ) | 161 | if ( *pkg == package ) |
162 | continue; | 162 | continue; |
163 | emit outputText( " " ); | 163 | emit outputText( " " ); |
164 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); | 164 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); |
165 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); | 165 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); |
166 | } | 166 | } |
167 | } | 167 | } |
168 | } | 168 | } |
169 | 169 | ||
170 | delete dependantPackages; | 170 | delete dependantPackages; |
171 | 171 | ||
172 | emit outputText( "Finished" ); | 172 | emit outputText( "Finished" ); |
173 | emit outputText( "" ); | 173 | emit outputText( "" ); |
174 | return ret; | 174 | return ret; |
175 | |||
176 | } | 175 | } |
177 | 176 | ||
178 | void Ipkg :: removeStatusEntry() | 177 | void Ipkg :: removeStatusEntry() |
179 | { | 178 | { |
180 | QString statusFile = destDir; | 179 | QString statusFile = destDir; |
181 | if ( statusFile.right( 1 ) != "/" ) | 180 | if ( statusFile.right( 1 ) != "/" ) |
182 | statusFile += "/"; | 181 | statusFile.append( "/" ); |
183 | statusFile += "usr/lib/ipkg/status"; | 182 | statusFile.append( "usr/lib/ipkg/status" ); |
184 | QString outStatusFile = statusFile + ".tmp"; | 183 | QString outStatusFile = statusFile; |
184 | outStatusFile.append( ".tmp" ); | ||
185 | 185 | ||
186 | emit outputText( "" ); | 186 | emit outputText( "" ); |
187 | emit outputText( "Removing status entry..." ); | 187 | emit outputText( "Removing status entry..." ); |
188 | emit outputText( QString( "status file - " )+ statusFile ); | 188 | QString tempstr = "status file - "; |
189 | emit outputText( QString( "package - " )+ package ); | 189 | tempstr.append( statusFile ); |
190 | emit outputText( tempstr ); | ||
191 | tempstr = "package - "; | ||
192 | tempstr.append( package ); | ||
193 | emit outputText( tempstr ); | ||
190 | 194 | ||
191 | ifstream in( statusFile ); | 195 | ifstream in( statusFile ); |
192 | ofstream out( outStatusFile ); | 196 | ofstream out( outStatusFile ); |
193 | if ( !in.is_open() ) | 197 | if ( !in.is_open() ) |
194 | { | 198 | { |
195 | emit outputText( QString( "Couldn't open status file - " )+ statusFile ); | 199 | tempstr = "Couldn't open status file - "; |
200 | tempstr.append( statusFile ); | ||
201 | emit outputText( tempstr ); | ||
196 | return; | 202 | return; |
197 | } | 203 | } |
198 | 204 | ||
199 | if ( !out.is_open() ) | 205 | if ( !out.is_open() ) |
200 | { | 206 | { |
201 | emit outputText( QString( "Couldn't create tempory status file - " )+ outStatusFile ); | 207 | tempstr = "Couldn't create tempory status file - "; |
208 | tempstr.append( outStatusFile ); | ||
209 | emit outputText( tempstr ); | ||
202 | return; | 210 | return; |
203 | } | 211 | } |
204 | 212 | ||
205 | char line[1001]; | 213 | char line[1001]; |
206 | char k[21]; | 214 | char k[21]; |
207 | char v[1001]; | 215 | char v[1001]; |
208 | QString key; | 216 | QString key; |
209 | QString value; | 217 | QString value; |
210 | vector<QString> lines; | 218 | vector<QString> lines; |
211 | do | 219 | do |
212 | { | 220 | { |
213 | in.getline( line, 1000 ); | 221 | in.getline( line, 1000 ); |
214 | if ( in.eof() ) | 222 | if ( in.eof() ) |
215 | continue; | 223 | continue; |
216 | 224 | ||
217 | k[0] = '\0'; | 225 | k[0] = '\0'; |
218 | v[0] = '\0'; | 226 | v[0] = '\0'; |
219 | 227 | ||
220 | sscanf( line, "%[^:]: %[^\n]", k, v ); | 228 | sscanf( line, "%[^:]: %[^\n]", k, v ); |
221 | key = k; | 229 | key = k; |
222 | value = v; | 230 | value = v; |
223 | key = key.stripWhiteSpace(); | 231 | key = key.stripWhiteSpace(); |
224 | value = value.stripWhiteSpace(); | 232 | value = value.stripWhiteSpace(); |
225 | if ( key == "Package" && value == package ) | 233 | if ( key == "Package" && value == package ) |
226 | { | 234 | { |
227 | // Ignore all lines up to next empty | 235 | // Ignore all lines up to next empty |
228 | do | 236 | do |
229 | { | 237 | { |
230 | in.getline( line, 1000 ); | 238 | in.getline( line, 1000 ); |
231 | if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) | 239 | if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) |
232 | continue; | 240 | continue; |
233 | } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); | 241 | } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); |
234 | } | 242 | } |
235 | 243 | ||
236 | lines.push_back( QString( line ) ); | 244 | lines.push_back( QString( line ) ); |
237 | // out << line << endl; | 245 | out << line << endl; |
238 | } while ( !in.eof() ); | 246 | } while ( !in.eof() ); |
239 | 247 | ||
240 | // Write lines out | 248 | // Write lines out |
241 | vector<QString>::iterator it; | 249 | vector<QString>::iterator it; |
242 | for ( it = lines.begin() ; it != lines.end() ; ++it ) | 250 | for ( it = lines.begin() ; it != lines.end() ; ++it ) |
243 | { | 251 | { |
244 | cout << "Writing " << (const char *)(*it) << endl; | ||
245 | out << (const char *)(*it) << endl; | 252 | out << (const char *)(*it) << endl; |
246 | } | 253 | } |
247 | 254 | ||
248 | in.close(); | 255 | in.close(); |
249 | out.close(); | 256 | out.close(); |
250 | 257 | ||
251 | // Remove old status file and put tmp stats file in its place | 258 | // Remove old status file and put tmp stats file in its place |
252 | remove( statusFile ); | 259 | remove( statusFile ); |
253 | rename( outStatusFile, statusFile ); | 260 | rename( outStatusFile, statusFile ); |
254 | } | 261 | } |
255 | 262 | ||
256 | int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ ) | 263 | int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ ) |
257 | { | 264 | { |
258 | // If one is already running - should never be but just to be safe | 265 | // If one is already running - should never be but just to be safe |
259 | if ( proc ) | 266 | if ( proc ) |
260 | { | 267 | { |
261 | delete proc; | 268 | delete proc; |
262 | proc = 0; | 269 | proc = 0; |
263 | } | 270 | } |
264 | 271 | ||
265 | // OK we're gonna use OProcess to run this thing | 272 | // OK we're gonna use OProcess to run this thing |
266 | proc = new OProcess(); | 273 | proc = new OProcess(); |
267 | aborted = false; | 274 | aborted = false; |
268 | 275 | ||
269 | 276 | ||
270 | // Connect up our slots | 277 | // Connect up our slots |
271 | connect(proc, SIGNAL(processExited(OProcess *)), | 278 | connect(proc, SIGNAL(processExited(OProcess *)), |
272 | this, SLOT( processFinished())); | 279 | this, SLOT( processFinished())); |
273 | 280 | ||
274 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), | 281 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), |
275 | this, SLOT(commandStdout(OProcess *, char *, int))); | 282 | this, SLOT(commandStdout(OProcess *, char *, int))); |
276 | 283 | ||
277 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), | 284 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), |
278 | this, SLOT(commandStderr(OProcess *, char *, int))); | 285 | this, SLOT(commandStderr(OProcess *, char *, int))); |
279 | 286 | ||
280 | for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) | 287 | for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) |
281 | { | 288 | { |
282 | qDebug( "%s ", (*it).latin1() ); | ||
283 | *proc << (*it).latin1(); | 289 | *proc << (*it).latin1(); |
284 | } | 290 | } |
285 | cout << endl; | ||
286 | 291 | ||
287 | // Start the process going | 292 | // Start the process going |
288 | finished = false; | 293 | finished = false; |
289 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) | 294 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) |
290 | { | 295 | { |
291 | emit outputText( QString( "Couldn't start ipkg process" ) ); | 296 | emit outputText( QString( "Couldn't start ipkg process" ) ); |
292 | qDebug( "Couldn't start ipkg process!" ); | ||
293 | } | 297 | } |
294 | 298 | ||
295 | // Now wait for it to finish | 299 | // Now wait for it to finish |
296 | while ( !finished ) | 300 | while ( !finished ) |
297 | qApp->processEvents(); | 301 | qApp->processEvents(); |
298 | } | 302 | } |
299 | 303 | ||
300 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) | 304 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) |
301 | { | 305 | { |
302 | qDebug("received stdout %d bytes", buflen); | ||
303 | |||
304 | QString lineStr = buffer; | 306 | QString lineStr = buffer; |
305 | if ( lineStr[buflen-1] == '\n' ) | 307 | if ( lineStr[buflen-1] == '\n' ) |
306 | buflen --; | 308 | buflen --; |
307 | lineStr = lineStr.left( buflen ); | 309 | lineStr = lineStr.left( buflen ); |
308 | emit outputText( lineStr ); | 310 | emit outputText( lineStr ); |
309 | 311 | ||
310 | // check if we are installing dependant packages | 312 | // check if we are installing dependant packages |
311 | if ( option == "install" || option == "reinstall" ) | 313 | if ( option == "install" || option == "reinstall" ) |
312 | { | 314 | { |
313 | // Need to keep track of any dependant packages that get installed | 315 | // Need to keep track of any dependant packages that get installed |
314 | // so that we can create links to them as necessary | 316 | // so that we can create links to them as necessary |
315 | if ( lineStr.startsWith( "Installing " ) ) | 317 | if ( lineStr.startsWith( "Installing " ) ) |
316 | { | 318 | { |
317 | int start = lineStr.find( " " ) + 1; | 319 | int start = lineStr.find( " " ) + 1; |
318 | int end = lineStr.find( " ", start ); | 320 | int end = lineStr.find( " ", start ); |
319 | QString *package = new QString( lineStr.mid( start, end-start ) ); | 321 | QString *package = new QString( lineStr.mid( start, end-start ) ); |
320 | dependantPackages->append( package ); | 322 | dependantPackages->append( package ); |
321 | } | 323 | } |
322 | } | 324 | } |
325 | else if ( option == "remove" && !( flags & FORCE_DEPENDS ) && | ||
326 | lineStr.find( "is depended upon by packages:" ) != -1 ) | ||
327 | { | ||
328 | // Ipkg should send this to STDERR, but doesn't - so trap here | ||
329 | error = true; | ||
330 | } | ||
323 | 331 | ||
324 | qDebug(lineStr); | ||
325 | buffer[0] = '\0'; | 332 | buffer[0] = '\0'; |
326 | } | 333 | } |
327 | 334 | ||
328 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) | 335 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) |
329 | { | 336 | { |
330 | qDebug("received stderrt %d bytes", buflen); | ||
331 | |||
332 | QString lineStr = buffer; | 337 | QString lineStr = buffer; |
333 | if ( lineStr[buflen-1] == '\n' ) | 338 | if ( lineStr[buflen-1] == '\n' ) |
334 | buflen --; | 339 | buflen --; |
335 | lineStr=lineStr.left( buflen ); | 340 | lineStr=lineStr.left( buflen ); |
336 | emit outputText( lineStr ); | 341 | emit outputText( lineStr ); |
337 | buffer[0] = '\0'; | 342 | buffer[0] = '\0'; |
338 | error = true; | 343 | error = true; |
339 | } | 344 | } |
340 | 345 | ||
341 | void Ipkg::processFinished() | 346 | void Ipkg::processFinished() |
342 | { | 347 | { |
343 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file | 348 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file |
344 | // to workaround an ipkg bug which stops reinstall to a different location | 349 | // to workaround an ipkg bug which stops reinstall to a different location |
350 | |||
345 | if ( !error && option == "remove" ) | 351 | if ( !error && option == "remove" ) |
346 | removeStatusEntry(); | 352 | removeStatusEntry(); |
347 | 353 | ||
348 | delete proc; | 354 | delete proc; |
349 | proc = 0; | 355 | proc = 0; |
350 | finished = true; | 356 | finished = true; |
351 | } | 357 | } |
352 | 358 | ||
353 | 359 | ||
354 | void Ipkg :: abort() | 360 | void Ipkg :: abort() |
355 | { | 361 | { |
356 | if ( proc ) | 362 | if ( proc ) |
357 | { | 363 | { |
358 | proc->kill(); | 364 | proc->kill(); |
359 | aborted = true; | 365 | aborted = true; |
360 | } | 366 | } |
361 | } | 367 | } |
362 | 368 | ||
363 | /* | 369 | /* |
364 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) | 370 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) |
365 | { | 371 | { |
366 | FILE *fp = NULL; | 372 | FILE *fp = NULL; |
367 | char line[130]; | 373 | char line[130]; |
368 | QString lineStr, lineStrOld; | 374 | QString lineStr, lineStrOld; |
369 | int ret = false; | 375 | int ret = false; |
370 | 376 | ||
371 | fp = popen( (const char *) cmd, "r"); | 377 | fp = popen( (const char *) cmd, "r"); |
372 | if ( fp == NULL ) | 378 | if ( fp == NULL ) |
373 | { | 379 | { |
374 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; | ||
375 | QString text; | 380 | QString text; |
376 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); | 381 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); |
377 | emit outputText( text ); | 382 | emit outputText( text ); |
378 | } | 383 | } |
379 | else | 384 | else |
380 | { | 385 | { |
381 | while ( fgets( line, sizeof line, fp) != NULL ) | 386 | while ( fgets( line, sizeof line, fp) != NULL ) |
382 | { | 387 | { |
383 | lineStr = line; | 388 | lineStr = line; |
384 | lineStr=lineStr.left( lineStr.length()-1 ); | 389 | lineStr=lineStr.left( lineStr.length()-1 ); |
385 | 390 | ||
386 | if ( lineStr != lineStrOld ) | 391 | if ( lineStr != lineStrOld ) |
387 | { | 392 | { |
388 | //See if we're finished | 393 | //See if we're finished |
389 | if ( option == "install" || option == "reinstall" ) | 394 | if ( option == "install" || option == "reinstall" ) |
390 | { | 395 | { |
391 | // Need to keep track of any dependant packages that get installed | 396 | // Need to keep track of any dependant packages that get installed |
392 | // so that we can create links to them as necessary | 397 | // so that we can create links to them as necessary |
393 | if ( lineStr.startsWith( "Installing " ) ) | 398 | if ( lineStr.startsWith( "Installing " ) ) |
394 | { | 399 | { |
395 | int start = lineStr.find( " " ) + 1; | 400 | int start = lineStr.find( " " ) + 1; |
396 | int end = lineStr.find( " ", start ); | 401 | int end = lineStr.find( " ", start ); |
397 | QString *package = new QString( lineStr.mid( start, end-start ) ); | 402 | QString *package = new QString( lineStr.mid( start, end-start ) ); |
398 | dependantPackages->append( package ); | 403 | dependantPackages->append( package ); |
399 | } | 404 | } |
400 | } | 405 | } |
401 | 406 | ||
402 | if ( option == "update" ) | 407 | if ( option == "update" ) |
403 | { | 408 | { |
404 | if (lineStr.contains("Updated list")) | 409 | if (lineStr.contains("Updated list")) |
405 | ret = true; | 410 | ret = true; |
406 | } | 411 | } |
@@ -412,155 +417,162 @@ int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) | |||
412 | else | 417 | else |
413 | { | 418 | { |
414 | if (lineStr.contains("Done")) | 419 | if (lineStr.contains("Done")) |
415 | ret = true; | 420 | ret = true; |
416 | } | 421 | } |
417 | 422 | ||
418 | emit outputText( lineStr ); | 423 | emit outputText( lineStr ); |
419 | } | 424 | } |
420 | lineStrOld = lineStr; | 425 | lineStrOld = lineStr; |
421 | qApp->processEvents(); | 426 | qApp->processEvents(); |
422 | } | 427 | } |
423 | pclose(fp); | 428 | pclose(fp); |
424 | } | 429 | } |
425 | 430 | ||
426 | return ret; | 431 | return ret; |
427 | } | 432 | } |
428 | */ | 433 | */ |
429 | 434 | ||
430 | void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) | 435 | void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) |
431 | { | 436 | { |
432 | if ( dest == "root" || dest == "/" ) | 437 | if ( dest == "root" || dest == "/" ) |
433 | return; | 438 | return; |
434 | 439 | ||
435 | qApp->processEvents(); | 440 | qApp->processEvents(); |
436 | QStringList *fileList = getList( packFileName, destDir ); | 441 | QStringList *fileList = getList( packFileName, destDir ); |
437 | qApp->processEvents(); | 442 | qApp->processEvents(); |
438 | processFileList( fileList, destDir ); | 443 | processFileList( fileList, destDir ); |
439 | delete fileList; | 444 | delete fileList; |
440 | } | 445 | } |
441 | 446 | ||
442 | QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) | 447 | QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) |
443 | { | 448 | { |
444 | QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list"; | 449 | QString packageFileDir = destDir; |
450 | packageFileDir.append( "/usr/lib/ipkg/info/" ); | ||
451 | packageFileDir.append( packageFilename ); | ||
452 | packageFileDir.append( ".list" ); | ||
445 | QFile f( packageFileDir ); | 453 | QFile f( packageFileDir ); |
446 | 454 | ||
447 | cout << "Try to open " << packageFileDir << endl; | ||
448 | if ( !f.open(IO_ReadOnly) ) | 455 | if ( !f.open(IO_ReadOnly) ) |
449 | { | 456 | { |
450 | // Couldn't open from dest, try from / | 457 | // Couldn't open from dest, try from / |
451 | cout << "Could not open:" << packageFileDir << endl; | ||
452 | f.close(); | 458 | f.close(); |
453 | 459 | ||
454 | packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; | 460 | packageFileDir = "/usr/lib/ipkg/info/"; |
461 | packageFileDir.append( packageFilename ); | ||
462 | packageFileDir.append( ".list" ); | ||
455 | f.setName( packageFileDir ); | 463 | f.setName( packageFileDir ); |
456 | qDebug( "Try to open %s", packageFileDir.latin1() ); | ||
457 | if ( ! f.open(IO_ReadOnly) ) | 464 | if ( ! f.open(IO_ReadOnly) ) |
458 | { | 465 | { |
459 | qDebug( "Could not open: %s", packageFileDir.latin1() ); | 466 | QString tempstr = "Could not open :"; |
460 | emit outputText( QString( "Could not open :" ) + packageFileDir ); | 467 | tempstr.append( packageFileDir ); |
468 | emit outputText( tempstr ); | ||
461 | return (QStringList*)0; | 469 | return (QStringList*)0; |
462 | } | 470 | } |
463 | } | 471 | } |
464 | QStringList *fileList = new QStringList(); | 472 | QStringList *fileList = new QStringList(); |
465 | QTextStream t( &f ); | 473 | QTextStream t( &f ); |
466 | while ( !t.eof() ) | 474 | while ( !t.eof() ) |
467 | *fileList += t.readLine(); | 475 | *fileList += t.readLine(); |
468 | 476 | ||
469 | f.close(); | 477 | f.close(); |
470 | return fileList; | 478 | return fileList; |
471 | } | 479 | } |
472 | 480 | ||
473 | void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) | 481 | void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) |
474 | { | 482 | { |
475 | if ( !fileList || fileList->isEmpty() ) | 483 | if ( !fileList || fileList->isEmpty() ) |
476 | return; | 484 | return; |
477 | 485 | ||
478 | QString baseDir = ROOT; | 486 | QString baseDir = ROOT; |
479 | 487 | ||
480 | if ( createLinks == true ) | 488 | if ( createLinks == true ) |
481 | { | 489 | { |
482 | for ( uint i=0; i < fileList->count(); i++ ) | 490 | for ( uint i=0; i < fileList->count(); i++ ) |
483 | { | 491 | { |
484 | processLinkDir( (*fileList)[i], baseDir, destDir ); | 492 | processLinkDir( (*fileList)[i], baseDir, destDir ); |
485 | qApp->processEvents(); | 493 | qApp->processEvents(); |
486 | } | 494 | } |
487 | } | 495 | } |
488 | else | 496 | else |
489 | { | 497 | { |
490 | for ( int i = fileList->count()-1; i >= 0 ; i-- ) | 498 | for ( int i = fileList->count()-1; i >= 0 ; i-- ) |
491 | { | 499 | { |
492 | processLinkDir( (*fileList)[i], baseDir, destDir ); | 500 | processLinkDir( (*fileList)[i], baseDir, destDir ); |
493 | qApp->processEvents(); | 501 | qApp->processEvents(); |
494 | } | 502 | } |
495 | } | 503 | } |
496 | } | 504 | } |
497 | 505 | ||
498 | void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) | 506 | void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) |
499 | { | 507 | { |
500 | 508 | ||
501 | QString sourceFile = baseDir + file; | 509 | QString sourceFile = baseDir; |
510 | sourceFile.append( file ); | ||
502 | 511 | ||
503 | QString linkFile = destDir; | 512 | QString linkFile = destDir; |
504 | if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) | 513 | if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) |
505 | { | 514 | { |
506 | linkFile += file.mid( 1 ); | 515 | linkFile.append( file.mid( 1 ) ); |
507 | } | 516 | } |
508 | else | 517 | else |
509 | { | 518 | { |
510 | linkFile += file; | 519 | linkFile.append( file ); |
511 | } | 520 | } |
512 | QString text; | 521 | QString text; |
513 | if ( createLinks ) | 522 | if ( createLinks ) |
514 | { | 523 | { |
515 | // If this file is a directory (ends with a /) and it doesn't exist, | 524 | // If this file is a directory (ends with a /) and it doesn't exist, |
516 | // we need to create it | 525 | // we need to create it |
517 | if ( file.right(1) == "/" ) | 526 | if ( file.right(1) == "/" ) |
518 | { | 527 | { |
519 | QFileInfo f( linkFile ); | 528 | QFileInfo f( linkFile ); |
520 | if ( !f.exists() ) | 529 | if ( !f.exists() ) |
521 | { | 530 | { |
522 | emit outputText( QString( "Creating directory " ) + linkFile ); | 531 | QString tempstr = "Creating directory "; |
532 | tempstr.append( linkFile ); | ||
533 | emit outputText( tempstr ); | ||
523 | QDir d; | 534 | QDir d; |
524 | d.mkdir( linkFile, true ); | 535 | d.mkdir( linkFile, true ); |
525 | } | 536 | } |
526 | // else | 537 | // else |
527 | // emit outputText( QString( "Directory " ) + linkFile + " already exists" ); | 538 | // emit outputText( QString( "Directory " ) + linkFile + " already exists" ); |
528 | 539 | ||
529 | } | 540 | } |
530 | else | 541 | else |
531 | { | 542 | { |
532 | int rc = symlink( sourceFile, linkFile ); | 543 | int rc = symlink( sourceFile, linkFile ); |
533 | text = (rc == 0 ? "Linked " : "Failed to link "); | 544 | text = (rc == 0 ? "Linked " : "Failed to link "); |
534 | text += sourceFile + " to " + linkFile; | 545 | text.append( sourceFile ); |
546 | text.append( " to " ); | ||
547 | text.append( linkFile ); | ||
535 | emit outputText( text ); | 548 | emit outputText( text ); |
536 | } | 549 | } |
537 | } | 550 | } |
538 | else | 551 | else |
539 | { | 552 | { |
540 | QFileInfo f( linkFile ); | 553 | QFileInfo f( linkFile ); |
541 | if ( f.exists() ) | 554 | if ( f.exists() ) |
542 | { | 555 | { |
543 | if ( f.isFile() ) | 556 | if ( f.isFile() ) |
544 | { | 557 | { |
545 | QFile f( linkFile ); | 558 | QFile f( linkFile ); |
546 | bool rc = f.remove(); | 559 | bool rc = f.remove(); |
547 | 560 | ||
548 | text = (rc ? "Removed " : "Failed to remove "); | 561 | text = (rc ? "Removed " : "Failed to remove "); |
549 | text += linkFile; | 562 | text.append( linkFile ); |
550 | emit outputText( text ); | 563 | emit outputText( text ); |
551 | } | 564 | } |
552 | else if ( f.isDir() ) | 565 | else if ( f.isDir() ) |
553 | { | 566 | { |
554 | QDir d; | 567 | QDir d; |
555 | bool rc = d.rmdir( linkFile, true ); | 568 | bool rc = d.rmdir( linkFile, true ); |
556 | if ( rc ) | 569 | if ( rc ) |
557 | { | 570 | { |
558 | text = (rc ? "Removed " : "Failed to remove "); | 571 | text = (rc ? "Removed " : "Failed to remove "); |
559 | text += linkFile; | 572 | text.append( linkFile ); |
560 | emit outputText( text ); | 573 | emit outputText( text ); |
561 | } | 574 | } |
562 | } | 575 | } |
563 | } | 576 | } |
564 | } | 577 | } |
565 | |||
566 | } | 578 | } |