summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/ipkg.cpp91
-rw-r--r--noncore/settings/aqpkg/ipkg.h3
2 files changed, 91 insertions, 3 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp
index 420863c..17efda9 100644
--- a/noncore/settings/aqpkg/ipkg.cpp
+++ b/noncore/settings/aqpkg/ipkg.cpp
@@ -1,521 +1,606 @@
1/* 1/*
2                This file is part of the OPIE Project 2                This file is part of the OPIE Project
3 3
4 =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> 4 =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk>
5             .=l. Dan Williams <drw@handhelds.org> 5             .=l. Dan Williams <drw@handhelds.org>
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This file is free software; you can 7 _;:,     .>    :=|. This file is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU General Public 9:`=1 )Y*s>-.--   : the terms of the GNU General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This file is distributed in the hope that 14    .i_,=:_.      -<s. This file is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
19..}^=.=       =       ; Public License for more details. 19..}^=.=       =       ; Public License for more details.
20++=   -.     .`     .: 20++=   -.     .`     .:
21 :     =  ...= . :.=- You should have received a copy of the GNU 21 :     =  ...= . :.=- You should have received a copy of the GNU
22 -.   .:....=;==+<; General Public License along with this file; 22 -.   .:....=;==+<; General Public License along with this file;
23  -_. . .   )=.  = see the file COPYING. If not, write to the 23  -_. . .   )=.  = see the file COPYING. If not, write to the
24    --        :-=` Free Software Foundation, Inc., 24    --        :-=` Free Software Foundation, Inc.,
25 59 Temple Place - Suite 330, 25 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#include <opie2/oprocess.h> 30#include <opie2/oprocess.h>
31 31
32#ifdef QWS 32#ifdef QWS
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#else 34#else
35#include <qapplication.h> 35#include <qapplication.h>
36#endif 36#endif
37#include <qdir.h> 37#include <qdir.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qtextstream.h> 39#include <qtextstream.h>
40 40
41#include "utils.h" 41#include "utils.h"
42#include "ipkg.h" 42#include "ipkg.h"
43#include "global.h" 43#include "global.h"
44 44
45using namespace Opie::Core; 45using namespace Opie::Core;
46Ipkg :: Ipkg() 46Ipkg :: Ipkg()
47{ 47{
48 proc = 0; 48 proc = 0;
49} 49}
50 50
51Ipkg :: ~Ipkg() 51Ipkg :: ~Ipkg()
52{ 52{
53} 53}
54 54
55// Option is what we are going to do - install, upgrade, download, reinstall 55// Option is what we are going to do - install, upgrade, download, reinstall
56// package is the package name to install - either a fully qualified path and ipk 56// package is the package name to install - either a fully qualified path and ipk
57// file (if stored locally) or just the name of the package (for a network package) 57// file (if stored locally) or just the name of the package (for a network package)
58// packageName is the package name - (for a network package this will be the same as 58// packageName is the package name - (for a network package this will be the same as
59// package parameter) 59// package parameter)
60// dest is the destination alias (from ipk.conf) 60// dest is the destination alias (from ipk.conf)
61// destDir is the dir that the destination alias points to (used to link to root) 61// destDir is the dir that the destination alias points to (used to link to root)
62// flags is the ipkg options flags 62// flags is the ipkg options flags
63// dir is the directory to run ipkg in (defaults to "") 63// dir is the directory to run ipkg in (defaults to "")
64void Ipkg :: runIpkg() 64void Ipkg :: runIpkg()
65{ 65{
66 error = false; 66 error = false;
67 QStringList commands; 67 QStringList commands;
68 68
69 QDir::setCurrent( "/tmp" ); 69 QDir::setCurrent( "/tmp" );
70 70
71 if ( runtimeDir != "" ) 71 if ( runtimeDir != "" )
72 { 72 {
73 commands << "cd "; 73 commands << "cd ";
74 commands << runtimeDir; 74 commands << runtimeDir;
75 commands << ";"; 75 commands << ";";
76 } 76 }
77 commands << "ipkg" << "-V" << QString::number( infoLevel ) << "-force-defaults"; 77 commands << "ipkg" << "-V" << QString::number( infoLevel ) << "-force-defaults";
78 78
79 // only set the destination for an install operation 79 // only set the destination for an install operation
80 if ( option == "install" ) 80 if ( option == "install" )
81 commands << "-dest" << destination; 81 commands << "-dest" << destination;
82 82
83 83
84 if ( option != "update" && option != "download" ) 84 if ( option != "update" && option != "download" )
85 { 85 {
86 if ( flags & FORCE_DEPENDS ) 86 if ( flags & FORCE_DEPENDS )
87 commands << "-force-depends"; 87 commands << "-force-depends";
88 if ( flags & FORCE_REINSTALL ) 88 if ( flags & FORCE_REINSTALL )
89 commands << "-force-reinstall"; 89 commands << "-force-reinstall";
90 if ( flags & FORCE_REMOVE ) 90 if ( flags & FORCE_REMOVE )
91 commands << "-force-removal-of-essential-packages"; 91 commands << "-force-removal-of-essential-packages";
92 if ( flags & FORCE_OVERWRITE ) 92 if ( flags & FORCE_OVERWRITE )
93 commands << "-force-overwrite"; 93 commands << "-force-overwrite";
94 if ( infoLevel == 3 ) 94 if ( infoLevel == 3 )
95 commands << "-verbose_wget"; 95 commands << "-verbose_wget";
96 96
97 // Handle make links 97 // Handle make links
98 // Rules - If make links is switched on, create links to root 98 // Rules - If make links is switched on, create links to root
99 // if destDir is NOT / 99 // if destDir is NOT /
100 if ( flags & MAKE_LINKS ) 100 if ( flags & MAKE_LINKS )
101 { 101 {
102 // If destDir == / turn off make links as package is being insalled 102 // If destDir == / turn off make links as package is being insalled
103 // to root already. 103 // to root already.
104 if ( destDir == "/" ) 104 if ( destDir == "/" )
105 flags ^= MAKE_LINKS; 105 flags ^= MAKE_LINKS;
106 } 106 }
107 } 107 }
108 108
109#ifdef X86 109#ifdef X86
110 commands << "-f"; 110 commands << "-f";
111 commands << IPKG_CONF; 111 commands << IPKG_CONF;
112#endif 112#endif
113 113
114 114
115 if ( option == "reinstall" ) 115 if ( option == "reinstall" )
116 commands << "install"; 116 commands << "install";
117 else 117 else
118 commands << option; 118 commands << option;
119 if ( package != "" ) 119 if ( package != "" )
120 commands << package; 120 commands << package;
121 121
122 122
123 if ( package != "" ) 123 if ( package != "" )
124 emit outputText( tr( "Dealing with package %1" ).arg( package) ); 124 emit outputText( tr( "Dealing with package %1" ).arg( package) );
125 125
126 qApp->processEvents(); 126 qApp->processEvents();
127 127
128 // If we are removing, reinstalling or upgrading packages and make links option is selected 128 // If we are removing, reinstalling or upgrading packages and make links option is selected
129 // create the links 129 // create the links
130 if ( option == "remove" || option == "reinstall" || option == "upgrade" ) 130 if ( option == "remove" || option == "reinstall" || option == "upgrade" )
131 { 131 {
132 createLinks = false; 132 createLinks = false;
133 if ( flags & MAKE_LINKS ) 133 if ( flags & MAKE_LINKS )
134 { 134 {
135 emit outputText( tr( "Removing symbolic links...\n" ) ); 135 emit outputText( tr( "Removing symbolic links...\n" ) );
136 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 136 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
137 emit outputText( QString( " " ) ); 137 emit outputText( QString( " " ) );
138 } 138 }
139 } 139 }
140 140
141 // Execute command 141 // Execute command
142 dependantPackages = new QList<QString>; 142 dependantPackages = new QList<QString>;
143 dependantPackages->setAutoDelete( true ); 143 dependantPackages->setAutoDelete( true );
144 144
145 executeIpkgCommand( commands, option ); 145 executeIpkgCommand( commands, option );
146
147} 146}
148 147
149void Ipkg :: createSymLinks() 148void Ipkg :: createSymLinks()
150{ 149{
151 if ( option == "install" || option == "reinstall" || option == "upgrade" ) 150 if ( option == "install" || option == "reinstall" || option == "upgrade" )
152 { 151 {
153 // If we are not removing packages and make links option is selected 152 // If we are not removing packages and make links option is selected
154 // create the links 153 // create the links
155 createLinks = true; 154 createLinks = true;
156 if ( flags & MAKE_LINKS ) 155 if ( flags & MAKE_LINKS )
157 { 156 {
158 emit outputText( " " ); 157 emit outputText( " " );
159 emit outputText( tr( "Creating symbolic links for %1." ).arg( package) ); 158 emit outputText( tr( "Creating symbolic links for %1." ).arg( package) );
160 159
161 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 160 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
162 161
163 // link dependant packages that were installed with this release 162 // link dependant packages that were installed with this release
164 QString *pkg; 163 QString *pkg;
165 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) 164 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() )
166 { 165 {
167 if ( *pkg == package ) 166 if ( *pkg == package )
168 continue; 167 continue;
169 emit outputText( " " ); 168 emit outputText( " " );
170 emit outputText( tr( "Creating symbolic links for %1" ).arg( *pkg ) ); 169 emit outputText( tr( "Creating symbolic links for %1" ).arg( *pkg ) );
171 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); 170 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir );
172 } 171 }
173 } 172 }
174 } 173 }
175 174
176 delete dependantPackages; 175 delete dependantPackages;
177 176
178 emit outputText( tr("Finished") ); 177 emit outputText( tr("Finished") );
179 emit outputText( "" ); 178 emit outputText( "" );
180} 179}
181 180
182void Ipkg :: removeStatusEntry() 181void Ipkg :: removeStatusEntry()
183{ 182{
184 QString statusFile = destDir; 183 QString statusFile = destDir;
185 if ( statusFile.right( 1 ) != "/" ) 184 if ( statusFile.right( 1 ) != "/" )
186 statusFile.append( "/" ); 185 statusFile.append( "/" );
187 statusFile.append( "usr/lib/ipkg/status" ); 186 statusFile.append( "usr/lib/ipkg/status" );
188 QString outStatusFile = statusFile; 187 QString outStatusFile = statusFile;
189 outStatusFile.append( ".tmp" ); 188 outStatusFile.append( ".tmp" );
190 189
191 emit outputText( "" ); 190 emit outputText( "" );
192 emit outputText( tr("Removing status entry...") ); 191 emit outputText( tr("Removing status entry...") );
193 QString tempstr = tr("status file - "); 192 QString tempstr = tr("status file - ");
194 tempstr.append( statusFile ); 193 tempstr.append( statusFile );
195 emit outputText( tempstr ); 194 emit outputText( tempstr );
196 tempstr = tr("package - "); 195 tempstr = tr("package - ");
197 tempstr.append( package ); 196 tempstr.append( package );
198 emit outputText( tempstr ); 197 emit outputText( tempstr );
199 198
200 QFile readFile( statusFile ); 199 QFile readFile( statusFile );
201 QFile writeFile( outStatusFile ); 200 QFile writeFile( outStatusFile );
202 201
203 if ( !readFile.open( IO_ReadOnly ) ) 202 if ( !readFile.open( IO_ReadOnly ) )
204 { 203 {
205 tempstr = tr("Couldn't open status file - "); 204 tempstr = tr("Couldn't open status file - ");
206 tempstr.append( statusFile ); 205 tempstr.append( statusFile );
207 emit outputText( tempstr ); 206 emit outputText( tempstr );
208 return; 207 return;
209 } 208 }
210 209
211 if ( !writeFile.open( IO_WriteOnly ) ) 210 if ( !writeFile.open( IO_WriteOnly ) )
212 { 211 {
213 tempstr = tr("Couldn't create tempory status file - "); 212 tempstr = tr("Couldn't create tempory status file - ");
214 tempstr.append( outStatusFile ); 213 tempstr.append( outStatusFile );
215 emit outputText( tempstr ); 214 emit outputText( tempstr );
216 return; 215 return;
217 } 216 }
218 217
219 int i = 0; 218 int i = 0;
220 219
221 QTextStream readStream( &readFile ); 220 QTextStream readStream( &readFile );
222 QTextStream writeStream( &writeFile ); 221 QTextStream writeStream( &writeFile );
223 QString line; 222 QString line;
224 223
225 char k[21]; 224 char k[21];
226 char v[1001]; 225 char v[1001];
227 QString key; 226 QString key;
228 QString value; 227 QString value;
229 228
230 while ( !readStream.atEnd() ) 229 while ( !readStream.atEnd() )
231 { 230 {
232 //read new line 231 //read new line
233 line = readStream.readLine(); 232 line = readStream.readLine();
234 233
235 if ( line.contains( ":", TRUE ) ) 234 if ( line.contains( ":", TRUE ) )
236 { 235 {
237 //grep key and value from line 236 //grep key and value from line
238 k[0] = '\0'; 237 k[0] = '\0';
239 v[0] = '\0'; 238 v[0] = '\0';
240 sscanf( line, "%[^:]: %[^\n]", k, v ); 239 sscanf( line, "%[^:]: %[^\n]", k, v );
241 key = k; 240 key = k;
242 value = v; 241 value = v;
243 key = key.stripWhiteSpace(); 242 key = key.stripWhiteSpace();
244 value = value.stripWhiteSpace(); 243 value = value.stripWhiteSpace();
245 } else { 244 } else {
246 key = ""; 245 key = "";
247 value = ""; 246 value = "";
248 } 247 }
249 248
250 if ( key == "Package" && value == package ) 249 if ( key == "Package" && value == package )
251 { 250 {
252 //skip lines from the deleted package 251 //skip lines from the deleted package
253 while ( ( !readStream.atEnd() ) && ( line.stripWhiteSpace() != "" ) ) 252 while ( ( !readStream.atEnd() ) && ( line.stripWhiteSpace() != "" ) )
254 { 253 {
255 line = readStream.readLine(); 254 line = readStream.readLine();
256 } 255 }
257 } else { 256 } else {
258 257
259 //write other lines into the tempfile 258 //write other lines into the tempfile
260 writeStream << line << "\n"; 259 writeStream << line << "\n";
261 260
262 // Improve UI responsiveness 261 // Improve UI responsiveness
263 i++; 262 i++;
264 if ( ( i % 50 ) == 0 ) 263 if ( ( i % 50 ) == 0 )
265 qApp->processEvents(); 264 qApp->processEvents();
266 } 265 }
267 } 266 }
268 267
269 readFile.close(); 268 readFile.close();
270 writeFile.close(); 269 writeFile.close();
271 270
272 // 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
273 remove( statusFile ); 272 remove( statusFile );
274 rename( outStatusFile, statusFile ); 273 rename( outStatusFile, statusFile );
275 } 274 }
276 275
276int Ipkg :: executeIpkgLinkCommand( QStringList *cmd )
277{
278 // If one is already running - should never be but just to be safe
279 if ( proc )
280 {
281 delete proc;
282 proc = 0;
283 }
284
285 // OK we're gonna use OProcess to run this thing
286 proc = new OProcess();
287 aborted = false;
288
289 // Connect up our slots
290 connect(proc, SIGNAL(processExited(Opie::Core::OProcess*)),
291 this, SLOT( linkProcessFinished()));
292 connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),
293 this, SLOT(linkCommandStdout(Opie::Core::OProcess*,char*,int)));
294
295 *proc << *cmd;
296
297 if(!proc->start(OProcess::NotifyOnExit, OProcess::All))
298 {
299 emit outputText( tr("Couldn't start ipkg-link process" ) );
300 }
301}
302
303void Ipkg::linkProcessFinished()
304{
305 // Report that the link process succeeded/failed
306
307 if ( error )
308 emit outputText( tr("Symbolic linking failed!\n") );
309 else
310 emit outputText( tr("Symbolic linking succeeded.\n") );
311
312 delete proc;
313 proc = 0;
314 finished = true;
315}
316
317void Ipkg::linkCommandStdout(OProcess*, char *buffer, int buflen)
318{
319 QString lineStr = buffer;
320 if ( lineStr[buflen-1] == '\n' )
321 buflen --;
322 lineStr = lineStr.left( buflen );
323 emit outputText( lineStr );
324
325 if ( lineStr.find( " not found." ) != -1 )
326 {
327 // Capture ipkg-link errors
328 error = true;
329 }
330
331 buffer[0] = '\0';
332}
333
277int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ ) 334int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ )
278{ 335{
279 // If one is already running - should never be but just to be safe 336 // If one is already running - should never be but just to be safe
280 if ( proc ) 337 if ( proc )
281 { 338 {
282 delete proc; 339 delete proc;
283 proc = 0; 340 proc = 0;
284 } 341 }
285 342
286 // OK we're gonna use OProcess to run this thing 343 // OK we're gonna use OProcess to run this thing
287 proc = new OProcess(); 344 proc = new OProcess();
288 aborted = false; 345 aborted = false;
289 346
290 347
291 // Connect up our slots 348 // Connect up our slots
292 connect(proc, SIGNAL(processExited(Opie::Core::OProcess*)), 349 connect(proc, SIGNAL(processExited(Opie::Core::OProcess*)),
293 this, SLOT( processFinished())); 350 this, SLOT( processFinished()));
294 351
295 connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), 352 connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),
296 this, SLOT(commandStdout(Opie::Core::OProcess*,char*,int))); 353 this, SLOT(commandStdout(Opie::Core::OProcess*,char*,int)));
297 354
298 connect(proc, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), 355 connect(proc, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),
299 this, SLOT(commandStderr(Opie::Core::OProcess*,char*,int))); 356 this, SLOT(commandStderr(Opie::Core::OProcess*,char*,int)));
300 357
301 for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) 358 for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it )
302 { 359 {
303 *proc << (*it).latin1(); 360 *proc << (*it).latin1();
304 } 361 }
305 362
306 // Start the process going 363 // Start the process going
307 finished = false; 364 finished = false;
308 if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) 365 if(!proc->start(OProcess::NotifyOnExit, OProcess::All))
309 { 366 {
310 emit outputText( tr("Couldn't start ipkg process" ) ); 367 emit outputText( tr("Couldn't start ipkg process" ) );
311 } 368 }
312} 369}
313 370
314void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) 371void Ipkg::commandStdout(OProcess*, char *buffer, int buflen)
315{ 372{
316 QString lineStr = buffer; 373 QString lineStr = buffer;
317 if ( lineStr[buflen-1] == '\n' ) 374 if ( lineStr[buflen-1] == '\n' )
318 buflen --; 375 buflen --;
319 lineStr = lineStr.left( buflen ); 376 lineStr = lineStr.left( buflen );
320 emit outputText( lineStr ); 377 emit outputText( lineStr );
321 378
322 // check if we are installing dependant packages 379 // check if we are installing dependant packages
323 if ( option == "install" || option == "reinstall" ) 380 if ( option == "install" || option == "reinstall" )
324 { 381 {
325 // Need to keep track of any dependant packages that get installed 382 // Need to keep track of any dependant packages that get installed
326 // so that we can create links to them as necessary 383 // so that we can create links to them as necessary
327 if ( lineStr.startsWith( "Installing " ) ) 384 if ( lineStr.startsWith( "Installing " ) )
328 { 385 {
329 int start = lineStr.find( " " ) + 1; 386 int start = lineStr.find( " " ) + 1;
330 int end = lineStr.find( " ", start ); 387 int end = lineStr.find( " ", start );
331 QString *package = new QString( lineStr.mid( start, end-start ) ); 388 QString *package = new QString( lineStr.mid( start, end-start ) );
332 dependantPackages->append( package ); 389 dependantPackages->append( package );
333 } 390 }
334 } 391 }
335 else if ( option == "remove" && !( flags & FORCE_DEPENDS ) && 392 else if ( option == "remove" && !( flags & FORCE_DEPENDS ) &&
336 lineStr.find( "is depended upon by packages:" ) != -1 ) 393 lineStr.find( "is depended upon by packages:" ) != -1 )
337 { 394 {
338 // Ipkg should send this to STDERR, but doesn't - so trap here 395 // Ipkg should send this to STDERR, but doesn't - so trap here
339 error = true; 396 error = true;
340 } 397 }
341 398
342 buffer[0] = '\0'; 399 buffer[0] = '\0';
343} 400}
344 401
345void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) 402void Ipkg::commandStderr(OProcess*, char *buffer, int buflen)
346{ 403{
347 QString lineStr = buffer; 404 QString lineStr = buffer;
348 if ( lineStr[buflen-1] == '\n' ) 405 if ( lineStr[buflen-1] == '\n' )
349 buflen --; 406 buflen --;
350 lineStr=lineStr.left( buflen ); 407 lineStr=lineStr.left( buflen );
351 emit outputText( lineStr ); 408 emit outputText( lineStr );
352 buffer[0] = '\0'; 409 buffer[0] = '\0';
353 error = true; 410 error = true;
354} 411}
355 412
356void Ipkg::processFinished() 413void Ipkg::processFinished()
357{ 414{
358 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file 415 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file
359 // to workaround an ipkg bug which stops reinstall to a different location 416 // to workaround an ipkg bug which stops reinstall to a different location
360 417
361 if ( !error && option == "remove" ) 418 if ( !error && option == "remove" )
362 removeStatusEntry(); 419 removeStatusEntry();
363 420
364 delete proc; 421 delete proc;
365 proc = 0; 422 proc = 0;
366 finished = true; 423 finished = true;
367 424
368 emit ipkgFinished(); 425 emit ipkgFinished();
369} 426}
370 427
371 428
372void Ipkg :: abort() 429void Ipkg :: abort()
373{ 430{
374 if ( proc ) 431 if ( proc )
375 { 432 {
376 proc->kill(); 433 proc->kill();
377 aborted = true; 434 aborted = true;
378 } 435 }
379} 436}
380 437
381void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) 438void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir )
382{ 439{
383 if ( dest == "root" || dest == "/" ) 440 if ( dest == "root" || dest == "/" )
384 return; 441 return;
385 442
443 if( option == "remove" || option == "reinstall" || option == "upgrade" )
444 {
445 QStringList commands;
446
447 if ( runtimeDir != "" )
448 {
449 commands << "cd ";
450 commands << runtimeDir;
451 commands << ";";
452 }
453 commands << "ipkg-link" << "remove" << packFileName;
454 executeIpkgLinkCommand( &commands );
455 }
456
457 if( option == "install" || option == "reinstall" || option == "upgrade" )
458 {
459 QStringList commands;
460 if ( runtimeDir != "" )
461 {
462 commands << "cd ";
463 commands << runtimeDir;
464 commands << ";";
465 }
466 commands << "ipkg-link" << "add" << packFileName;
467 executeIpkgLinkCommand( &commands );
468 }
469/*
386 qApp->processEvents(); 470 qApp->processEvents();
387 QStringList *fileList = getList( packFileName, destDir ); 471 QStringList *fileList = getList( packFileName, destDir );
388 qApp->processEvents(); 472 qApp->processEvents();
389 processFileList( fileList, destDir ); 473 processFileList( fileList, destDir );
390 delete fileList; 474 delete fileList;*/
391} 475}
392 476/*
393QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) 477QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir )
394{ 478{
395 QString packageFileDir = destDir; 479 QString packageFileDir = destDir;
396 packageFileDir.append( "/usr/lib/ipkg/info/" ); 480 packageFileDir.append( "/usr/lib/ipkg/info/" );
397 packageFileDir.append( packageFilename ); 481 packageFileDir.append( packageFilename );
398 packageFileDir.append( ".list" ); 482 packageFileDir.append( ".list" );
399 QFile f( packageFileDir ); 483 QFile f( packageFileDir );
400 484
401 if ( !f.open(IO_ReadOnly) ) 485 if ( !f.open(IO_ReadOnly) )
402 { 486 {
403 // Couldn't open from dest, try from / 487 // Couldn't open from dest, try from /
404 f.close(); 488 f.close();
405 489
406 packageFileDir = "/usr/lib/ipkg/info/"; 490 packageFileDir = "/usr/lib/ipkg/info/";
407 packageFileDir.append( packageFilename ); 491 packageFileDir.append( packageFilename );
408 packageFileDir.append( ".list" ); 492 packageFileDir.append( ".list" );
409 f.setName( packageFileDir ); 493 f.setName( packageFileDir );
410 if ( ! f.open(IO_ReadOnly) ) 494 if ( ! f.open(IO_ReadOnly) )
411 { 495 {
412 QString tempstr = tr("Could not open :"); 496 QString tempstr = tr("Could not open :");
413 tempstr.append( packageFileDir ); 497 tempstr.append( packageFileDir );
414 emit outputText( tempstr ); 498 emit outputText( tempstr );
415 return (QStringList*)0; 499 return (QStringList*)0;
416 } 500 }
417 } 501 }
418 QStringList *fileList = new QStringList(); 502 QStringList *fileList = new QStringList();
419 QTextStream t( &f ); 503 QTextStream t( &f );
420 while ( !t.eof() ) 504 while ( !t.eof() )
421 *fileList += t.readLine(); 505 *fileList += t.readLine();
422 506
423 f.close(); 507 f.close();
424 return fileList; 508 return fileList;
425} 509}
426 510
427void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) 511void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir )
428{ 512{
429 if ( !fileList || fileList->isEmpty() ) 513 if ( !fileList || fileList->isEmpty() )
430 return; 514 return;
431 515
432 QString baseDir = ROOT; 516 QString baseDir = ROOT;
433 517
434 if ( createLinks == true ) 518 if ( createLinks == true )
435 { 519 {
436 for ( uint i=0; i < fileList->count(); i++ ) 520 for ( uint i=0; i < fileList->count(); i++ )
437 { 521 {
438 processLinkDir( (*fileList)[i], baseDir, destDir ); 522 processLinkDir( (*fileList)[i], baseDir, destDir );
439 qApp->processEvents(); 523 qApp->processEvents();
440 } 524 }
441 } 525 }
442 else 526 else
443 { 527 {
444 for ( int i = fileList->count()-1; i >= 0 ; i-- ) 528 for ( int i = fileList->count()-1; i >= 0 ; i-- )
445 { 529 {
446 processLinkDir( (*fileList)[i], baseDir, destDir ); 530 processLinkDir( (*fileList)[i], baseDir, destDir );
447 qApp->processEvents(); 531 qApp->processEvents();
448 } 532 }
449 } 533 }
450} 534}
451 535
452void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) 536void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir )
453{ 537{
454 538
455 QString sourceFile = baseDir; 539 QString sourceFile = baseDir;
456 sourceFile.append( file ); 540 sourceFile.append( file );
457 541
458 QString linkFile = destDir; 542 QString linkFile = destDir;
459 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) 543 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" )
460 { 544 {
461 linkFile.append( file.mid( 1 ) ); 545 linkFile.append( file.mid( 1 ) );
462 } 546 }
463 else 547 else
464 { 548 {
465 linkFile.append( file ); 549 linkFile.append( file );
466 } 550 }
467 QString text; 551 QString text;
468 if ( createLinks ) 552 if ( createLinks )
469 { 553 {
470 // If this file is a directory (ends with a /) and it doesn't exist, 554 // If this file is a directory (ends with a /) and it doesn't exist,
471 // we need to create it 555 // we need to create it
472 if ( file.right(1) == "/" ) 556 if ( file.right(1) == "/" )
473 { 557 {
474 QFileInfo f( linkFile ); 558 QFileInfo f( linkFile );
475 if ( !f.exists() ) 559 if ( !f.exists() )
476 { 560 {
477 QString tempstr = tr("Creating directory "); 561 QString tempstr = tr("Creating directory ");
478 tempstr.append( linkFile ); 562 tempstr.append( linkFile );
479 emit outputText( tempstr ); 563 emit outputText( tempstr );
480 QDir d; 564 QDir d;
481 d.mkdir( linkFile, true ); 565 d.mkdir( linkFile, true );
482 } 566 }
483// else 567// else
484// emit outputText( QString( "Directory " ) + linkFile + " already exists" ); 568// emit outputText( QString( "Directory " ) + linkFile + " already exists" );
485 569
486 } 570 }
487 else 571 else
488 { 572 {
489 int rc = symlink( sourceFile, linkFile ); 573 int rc = symlink( sourceFile, linkFile );
490 text = ( rc == 0 ? tr( "Linked %1 to %2" ) : tr( "Failed to link %1 to %2" ) ). 574 text = ( rc == 0 ? tr( "Linked %1 to %2" ) : tr( "Failed to link %1 to %2" ) ).
491 arg( sourceFile ). 575 arg( sourceFile ).
492 arg( linkFile ); 576 arg( linkFile );
493 emit outputText( text ); 577 emit outputText( text );
494 } 578 }
495 } 579 }
496 else 580 else
497 { 581 {
498 QFileInfo f( linkFile ); 582 QFileInfo f( linkFile );
499 if ( f.exists() ) 583 if ( f.exists() )
500 { 584 {
501 if ( f.isFile() ) 585 if ( f.isFile() )
502 { 586 {
503 QFile f( linkFile ); 587 QFile f( linkFile );
504 bool rc = f.remove(); 588 bool rc = f.remove();
505 589
506 text = ( rc ? tr( "Removed %1" ) : tr( "Failed to remove %1" ) ).arg( linkFile ); 590 text = ( rc ? tr( "Removed %1" ) : tr( "Failed to remove %1" ) ).arg( linkFile );
507 emit outputText( text ); 591 emit outputText( text );
508 } 592 }
509 else if ( f.isDir() ) 593 else if ( f.isDir() )
510 { 594 {
511 QDir d; 595 QDir d;
512 bool rc = d.rmdir( linkFile, true ); 596 bool rc = d.rmdir( linkFile, true );
513 if ( rc ) 597 if ( rc )
514 { 598 {
515 text = ( rc ? tr( "Removed " ) : tr( "Failed to remove " ) ).arg( linkFile ); 599 text = ( rc ? tr( "Removed " ) : tr( "Failed to remove " ) ).arg( linkFile );
516 emit outputText( text ); 600 emit outputText( text );
517 } 601 }
518 } 602 }
519 } 603 }
520 } 604 }
521} 605}
606*/
diff --git a/noncore/settings/aqpkg/ipkg.h b/noncore/settings/aqpkg/ipkg.h
index e216d17..5df63f1 100644
--- a/noncore/settings/aqpkg/ipkg.h
+++ b/noncore/settings/aqpkg/ipkg.h
@@ -1,104 +1,107 @@
1/* 1/*
2                This file is part of the OPIE Project 2                This file is part of the OPIE Project
3 3
4 =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> 4 =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk>
5             .=l. Dan Williams <drw@handhelds.org> 5             .=l. Dan Williams <drw@handhelds.org>
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This file is free software; you can 7 _;:,     .>    :=|. This file is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU General Public 9:`=1 )Y*s>-.--   : the terms of the GNU General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This file is distributed in the hope that 14    .i_,=:_.      -<s. This file is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
19..}^=.=       =       ; Public License for more details. 19..}^=.=       =       ; Public License for more details.
20++=   -.     .`     .: 20++=   -.     .`     .:
21 :     =  ...= . :.=- You should have received a copy of the GNU 21 :     =  ...= . :.=- You should have received a copy of the GNU
22 -.   .:....=;==+<; General Public License along with this file; 22 -.   .:....=;==+<; General Public License along with this file;
23  -_. . .   )=.  = see the file COPYING. If not, write to the 23  -_. . .   )=.  = see the file COPYING. If not, write to the
24    --        :-=` Free Software Foundation, Inc., 24    --        :-=` Free Software Foundation, Inc.,
25 59 Temple Place - Suite 330, 25 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#ifndef IPKG_H 30#ifndef IPKG_H
31#define IPKG_H 31#define IPKG_H
32 32
33 33
34/** 34/**
35 *@author Andy Qua 35 *@author Andy Qua
36 */ 36 */
37 37
38#include <qobject.h> 38#include <qobject.h>
39#include <qstring.h> 39#include <qstring.h>
40#include <qstringlist.h> 40#include <qstringlist.h>
41#include <qlist.h> 41#include <qlist.h>
42 42
43#define FORCE_DEPENDS 0x0001 43#define FORCE_DEPENDS 0x0001
44#define FORCE_REMOVE 0x0002 44#define FORCE_REMOVE 0x0002
45#define FORCE_REINSTALL 0x0004 45#define FORCE_REINSTALL 0x0004
46#define FORCE_OVERWRITE 0x0008 46#define FORCE_OVERWRITE 0x0008
47#define MAKE_LINKS 0x0010 47#define MAKE_LINKS 0x0010
48#define VERBOSE_WGET 0x0020 48#define VERBOSE_WGET 0x0020
49 49
50namespace Opie {namespace Core {class OProcess;}} 50namespace Opie {namespace Core {class OProcess;}}
51 51
52class Ipkg : public QObject 52class Ipkg : public QObject
53{ 53{
54 Q_OBJECT 54 Q_OBJECT
55public: 55public:
56 Ipkg(); 56 Ipkg();
57 ~Ipkg(); 57 ~Ipkg();
58 void runIpkg(); 58 void runIpkg();
59 void createSymLinks(); 59 void createSymLinks();
60 60
61 void setOption( const char *opt ) { option = opt; } 61 void setOption( const char *opt ) { option = opt; }
62 void setPackage( const char *pkg ) { package = pkg; } 62 void setPackage( const char *pkg ) { package = pkg; }
63 void setDestination( const char *dest ) { destination = dest; } 63 void setDestination( const char *dest ) { destination = dest; }
64 void setDestinationDir( const char *dir ) { destDir = dir; } 64 void setDestinationDir( const char *dir ) { destDir = dir; }
65 void setFlags( int fl, int il ) { flags = fl; infoLevel = il; } 65 void setFlags( int fl, int il ) { flags = fl; infoLevel = il; }
66 void setRuntimeDirectory( const char *dir ) { runtimeDir = dir; } 66 void setRuntimeDirectory( const char *dir ) { runtimeDir = dir; }
67 67
68signals: 68signals:
69 void outputText( const QString &text ); 69 void outputText( const QString &text );
70 void ipkgFinished(); 70 void ipkgFinished();
71 71
72public slots: 72public slots:
73 void linkCommandStdout(Opie::Core::OProcess*, char *buffer, int buflen);
73 void commandStdout(Opie::Core::OProcess*, char *buffer, int buflen); 74 void commandStdout(Opie::Core::OProcess*, char *buffer, int buflen);
74 void commandStderr(Opie::Core::OProcess*, char *buffer, int buflen); 75 void commandStderr(Opie::Core::OProcess*, char *buffer, int buflen);
76 void linkProcessFinished();
75 void processFinished(); 77 void processFinished();
76 void abort(); 78 void abort();
77 79
78 80
79private: 81private:
80 bool createLinks; 82 bool createLinks;
81 bool aborted; 83 bool aborted;
82 bool error; 84 bool error;
83 QString option; 85 QString option;
84 QString package; 86 QString package;
85 QString destination; 87 QString destination;
86 QString destDir; 88 QString destDir;
87 QString runtimeDir; 89 QString runtimeDir;
88 Opie::Core::OProcess *proc; 90 Opie::Core::OProcess *proc;
89 int flags; 91 int flags;
90 int infoLevel; 92 int infoLevel;
91 bool finished; 93 bool finished;
92 94
93 QList<QString> *dependantPackages; 95 QList<QString> *dependantPackages;
94 96
97 int executeIpkgLinkCommand( QStringList *cmd );
95 int executeIpkgCommand( QStringList &cmd, const QString option ); 98 int executeIpkgCommand( QStringList &cmd, const QString option );
96 void removeStatusEntry(); 99 void removeStatusEntry();
97 void linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ); 100 void linkPackage( const QString &packFileName, const QString &dest, const QString &destDir );
98 QStringList* getList( const QString &packageFilename, const QString &destDir ); 101 QStringList* getList( const QString &packageFilename, const QString &destDir );
99 void processFileList( const QStringList *fileList, const QString &destDir ); 102 void processFileList( const QStringList *fileList, const QString &destDir );
100 void processLinkDir( const QString &file, const QString &baseDir, const QString &destDir ); 103 void processLinkDir( const QString &file, const QString &baseDir, const QString &destDir );
101 104
102}; 105};
103 106
104#endif 107#endif