summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/ipkg.cpp15
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
@@ -58,490 +58,505 @@ Ipkg :: ~Ipkg()
58bool Ipkg :: runIpkg( ) 58bool Ipkg :: runIpkg( )
59{ 59{
60 bool ret = false; 60 bool ret = false;
61 QStringList commands; 61 QStringList commands;
62 62
63 QDir::setCurrent( "/tmp" ); 63 QDir::setCurrent( "/tmp" );
64 64
65 if ( runtimeDir != "" ) 65 if ( runtimeDir != "" )
66 { 66 {
67 commands << "cd "; 67 commands << "cd ";
68 commands << runtimeDir; 68 commands << runtimeDir;
69 commands << ";"; 69 commands << ";";
70 } 70 }
71 commands << "ipkg" << "-force-defaults"; 71 commands << "ipkg" << "-force-defaults";
72 72
73 // only set the destination for an install operation 73 // only set the destination for an install operation
74 if ( option == "install" ) 74 if ( option == "install" )
75 commands << "-dest" << destination; 75 commands << "-dest" << destination;
76 76
77 77
78 if ( option != "update" && option != "download" ) 78 if ( option != "update" && option != "download" )
79 { 79 {
80 if ( flags & FORCE_DEPENDS ) 80 if ( flags & FORCE_DEPENDS )
81 commands << "-force-depends"; 81 commands << "-force-depends";
82 if ( flags & FORCE_REINSTALL ) 82 if ( flags & FORCE_REINSTALL )
83 commands << "-force-reinstall"; 83 commands << "-force-reinstall";
84 if ( flags & FORCE_REMOVE ) 84 if ( flags & FORCE_REMOVE )
85 commands << "-force-removal-of-essential-packages"; 85 commands << "-force-removal-of-essential-packages";
86 if ( flags & FORCE_OVERWRITE ) 86 if ( flags & FORCE_OVERWRITE )
87 commands << "-force-overwrite"; 87 commands << "-force-overwrite";
88 if ( flags & VERBOSE_WGET ) 88 if ( flags & VERBOSE_WGET )
89 commands << "-verbose_wget"; 89 commands << "-verbose_wget";
90 90
91 // Handle make links 91 // Handle make links
92 // Rules - If make links is switched on, create links to root 92 // Rules - If make links is switched on, create links to root
93 // if destDir is NOT / 93 // if destDir is NOT /
94 if ( flags & MAKE_LINKS ) 94 if ( flags & MAKE_LINKS )
95 { 95 {
96 // If destDir == / turn off make links as package is being insalled 96 // If destDir == / turn off make links as package is being insalled
97 // to root already. 97 // to root already.
98 if ( destDir == "/" ) 98 if ( destDir == "/" )
99 flags ^= MAKE_LINKS; 99 flags ^= MAKE_LINKS;
100 } 100 }
101 } 101 }
102 102
103#ifdef X86 103#ifdef X86
104 commands << "-f"; 104 commands << "-f";
105 commands << IPKG_CONF; 105 commands << IPKG_CONF;
106#endif 106#endif
107 107
108 108
109 if ( option == "reinstall" ) 109 if ( option == "reinstall" )
110 commands << "install"; 110 commands << "install";
111 else 111 else
112 commands << option; 112 commands << option;
113 if ( package != "" ) 113 if ( package != "" )
114 commands << package; 114 commands << package;
115 115
116 116
117 if ( package != "" ) 117 if ( package != "" )
118 emit outputText( QString( "Dealing with package " ) + package ); 118 emit outputText( QString( "Dealing with package " ) + package );
119 119
120 qApp->processEvents(); 120 qApp->processEvents();
121 121
122 // If we are removing packages and make links option is selected 122 // If we are removing packages and make links option is selected
123 // create the links 123 // create the links
124 if ( option == "remove" || option == "reinstall" ) 124 if ( option == "remove" || option == "reinstall" )
125 { 125 {
126 createLinks = false; 126 createLinks = false;
127 if ( flags & MAKE_LINKS ) 127 if ( flags & MAKE_LINKS )
128 { 128 {
129 emit outputText( QString( "Removing symbolic links...\n" ) ); 129 emit outputText( QString( "Removing symbolic links...\n" ) );
130 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 130 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
131 emit outputText( QString( " " ) ); 131 emit outputText( QString( " " ) );
132 } 132 }
133 } 133 }
134 134
135 // Execute command 135 // Execute command
136 dependantPackages = new QList<QString>; 136 dependantPackages = new QList<QString>;
137 dependantPackages->setAutoDelete( true ); 137 dependantPackages->setAutoDelete( true );
138 138
139 ret = executeIpkgCommand( commands, option ); 139 ret = executeIpkgCommand( commands, option );
140 140
141 if ( aborted ) 141 if ( aborted )
142 return false; 142 return false;
143 143
144 if ( option == "install" || option == "reinstall" ) 144 if ( option == "install" || option == "reinstall" )
145 { 145 {
146 // If we are not removing packages and make links option is selected 146 // If we are not removing packages and make links option is selected
147 // create the links 147 // create the links
148 createLinks = true; 148 createLinks = true;
149 if ( flags & MAKE_LINKS ) 149 if ( flags & MAKE_LINKS )
150 { 150 {
151 emit outputText( " " ); 151 emit outputText( " " );
152 emit outputText( QString( "Creating symbolic links for " )+ package ); 152 emit outputText( QString( "Creating symbolic links for " )+ package );
153 153
154 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 154 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
155 155
156 // link dependant packages that were installed with this release 156 // link dependant packages that were installed with this release
157 QString *pkg; 157 QString *pkg;
158 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) 158 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() )
159 { 159 {
160 if ( *pkg == package ) 160 if ( *pkg == package )
161 continue; 161 continue;
162 emit outputText( " " ); 162 emit outputText( " " );
163 emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); 163 emit outputText( QString( "Creating symbolic links for " )+ (*pkg) );
164 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); 164 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir );
165 } 165 }
166 } 166 }
167 } 167 }
168 168
169 delete dependantPackages; 169 delete dependantPackages;
170 170
171 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file 171 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file
172 // to workaround an ipkg bug which stops reinstall to a different location 172 // to workaround an ipkg bug which stops reinstall to a different location
173 if ( option == "remove" ) 173 if ( option == "remove" )
174 removeStatusEntry(); 174 removeStatusEntry();
175 175
176 176
177 emit outputText( "Finished" ); 177 emit outputText( "Finished" );
178 emit outputText( "" ); 178 emit outputText( "" );
179 return ret; 179 return ret;
180 180
181} 181}
182 182
183void Ipkg :: removeStatusEntry() 183void Ipkg :: removeStatusEntry()
184{ 184{
185 QString statusFile = destDir; 185 QString statusFile = destDir;
186 if ( statusFile.right( 1 ) != "/" ) 186 if ( statusFile.right( 1 ) != "/" )
187 statusFile += "/"; 187 statusFile += "/";
188 statusFile += "usr/lib/ipkg/status"; 188 statusFile += "usr/lib/ipkg/status";
189 QString outStatusFile = statusFile + ".tmp"; 189 QString outStatusFile = statusFile + ".tmp";
190 190
191 emit outputText( "" ); 191 emit outputText( "" );
192 emit outputText( "Removing status entry..." ); 192 emit outputText( "Removing status entry..." );
193 emit outputText( QString( "status file - " )+ statusFile ); 193 emit outputText( QString( "status file - " )+ statusFile );
194 emit outputText( QString( "package - " )+ package ); 194 emit outputText( QString( "package - " )+ package );
195 195
196 ifstream in( statusFile ); 196 ifstream in( statusFile );
197 ofstream out( outStatusFile ); 197 ofstream out( outStatusFile );
198 if ( !in.is_open() ) 198 if ( !in.is_open() )
199 { 199 {
200 emit outputText( QString( "Couldn't open status file - " )+ statusFile ); 200 emit outputText( QString( "Couldn't open status file - " )+ statusFile );
201 return; 201 return;
202 } 202 }
203 203
204 if ( !out.is_open() ) 204 if ( !out.is_open() )
205 { 205 {
206 emit outputText( QString( "Couldn't create tempory status file - " )+ outStatusFile ); 206 emit outputText( QString( "Couldn't create tempory status file - " )+ outStatusFile );
207 return; 207 return;
208 } 208 }
209 209
210 char line[1001]; 210 char line[1001];
211 char k[21]; 211 char k[21];
212 char v[1001]; 212 char v[1001];
213 QString key; 213 QString key;
214 QString value; 214 QString value;
215 vector<QString> lines; 215 vector<QString> lines;
216 do 216 do
217 { 217 {
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
261int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString option ) 261int 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
305void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) 305void 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
318void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) 333void 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
330void Ipkg::processFinished() 345void 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
338void Ipkg :: abort() 353void 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/*
348int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) 363int 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
410 return ret; 425 return ret;
411} 426}
412*/ 427*/
413 428
414void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) 429void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir )
415{ 430{
416 if ( dest == "root" || dest == "/" ) 431 if ( dest == "root" || dest == "/" )
417 return; 432 return;
418 433
419 qApp->processEvents(); 434 qApp->processEvents();
420 QStringList *fileList = getList( packFileName, destDir ); 435 QStringList *fileList = getList( packFileName, destDir );
421 qApp->processEvents(); 436 qApp->processEvents();
422 processFileList( fileList, destDir ); 437 processFileList( fileList, destDir );
423 delete fileList; 438 delete fileList;
424} 439}
425 440
426QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) 441QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir )
427{ 442{
428 QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list"; 443 QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list";
429 QFile f( packageFileDir ); 444 QFile f( packageFileDir );
430 445
431 cout << "Try to open " << packageFileDir << endl; 446 cout << "Try to open " << packageFileDir << endl;
432 if ( !f.open(IO_ReadOnly) ) 447 if ( !f.open(IO_ReadOnly) )
433 { 448 {
434 // Couldn't open from dest, try from / 449 // Couldn't open from dest, try from /
435 cout << "Could not open:" << packageFileDir << endl; 450 cout << "Could not open:" << packageFileDir << endl;
436 f.close(); 451 f.close();
437 452
438 packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; 453 packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list";
439 f.setName( packageFileDir ); 454 f.setName( packageFileDir );
440 qDebug( "Try to open %s", packageFileDir.latin1() ); 455 qDebug( "Try to open %s", packageFileDir.latin1() );
441 if ( ! f.open(IO_ReadOnly) ) 456 if ( ! f.open(IO_ReadOnly) )
442 { 457 {
443 qDebug( "Could not open: %s", packageFileDir.latin1() ); 458 qDebug( "Could not open: %s", packageFileDir.latin1() );
444 emit outputText( QString( "Could not open :" ) + packageFileDir ); 459 emit outputText( QString( "Could not open :" ) + packageFileDir );
445 return (QStringList*)0; 460 return (QStringList*)0;
446 } 461 }
447 } 462 }
448 QStringList *fileList = new QStringList(); 463 QStringList *fileList = new QStringList();
449 QTextStream t( &f ); 464 QTextStream t( &f );
450 while ( !t.eof() ) 465 while ( !t.eof() )
451 *fileList += t.readLine(); 466 *fileList += t.readLine();
452 467
453 f.close(); 468 f.close();
454 return fileList; 469 return fileList;
455} 470}
456 471
457void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) 472void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir )
458{ 473{
459 if ( !fileList || fileList->isEmpty() ) 474 if ( !fileList || fileList->isEmpty() )
460 return; 475 return;
461 476
462 QString baseDir = ROOT; 477 QString baseDir = ROOT;
463 478
464 if ( createLinks == true ) 479 if ( createLinks == true )
465 { 480 {
466 for ( uint i=0; i < fileList->count(); i++ ) 481 for ( uint i=0; i < fileList->count(); i++ )
467 { 482 {
468 processLinkDir( (*fileList)[i], baseDir, destDir ); 483 processLinkDir( (*fileList)[i], baseDir, destDir );
469 qApp->processEvents(); 484 qApp->processEvents();
470 } 485 }
471 } 486 }
472 else 487 else
473 { 488 {
474 for ( int i = fileList->count()-1; i >= 0 ; i-- ) 489 for ( int i = fileList->count()-1; i >= 0 ; i-- )
475 { 490 {
476 processLinkDir( (*fileList)[i], baseDir, destDir ); 491 processLinkDir( (*fileList)[i], baseDir, destDir );
477 qApp->processEvents(); 492 qApp->processEvents();
478 } 493 }
479 } 494 }
480} 495}
481 496
482void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) 497void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir )
483{ 498{
484 499
485 QString sourceFile = baseDir + file; 500 QString sourceFile = baseDir + file;
486 501
487 QString linkFile = destDir; 502 QString linkFile = destDir;
488 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) 503 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" )
489 { 504 {
490 linkFile += file.mid( 1 ); 505 linkFile += file.mid( 1 );
491 } 506 }
492 else 507 else
493 { 508 {
494 linkFile += file; 509 linkFile += file;
495 } 510 }
496 QString text; 511 QString text;
497 if ( createLinks ) 512 if ( createLinks )
498 { 513 {
499 // If this file is a directory (ends with a /) and it doesn't exist, 514 // If this file is a directory (ends with a /) and it doesn't exist,
500 // we need to create it 515 // we need to create it
501 if ( file.right(1) == "/" ) 516 if ( file.right(1) == "/" )
502 { 517 {
503 QFileInfo f( linkFile ); 518 QFileInfo f( linkFile );
504 if ( !f.exists() ) 519 if ( !f.exists() )
505 { 520 {
506 emit outputText( QString( "Creating directory " ) + linkFile ); 521 emit outputText( QString( "Creating directory " ) + linkFile );
507 QDir d; 522 QDir d;
508 d.mkdir( linkFile, true ); 523 d.mkdir( linkFile, true );
509 } 524 }
510 else 525 else
511 emit outputText( QString( "Directory " ) + linkFile + " already exists" ); 526 emit outputText( QString( "Directory " ) + linkFile + " already exists" );
512 527
513 } 528 }
514 else 529 else
515 { 530 {
516 int rc = symlink( sourceFile, linkFile ); 531 int rc = symlink( sourceFile, linkFile );
517 text = (rc == 0 ? "Linked " : "Failed to link "); 532 text = (rc == 0 ? "Linked " : "Failed to link ");
518 text += sourceFile + " to " + linkFile; 533 text += sourceFile + " to " + linkFile;
519 emit outputText( text ); 534 emit outputText( text );
520 } 535 }
521 } 536 }
522 else 537 else
523 { 538 {
524 QFileInfo f( linkFile ); 539 QFileInfo f( linkFile );
525 if ( f.exists() ) 540 if ( f.exists() )
526 { 541 {
527 if ( f.isFile() ) 542 if ( f.isFile() )
528 { 543 {
529 QFile f( linkFile ); 544 QFile f( linkFile );
530 bool rc = f.remove(); 545 bool rc = f.remove();
531 546
532 text = (rc ? "Removed " : "Failed to remove "); 547 text = (rc ? "Removed " : "Failed to remove ");
533 text += linkFile; 548 text += linkFile;
534 emit outputText( text ); 549 emit outputText( text );
535 } 550 }
536 else if ( f.isDir() ) 551 else if ( f.isDir() )
537 { 552 {
538 QDir d; 553 QDir d;
539 bool rc = d.rmdir( linkFile, true ); 554 bool rc = d.rmdir( linkFile, true );
540 text = (rc ? "Removed " : "Failed to remove "); 555 text = (rc ? "Removed " : "Failed to remove ");
541 text += linkFile; 556 text += linkFile;
542 emit outputText( text ); 557 emit outputText( text );
543 } 558 }
544 } 559 }
545 } 560 }
546 561
547} 562}