summaryrefslogtreecommitdiff
authorkergoth <kergoth>2002-11-29 18:58:15 (UTC)
committer kergoth <kergoth>2002-11-29 18:58:15 (UTC)
commit17906c7fefc001c74af2141610c23c28c28a4e52 (patch) (unidiff)
tree527fe02d74b54debefd4f66eb5989e14a6d2d1ba
parentd85d0022270da220f219764593c98dc8f28439b7 (diff)
downloadopie-17906c7fefc001c74af2141610c23c28c28a4e52.zip
opie-17906c7fefc001c74af2141610c23c28c28a4e52.tar.gz
opie-17906c7fefc001c74af2141610c23c28c28a4e52.tar.bz2
Compile fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/ipkg.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp
index 1efe030..407abe9 100644
--- a/noncore/settings/aqpkg/ipkg.cpp
+++ b/noncore/settings/aqpkg/ipkg.cpp
@@ -1,525 +1,525 @@
1/*************************************************************************** 1/***************************************************************************
2 ipkg.cpp - description 2 ipkg.cpp - description
3 ------------------- 3 -------------------
4 begin : Sat Aug 31 2002 4 begin : Sat Aug 31 2002
5 copyright : (C) 2002 by Andy Qua 5 copyright : (C) 2002 by Andy Qua
6 email : andy.qua@blueyonder.co.uk 6 email : andy.qua@blueyonder.co.uk
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. * 14 * (at your option) any later version. *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17 17
18#include <fstream> 18#include <fstream>
19#include <iostream> 19#include <iostream>
20#include <vector> 20#include <vector>
21using namespace std; 21using namespace std;
22 22
23#include <stdio.h> 23#include <stdio.h>
24#include <unistd.h> 24#include <unistd.h>
25 25
26#ifdef QWS 26#ifdef QWS
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#else 28#else
29#include <qapplication.h> 29#include <qapplication.h>
30#endif 30#endif
31#include <qdir.h> 31#include <qdir.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33 33
34#include <opie/oprocess.h> 34#include <opie/oprocess.h>
35 35
36#include "utils.h" 36#include "utils.h"
37#include "ipkg.h" 37#include "ipkg.h"
38#include "global.h" 38#include "global.h"
39 39
40Ipkg :: Ipkg() 40Ipkg :: Ipkg()
41{ 41{
42} 42}
43 43
44Ipkg :: ~Ipkg() 44Ipkg :: ~Ipkg()
45{ 45{
46} 46}
47 47
48// Option is what we are going to do - install, upgrade, download, reinstall 48// Option is what we are going to do - install, upgrade, download, reinstall
49// package is the package name to install - either a fully qualified path and ipk 49// package is the package name to install - either a fully qualified path and ipk
50// file (if stored locally) or just the name of the package (for a network package) 50// file (if stored locally) or just the name of the package (for a network package)
51// packageName is the package name - (for a network package this will be the same as 51// packageName is the package name - (for a network package this will be the same as
52// package parameter) 52// package parameter)
53// dest is the destination alias (from ipk.conf) 53// dest is the destination alias (from ipk.conf)
54// destDir is the dir that the destination alias points to (used to link to root) 54// destDir is the dir that the destination alias points to (used to link to root)
55// flags is the ipkg options flags 55// flags is the ipkg options flags
56// dir is the directory to run ipkg in (defaults to "") 56// dir is the directory to run ipkg in (defaults to "")
57bool Ipkg :: runIpkg( ) 57bool Ipkg :: runIpkg( )
58{ 58{
59 bool ret = false; 59 bool ret = false;
60 QStringList commands; 60 QStringList commands;
61 61
62 QDir::setCurrent( "/tmp" ); 62 QDir::setCurrent( "/tmp" );
63 63
64 if ( runtimeDir != "" ) 64 if ( runtimeDir != "" )
65 { 65 {
66 commands << "cd "; 66 commands << "cd ";
67 commands << runtimeDir; 67 commands << runtimeDir;
68 commands << ";"; 68 commands << ";";
69 } 69 }
70 commands << "ipkg" << "-force-defaults"; 70 commands << "ipkg" << "-force-defaults";
71 71
72 // only set the destination for an install operation 72 // only set the destination for an install operation
73 if ( option == "install" ) 73 if ( option == "install" )
74 commands << "-dest" << destination; 74 commands << "-dest" << destination;
75 75
76 76
77 if ( option != "update" && option != "download" ) 77 if ( option != "update" && option != "download" )
78 { 78 {
79 if ( flags & FORCE_DEPENDS ) 79 if ( flags & FORCE_DEPENDS )
80 commands << "-force-depends"; 80 commands << "-force-depends";
81 if ( flags & FORCE_REINSTALL ) 81 if ( flags & FORCE_REINSTALL )
82 commands << "-force-reinstall"; 82 commands << "-force-reinstall";
83 if ( flags & FORCE_REMOVE ) 83 if ( flags & FORCE_REMOVE )
84 commands << "-force-removal-of-essential-packages"; 84 commands << "-force-removal-of-essential-packages";
85 if ( flags & FORCE_OVERWRITE ) 85 if ( flags & FORCE_OVERWRITE )
86 commands << "-force-overwrite"; 86 commands << "-force-overwrite";
87 if ( flags & VERBOSE_WGET ) 87 if ( flags & VERBOSE_WGET )
88 commands << "-verbose_wget"; 88 commands << "-verbose_wget";
89 89
90 // Handle make links 90 // Handle make links
91 // Rules - If make links is switched on, create links to root 91 // Rules - If make links is switched on, create links to root
92 // if destDir is NOT / 92 // if destDir is NOT /
93 if ( flags & MAKE_LINKS ) 93 if ( flags & MAKE_LINKS )
94 { 94 {
95 // If destDir == / turn off make links as package is being insalled 95 // If destDir == / turn off make links as package is being insalled
96 // to root already. 96 // to root already.
97 if ( destDir == "/" ) 97 if ( destDir == "/" )
98 flags ^= MAKE_LINKS; 98 flags ^= MAKE_LINKS;
99 } 99 }
100 } 100 }
101 101
102#ifdef X86 102#ifdef X86
103 commands << "-f"; 103 commands << "-f";
104 commands << IPKG_CONF; 104 commands << IPKG_CONF;
105#endif 105#endif
106 106
107 107
108 if ( option == "reinstall" ) 108 if ( option == "reinstall" )
109 commands << "install"; 109 commands << "install";
110 else 110 else
111 commands << option; 111 commands << option;
112 if ( package != "" ) 112 if ( package != "" )
113 commands << package; 113 commands << package;
114 114
115 115
116 if ( package != "" ) 116 if ( package != "" )
117 emit outputText( QString( "Dealing with package " ) + package ); 117 emit outputText( QString( "Dealing with package " ) + package );
118 118
119 qApp->processEvents(); 119 qApp->processEvents();
120 120
121 // If we are removing packages and make links option is selected 121 // If we are removing packages and make links option is selected
122 // create the links 122 // create the links
123 if ( option == "remove" || option == "reinstall" ) 123 if ( option == "remove" || option == "reinstall" )
124 { 124 {
125 createLinks = false; 125 createLinks = false;
126 if ( flags & MAKE_LINKS ) 126 if ( flags & MAKE_LINKS )
127 { 127 {
128 emit outputText( QString( "Removing symbolic links...\n" ) ); 128 emit outputText( QString( "Removing symbolic links...\n" ) );
129 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 129 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
130 emit outputText( QString( " " ) ); 130 emit outputText( QString( " " ) );
131 } 131 }
132 } 132 }
133 133
134 // Execute command 134 // Execute command
135 dependantPackages = new QList<QString>; 135 dependantPackages = new QList<QString>;
136 dependantPackages->setAutoDelete( true ); 136 dependantPackages->setAutoDelete( true );
137 137
138 ret = executeIpkgCommand( commands, option ); 138 ret = executeIpkgCommand( commands, option );
139 139
140 if ( option == "install" || option == "reinstall" ) 140 if ( option == "install" || option == "reinstall" )
141 { 141 {
142 // If we are not removing packages and make links option is selected 142 // If we are not removing packages and make links option is selected
143 // create the links 143 // create the links
144 createLinks = true; 144 createLinks = true;
145 if ( flags & MAKE_LINKS ) 145 if ( flags & MAKE_LINKS )
146 { 146 {
147 emit outputText( " " ); 147 emit outputText( " " );
148 emit outputText( QString( "Creating symbolic links for " )+ package ); 148 emit outputText( QString( "Creating symbolic links for " )+ package );
149 149
150 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 150 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
151 151
152 // link dependant packages that were installed with this release 152 // link dependant packages that were installed with this release
153 QString *pkg; 153 QString *pkg;
154 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) 154 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() )
155 { 155 {
156 if ( *pkg == package ) 156 if ( *pkg == package )
157 continue; 157 continue;
158 emit outputText( " " ); 158 emit outputText( " " );
159 emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); 159 emit outputText( QString( "Creating symbolic links for " )+ (*pkg) );
160 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); 160 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir );
161 } 161 }
162 } 162 }
163 } 163 }
164 164
165 delete dependantPackages; 165 delete dependantPackages;
166 166
167 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file 167 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file
168 // to workaround an ipkg bug which stops reinstall to a different location 168 // to workaround an ipkg bug which stops reinstall to a different location
169 if ( option == "remove" ) 169 if ( option == "remove" )
170 removeStatusEntry(); 170 removeStatusEntry();
171 171
172 172
173 emit outputText( "Finished" ); 173 emit outputText( "Finished" );
174 emit outputText( "" ); 174 emit outputText( "" );
175 return ret; 175 return ret;
176 176
177} 177}
178 178
179void Ipkg :: removeStatusEntry() 179void Ipkg :: removeStatusEntry()
180{ 180{
181 QString statusFile = destDir; 181 QString statusFile = destDir;
182 if ( statusFile.right( 1 ) != "/" ) 182 if ( statusFile.right( 1 ) != "/" )
183 statusFile += "/"; 183 statusFile += "/";
184 statusFile += "usr/lib/ipkg/status"; 184 statusFile += "usr/lib/ipkg/status";
185 QString outStatusFile = statusFile + ".tmp"; 185 QString outStatusFile = statusFile + ".tmp";
186 186
187 emit outputText( "" ); 187 emit outputText( "" );
188 emit outputText( "Removing status entry..." ); 188 emit outputText( "Removing status entry..." );
189 emit outputText( QString( "status file - " )+ statusFile ); 189 emit outputText( QString( "status file - " )+ statusFile );
190 emit outputText( QString( "package - " )+ package ); 190 emit outputText( QString( "package - " )+ package );
191 191
192 ifstream in( statusFile ); 192 ifstream in( statusFile );
193 ofstream out( outStatusFile ); 193 ofstream out( outStatusFile );
194 if ( !in.is_open() ) 194 if ( !in.is_open() )
195 { 195 {
196 emit outputText( QString( "Couldn't open status file - " )+ statusFile ); 196 emit outputText( QString( "Couldn't open status file - " )+ statusFile );
197 return; 197 return;
198 } 198 }
199 199
200 if ( !out.is_open() ) 200 if ( !out.is_open() )
201 { 201 {
202 emit outputText( QString( "Couldn't create tempory status file - " )+ outStatusFile ); 202 emit outputText( QString( "Couldn't create tempory status file - " )+ outStatusFile );
203 return; 203 return;
204 } 204 }
205 205
206 char line[1001]; 206 char line[1001];
207 char k[21]; 207 char k[21];
208 char v[1001]; 208 char v[1001];
209 QString key; 209 QString key;
210 QString value; 210 QString value;
211 vector<QString> lines; 211 vector<QString> lines;
212 do 212 do
213 { 213 {
214 in.getline( line, 1000 ); 214 in.getline( line, 1000 );
215 if ( in.eof() ) 215 if ( in.eof() )
216 continue; 216 continue;
217 217
218 k[0] = '\0'; 218 k[0] = '\0';
219 v[0] = '\0'; 219 v[0] = '\0';
220 220
221 sscanf( line, "%[^:]: %[^\n]", k, v ); 221 sscanf( line, "%[^:]: %[^\n]", k, v );
222 key = k; 222 key = k;
223 value = v; 223 value = v;
224 key = key.stripWhiteSpace(); 224 key = key.stripWhiteSpace();
225 value = value.stripWhiteSpace(); 225 value = value.stripWhiteSpace();
226 if ( key == "Package" && value == package ) 226 if ( key == "Package" && value == package )
227 { 227 {
228 // Ignore all lines up to next empty 228 // Ignore all lines up to next empty
229 do 229 do
230 { 230 {
231 in.getline( line, 1000 ); 231 in.getline( line, 1000 );
232 if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) 232 if ( in.eof() || QString( line ).stripWhiteSpace() == "" )
233 continue; 233 continue;
234 } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); 234 } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" );
235 } 235 }
236 236
237 lines.push_back( QString( line ) ); 237 lines.push_back( QString( line ) );
238// out << line << endl; 238// out << line << endl;
239 } while ( !in.eof() ); 239 } while ( !in.eof() );
240 240
241 // Write lines out 241 // Write lines out
242 vector<QString>::iterator it; 242 vector<QString>::iterator it;
243 for ( it = lines.begin() ; it != lines.end() ; ++it ) 243 for ( it = lines.begin() ; it != lines.end() ; ++it )
244 { 244 {
245 cout << "Writing " << (const char *)(*it) << endl; 245 cout << "Writing " << (const char *)(*it) << endl;
246 out << (const char *)(*it) << endl; 246 out << (const char *)(*it) << endl;
247 } 247 }
248 248
249 in.close(); 249 in.close();
250 out.close(); 250 out.close();
251 251
252 // Remove old status file and put tmp stats file in its place 252 // Remove old status file and put tmp stats file in its place
253 remove( statusFile ); 253 remove( statusFile );
254 rename( outStatusFile, statusFile ); 254 rename( outStatusFile, statusFile );
255} 255}
256 256
257int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString option ) 257int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString option )
258{ 258{
259 // OK we're gonna use OProcess to run this thing 259 // OK we're gonna use OProcess to run this thing
260 proc = new OProcess(); 260 proc = new OProcess();
261 261
262 // Connect up our slots 262 // Connect up our slots
263 connect(proc, SIGNAL(processExited(OProcess *)), 263 connect(proc, SIGNAL(processExited(OProcess *)),
264 this, SLOT( processFinished())); 264 this, SLOT( processFinished()));
265 265
266 connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), 266 connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)),
267 this, SLOT(commandStdout(OProcess *, char *, int))); 267 this, SLOT(commandStdout(OProcess *, char *, int)));
268 268
269 connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), 269 connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)),
270 this, SLOT(commandStderr(OProcess *, char *, int))); 270 this, SLOT(commandStderr(OProcess *, char *, int)));
271 271
272 for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) 272 for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it )
273 { 273 {
274 qDebug( "%s ", (*it).latin1() ); 274 qDebug( "%s ", (*it).latin1() );
275 *proc << (*it).latin1(); 275 *proc << (*it).latin1();
276 } 276 }
277 cout << endl; 277 cout << endl;
278 278
279 // Start the process going 279 // Start the process going
280 finished = false; 280 finished = false;
281 if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) 281 if(!proc->start(OProcess::NotifyOnExit, OProcess::All))
282 { 282 {
283 emit outputText( QString( "Couldn't start ipkg process" ) ); 283 emit outputText( QString( "Couldn't start ipkg process" ) );
284 qDebug( "Couldn't start ipkg process!" ); 284 qDebug( "Couldn't start ipkg process!" );
285 } 285 }
286 286
287 // Now wait for it to finish 287 // Now wait for it to finish
288 while ( !finished ) 288 while ( !finished )
289 qApp->processEvents(); 289 qApp->processEvents();
290} 290}
291 291
292void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) 292void Ipkg::commandStdout(OProcess*, char *buffer, int buflen)
293{ 293{
294 qDebug("received stdout %d bytes", buflen); 294 qDebug("received stdout %d bytes", buflen);
295 295
296 QString lineStr = buffer; 296 QString lineStr = buffer;
297 if ( lineStr[buflen-1] == '\n' ) 297 if ( lineStr[buflen-1] == '\n' )
298 buflen --; 298 buflen --;
299 lineStr = lineStr.left( buflen ); 299 lineStr = lineStr.left( buflen );
300 emit outputText( lineStr ); 300 emit outputText( lineStr );
301 qDebug(lineStr); 301 qDebug(lineStr);
302 buffer[0] = '\0'; 302 buffer[0] = '\0';
303} 303}
304 304
305void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) 305void Ipkg::commandStderr(OProcess*, char *buffer, int buflen)
306{ 306{
307 qDebug("received stderrt %d bytes", buflen); 307 qDebug("received stderrt %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 buffer[0] = '\0'; 314 buffer[0] = '\0';
315} 315}
316 316
317void Ipkg::processFinished() 317void Ipkg::processFinished()
318{ 318{
319 delete proc; 319 delete proc;
320 finished = true; 320 finished = true;
321} 321}
322 322
323 323
324 324
325/* 325/*
326int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) 326int Ipkg :: executeIpkgCommand( QString &cmd, const QString option )
327{ 327{
328 FILE *fp = NULL; 328 FILE *fp = NULL;
329 char line[130]; 329 char line[130];
330 QString lineStr, lineStrOld; 330 QString lineStr, lineStrOld;
331 int ret = false; 331 int ret = false;
332 332
333 fp = popen( (const char *) cmd, "r"); 333 fp = popen( (const char *) cmd, "r");
334 if ( fp == NULL ) 334 if ( fp == NULL )
335 { 335 {
336 cout << "Couldn't execute " << cmd << "! err = " << fp << endl; 336 cout << "Couldn't execute " << cmd << "! err = " << fp << endl;
337 QString text; 337 QString text;
338 text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); 338 text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd );
339 emit outputText( text ); 339 emit outputText( text );
340 } 340 }
341 else 341 else
342 { 342 {
343 while ( fgets( line, sizeof line, fp) != NULL ) 343 while ( fgets( line, sizeof line, fp) != NULL )
344 { 344 {
345 lineStr = line; 345 lineStr = line;
346 lineStr=lineStr.left( lineStr.length()-1 ); 346 lineStr=lineStr.left( lineStr.length()-1 );
347 347
348 if ( lineStr != lineStrOld ) 348 if ( lineStr != lineStrOld )
349 { 349 {
350 //See if we're finished 350 //See if we're finished
351 if ( option == "install" || option == "reinstall" ) 351 if ( option == "install" || option == "reinstall" )
352 { 352 {
353 // Need to keep track of any dependant packages that get installed 353 // Need to keep track of any dependant packages that get installed
354 // so that we can create links to them as necessary 354 // so that we can create links to them as necessary
355 if ( lineStr.startsWith( "Installing " ) ) 355 if ( lineStr.startsWith( "Installing " ) )
356 { 356 {
357 int start = lineStr.find( " " ) + 1; 357 int start = lineStr.find( " " ) + 1;
358 int end = lineStr.find( " ", start ); 358 int end = lineStr.find( " ", start );
359 QString *package = new QString( lineStr.mid( start, end-start ) ); 359 QString *package = new QString( lineStr.mid( start, end-start ) );
360 dependantPackages->append( package ); 360 dependantPackages->append( package );
361 } 361 }
362 } 362 }
363 363
364 if ( option == "update" ) 364 if ( option == "update" )
365 { 365 {
366 if (lineStr.contains("Updated list")) 366 if (lineStr.contains("Updated list"))
367 ret = true; 367 ret = true;
368 } 368 }
369 else if ( option == "download" ) 369 else if ( option == "download" )
370 { 370 {
371 if (lineStr.contains("Downloaded")) 371 if (lineStr.contains("Downloaded"))
372 ret = true; 372 ret = true;
373 } 373 }
374 else 374 else
375 { 375 {
376 if (lineStr.contains("Done")) 376 if (lineStr.contains("Done"))
377 ret = true; 377 ret = true;
378 } 378 }
379 379
380 emit outputText( lineStr ); 380 emit outputText( lineStr );
381 } 381 }
382 lineStrOld = lineStr; 382 lineStrOld = lineStr;
383 qApp->processEvents(); 383 qApp->processEvents();
384 } 384 }
385 pclose(fp); 385 pclose(fp);
386 } 386 }
387 387
388 return ret; 388 return ret;
389} 389}
390*/ 390*/
391 391
392void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) 392void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir )
393{ 393{
394 if ( dest == "root" || dest == "/" ) 394 if ( dest == "root" || dest == "/" )
395 return; 395 return;
396 396
397 qApp->processEvents(); 397 qApp->processEvents();
398 QStringList *fileList = getList( packFileName, destDir ); 398 QStringList *fileList = getList( packFileName, destDir );
399 qApp->processEvents(); 399 qApp->processEvents();
400 processFileList( fileList, destDir ); 400 processFileList( fileList, destDir );
401 delete fileList; 401 delete fileList;
402} 402}
403 403
404QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) 404QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir )
405{ 405{
406 QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list"; 406 QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list";
407 QFile f( packageFileDir ); 407 QFile f( packageFileDir );
408 408
409 cout << "Try to open " << packageFileDir << endl; 409 cout << "Try to open " << packageFileDir << endl;
410 if ( !f.open(IO_ReadOnly) ) 410 if ( !f.open(IO_ReadOnly) )
411 { 411 {
412 // Couldn't open from dest, try from / 412 // Couldn't open from dest, try from /
413 cout << "Could not open:" << packageFileDir << endl; 413 cout << "Could not open:" << packageFileDir << endl;
414 f.close(); 414 f.close();
415 415
416 packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; 416 packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list";
417 f.setName( packageFileDir ); 417 f.setName( packageFileDir );
418 qDebug( "Try to open %s", packageFileDir.latin1() ); 418 qDebug( "Try to open %s", packageFileDir.latin1() );
419 if ( ! f.open(IO_ReadOnly) ) 419 if ( ! f.open(IO_ReadOnly) )
420 { 420 {
421 qDebug( "Could not open: %s", packageFileDir ); 421 qDebug( "Could not open: %s", packageFileDir.latin1() );
422 emit outputText( QString( "Could not open :" ) + packageFileDir ); 422 emit outputText( QString( "Could not open :" ) + packageFileDir );
423 return (QStringList*)0; 423 return (QStringList*)0;
424 } 424 }
425 } 425 }
426 QStringList *fileList = new QStringList(); 426 QStringList *fileList = new QStringList();
427 QTextStream t( &f ); 427 QTextStream t( &f );
428 while ( !t.eof() ) 428 while ( !t.eof() )
429 *fileList += t.readLine(); 429 *fileList += t.readLine();
430 430
431 f.close(); 431 f.close();
432 return fileList; 432 return fileList;
433} 433}
434 434
435void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) 435void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir )
436{ 436{
437 if ( !fileList || fileList->isEmpty() ) 437 if ( !fileList || fileList->isEmpty() )
438 return; 438 return;
439 439
440 QString baseDir = ROOT; 440 QString baseDir = ROOT;
441 441
442 if ( createLinks == true ) 442 if ( createLinks == true )
443 { 443 {
444 for ( uint i=0; i < fileList->count(); i++ ) 444 for ( uint i=0; i < fileList->count(); i++ )
445 { 445 {
446 processLinkDir( (*fileList)[i], baseDir, destDir ); 446 processLinkDir( (*fileList)[i], baseDir, destDir );
447 qApp->processEvents(); 447 qApp->processEvents();
448 } 448 }
449 } 449 }
450 else 450 else
451 { 451 {
452 for ( int i = fileList->count()-1; i >= 0 ; i-- ) 452 for ( int i = fileList->count()-1; i >= 0 ; i-- )
453 { 453 {
454 processLinkDir( (*fileList)[i], baseDir, destDir ); 454 processLinkDir( (*fileList)[i], baseDir, destDir );
455 qApp->processEvents(); 455 qApp->processEvents();
456 } 456 }
457 } 457 }
458} 458}
459 459
460void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) 460void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir )
461{ 461{
462 462
463 QString sourceFile = baseDir + file; 463 QString sourceFile = baseDir + file;
464 464
465 QString linkFile = destDir; 465 QString linkFile = destDir;
466 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) 466 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" )
467 { 467 {
468 linkFile += file.mid( 1 ); 468 linkFile += file.mid( 1 );
469 } 469 }
470 else 470 else
471 { 471 {
472 linkFile += file; 472 linkFile += file;
473 } 473 }
474 QString text; 474 QString text;
475 if ( createLinks ) 475 if ( createLinks )
476 { 476 {
477 // If this file is a directory (ends with a /) and it doesn't exist, 477 // If this file is a directory (ends with a /) and it doesn't exist,
478 // we need to create it 478 // we need to create it
479 if ( file.right(1) == "/" ) 479 if ( file.right(1) == "/" )
480 { 480 {
481 QFileInfo f( linkFile ); 481 QFileInfo f( linkFile );
482 if ( !f.exists() ) 482 if ( !f.exists() )
483 { 483 {
484 emit outputText( QString( "Creating directory " ) + linkFile ); 484 emit outputText( QString( "Creating directory " ) + linkFile );
485 QDir d; 485 QDir d;
486 d.mkdir( linkFile, true ); 486 d.mkdir( linkFile, true );
487 } 487 }
488 else 488 else
489 emit outputText( QString( "Directory " ) + linkFile + " already exists" ); 489 emit outputText( QString( "Directory " ) + linkFile + " already exists" );
490 490
491 } 491 }
492 else 492 else
493 { 493 {
494 int rc = symlink( sourceFile, linkFile ); 494 int rc = symlink( sourceFile, linkFile );
495 text = (rc == 0 ? "Linked " : "Failed to link "); 495 text = (rc == 0 ? "Linked " : "Failed to link ");
496 text += sourceFile + " to " + linkFile; 496 text += sourceFile + " to " + linkFile;
497 emit outputText( text ); 497 emit outputText( text );
498 } 498 }
499 } 499 }
500 else 500 else
501 { 501 {
502 QFileInfo f( linkFile ); 502 QFileInfo f( linkFile );
503 if ( f.exists() ) 503 if ( f.exists() )
504 { 504 {
505 if ( f.isFile() ) 505 if ( f.isFile() )
506 { 506 {
507 QFile f( linkFile ); 507 QFile f( linkFile );
508 bool rc = f.remove(); 508 bool rc = f.remove();
509 509
510 text = (rc ? "Removed " : "Failed to remove "); 510 text = (rc ? "Removed " : "Failed to remove ");
511 text += linkFile; 511 text += linkFile;
512 emit outputText( text ); 512 emit outputText( text );
513 } 513 }
514 else if ( f.isDir() ) 514 else if ( f.isDir() )
515 { 515 {
516 QDir d; 516 QDir d;
517 bool rc = d.rmdir( linkFile, true ); 517 bool rc = d.rmdir( linkFile, true );
518 text = (rc ? "Removed " : "Failed to remove "); 518 text = (rc ? "Removed " : "Failed to remove ");
519 text += linkFile; 519 text += linkFile;
520 emit outputText( text ); 520 emit outputText( text );
521 } 521 }
522 } 522 }
523 } 523 }
524 524
525} 525}