summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/aqpkg.pro2
-rw-r--r--noncore/settings/aqpkg/ipkg.cpp103
-rw-r--r--noncore/settings/aqpkg/utils.cpp9
3 files changed, 52 insertions, 62 deletions
diff --git a/noncore/settings/aqpkg/aqpkg.pro b/noncore/settings/aqpkg/aqpkg.pro
index 882cfd4..a24f036 100644
--- a/noncore/settings/aqpkg/aqpkg.pro
+++ b/noncore/settings/aqpkg/aqpkg.pro
@@ -1,40 +1,40 @@
1 CONFIG = qt warn_on release quick-app 1 CONFIG = qt warn_on release quick-app
2 HEADERS = global.h \ 2 HEADERS = global.h \
3 mainwin.h \ 3 mainwin.h \
4 datamgr.h \ 4 datamgr.h \
5 settingsimpl.h \ 5 settingsimpl.h \
6 ipkg.h \ 6 ipkg.h \
7 packagewin.h \ 7 packagewin.h \
8 package.h \ 8 package.h \
9 installdlgimpl.h \ 9 installdlgimpl.h \
10 instoptionsimpl.h \ 10 instoptionsimpl.h \
11 destination.h \ 11 destination.h \
12 utils.h \ 12 utils.h \
13 server.h \ 13 server.h \
14 letterpushbutton.h \ 14 letterpushbutton.h \
15 inputdlg.h \ 15 inputdlg.h \
16 categoryfilterimpl.h 16 categoryfilterimpl.h
17 SOURCES = mainwin.cpp \ 17 SOURCES = mainwin.cpp \
18 datamgr.cpp \ 18 datamgr.cpp \
19 mem.cpp \ 19 mem.cpp \
20 settingsimpl.cpp \ 20 settingsimpl.cpp \
21 ipkg.cpp \ 21 ipkg.cpp \
22 main.cpp \ 22 main.cpp \
23 packagewin.cpp \ 23 packagewin.cpp \
24 package.cpp \ 24 package.cpp \
25 installdlgimpl.cpp \ 25 installdlgimpl.cpp \
26 instoptionsimpl.cpp \ 26 instoptionsimpl.cpp \
27 destination.cpp \ 27 destination.cpp \
28 utils.cpp \ 28 utils.cpp \
29 server.cpp \ 29 server.cpp \
30 letterpushbutton.cpp \ 30 letterpushbutton.cpp \
31 inputdlg.cpp \ 31 inputdlg.cpp \
32 version.cpp \ 32 version.cpp \
33 categoryfilterimpl.cpp 33 categoryfilterimpl.cpp
34 TARGET = aqpkg 34 TARGET = aqpkg
35INCLUDEPATH += $(OPIEDIR)/include 35INCLUDEPATH += $(OPIEDIR)/include
36DEPENDPATH += $(OPIEDIR)/include 36DEPENDPATH += $(OPIEDIR)/include
37LIBS += -lqpe -lopie -lstdc++ 37LIBS += -lqpe -lopie
38 38
39include ( $(OPIEDIR)/include.pro ) 39include ( $(OPIEDIR)/include.pro )
40 40
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp
index 43eaaae..2a9c576 100644
--- a/noncore/settings/aqpkg/ipkg.cpp
+++ b/noncore/settings/aqpkg/ipkg.cpp
@@ -1,475 +1,466 @@
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 <fstream>
31#include <iostream>
32#include <vector>
33using namespace std;
34
35#include <stdio.h>
36#include <unistd.h>
37
38#ifdef QWS 30#ifdef QWS
39#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
40#else 32#else
41#include <qapplication.h> 33#include <qapplication.h>
42#endif 34#endif
43#include <qdir.h> 35#include <qdir.h>
36#include <qfile.h>
44#include <qtextstream.h> 37#include <qtextstream.h>
45 38
46#include <opie/oprocess.h> 39#include <opie/oprocess.h>
47 40
48#include "utils.h" 41#include "utils.h"
49#include "ipkg.h" 42#include "ipkg.h"
50#include "global.h" 43#include "global.h"
51 44
52Ipkg :: Ipkg() 45Ipkg :: Ipkg()
53{ 46{
54 proc = 0; 47 proc = 0;
55} 48}
56 49
57Ipkg :: ~Ipkg() 50Ipkg :: ~Ipkg()
58{ 51{
59} 52}
60 53
61// Option is what we are going to do - install, upgrade, download, reinstall 54// Option is what we are going to do - install, upgrade, download, reinstall
62// package is the package name to install - either a fully qualified path and ipk 55// package is the package name to install - either a fully qualified path and ipk
63// file (if stored locally) or just the name of the package (for a network package) 56// file (if stored locally) or just the name of the package (for a network package)
64// packageName is the package name - (for a network package this will be the same as 57// packageName is the package name - (for a network package this will be the same as
65// package parameter) 58// package parameter)
66// dest is the destination alias (from ipk.conf) 59// dest is the destination alias (from ipk.conf)
67// destDir is the dir that the destination alias points to (used to link to root) 60// destDir is the dir that the destination alias points to (used to link to root)
68// flags is the ipkg options flags 61// flags is the ipkg options flags
69// dir is the directory to run ipkg in (defaults to "") 62// dir is the directory to run ipkg in (defaults to "")
70void Ipkg :: runIpkg() 63void Ipkg :: runIpkg()
71{ 64{
72 error = false; 65 error = false;
73 QStringList commands; 66 QStringList commands;
74 67
75 QDir::setCurrent( "/tmp" ); 68 QDir::setCurrent( "/tmp" );
76 69
77 if ( runtimeDir != "" ) 70 if ( runtimeDir != "" )
78 { 71 {
79 commands << "cd "; 72 commands << "cd ";
80 commands << runtimeDir; 73 commands << runtimeDir;
81 commands << ";"; 74 commands << ";";
82 } 75 }
83 commands << "ipkg" << "-V" << QString::number( infoLevel ) << "-force-defaults"; 76 commands << "ipkg" << "-V" << QString::number( infoLevel ) << "-force-defaults";
84 77
85 // only set the destination for an install operation 78 // only set the destination for an install operation
86 if ( option == "install" ) 79 if ( option == "install" )
87 commands << "-dest" << destination; 80 commands << "-dest" << destination;
88 81
89 82
90 if ( option != "update" && option != "download" ) 83 if ( option != "update" && option != "download" )
91 { 84 {
92 if ( flags & FORCE_DEPENDS ) 85 if ( flags & FORCE_DEPENDS )
93 commands << "-force-depends"; 86 commands << "-force-depends";
94 if ( flags & FORCE_REINSTALL ) 87 if ( flags & FORCE_REINSTALL )
95 commands << "-force-reinstall"; 88 commands << "-force-reinstall";
96 if ( flags & FORCE_REMOVE ) 89 if ( flags & FORCE_REMOVE )
97 commands << "-force-removal-of-essential-packages"; 90 commands << "-force-removal-of-essential-packages";
98 if ( flags & FORCE_OVERWRITE ) 91 if ( flags & FORCE_OVERWRITE )
99 commands << "-force-overwrite"; 92 commands << "-force-overwrite";
100 if ( infoLevel == 3 ) 93 if ( infoLevel == 3 )
101 commands << "-verbose_wget"; 94 commands << "-verbose_wget";
102 95
103 // Handle make links 96 // Handle make links
104 // Rules - If make links is switched on, create links to root 97 // Rules - If make links is switched on, create links to root
105 // if destDir is NOT / 98 // if destDir is NOT /
106 if ( flags & MAKE_LINKS ) 99 if ( flags & MAKE_LINKS )
107 { 100 {
108 // If destDir == / turn off make links as package is being insalled 101 // If destDir == / turn off make links as package is being insalled
109 // to root already. 102 // to root already.
110 if ( destDir == "/" ) 103 if ( destDir == "/" )
111 flags ^= MAKE_LINKS; 104 flags ^= MAKE_LINKS;
112 } 105 }
113 } 106 }
114 107
115#ifdef X86 108#ifdef X86
116 commands << "-f"; 109 commands << "-f";
117 commands << IPKG_CONF; 110 commands << IPKG_CONF;
118#endif 111#endif
119 112
120 113
121 if ( option == "reinstall" ) 114 if ( option == "reinstall" )
122 commands << "install"; 115 commands << "install";
123 else 116 else
124 commands << option; 117 commands << option;
125 if ( package != "" ) 118 if ( package != "" )
126 commands << package; 119 commands << package;
127 120
128 121
129 if ( package != "" ) 122 if ( package != "" )
130 emit outputText( tr( "Dealing with package %1" ).arg( package) ); 123 emit outputText( tr( "Dealing with package %1" ).arg( package) );
131 124
132 qApp->processEvents(); 125 qApp->processEvents();
133 126
134 // If we are removing, reinstalling or upgrading packages and make links option is selected 127 // If we are removing, reinstalling or upgrading packages and make links option is selected
135 // create the links 128 // create the links
136 if ( option == "remove" || option == "reinstall" || option == "upgrade" ) 129 if ( option == "remove" || option == "reinstall" || option == "upgrade" )
137 { 130 {
138 createLinks = false; 131 createLinks = false;
139 if ( flags & MAKE_LINKS ) 132 if ( flags & MAKE_LINKS )
140 { 133 {
141 emit outputText( tr( "Removing symbolic links...\n" ) ); 134 emit outputText( tr( "Removing symbolic links...\n" ) );
142 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 135 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
143 emit outputText( QString( " " ) ); 136 emit outputText( QString( " " ) );
144 } 137 }
145 } 138 }
146 139
147 // Execute command 140 // Execute command
148 dependantPackages = new QList<QString>; 141 dependantPackages = new QList<QString>;
149 dependantPackages->setAutoDelete( true ); 142 dependantPackages->setAutoDelete( true );
150 143
151 executeIpkgCommand( commands, option ); 144 executeIpkgCommand( commands, option );
152 145
153} 146}
154 147
155void Ipkg :: createSymLinks() 148void Ipkg :: createSymLinks()
156{ 149{
157 if ( option == "install" || option == "reinstall" || option == "upgrade" ) 150 if ( option == "install" || option == "reinstall" || option == "upgrade" )
158 { 151 {
159 // 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
160 // create the links 153 // create the links
161 createLinks = true; 154 createLinks = true;
162 if ( flags & MAKE_LINKS ) 155 if ( flags & MAKE_LINKS )
163 { 156 {
164 emit outputText( " " ); 157 emit outputText( " " );
165 emit outputText( tr( "Creating symbolic links for %1." ).arg( package) ); 158 emit outputText( tr( "Creating symbolic links for %1." ).arg( package) );
166 159
167 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 160 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
168 161
169 // link dependant packages that were installed with this release 162 // link dependant packages that were installed with this release
170 QString *pkg; 163 QString *pkg;
171 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) 164 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() )
172 { 165 {
173 if ( *pkg == package ) 166 if ( *pkg == package )
174 continue; 167 continue;
175 emit outputText( " " ); 168 emit outputText( " " );
176 emit outputText( tr( "Creating symbolic links for %1" ).arg( *pkg ) ); 169 emit outputText( tr( "Creating symbolic links for %1" ).arg( *pkg ) );
177 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); 170 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir );
178 } 171 }
179 } 172 }
180 } 173 }
181 174
182 delete dependantPackages; 175 delete dependantPackages;
183 176
184 emit outputText( tr("Finished") ); 177 emit outputText( tr("Finished") );
185 emit outputText( "" ); 178 emit outputText( "" );
186} 179}
187 180
188void Ipkg :: removeStatusEntry() 181void Ipkg :: removeStatusEntry()
189{ 182{
190 QString statusFile = destDir; 183 QString statusFile = destDir;
191 if ( statusFile.right( 1 ) != "/" ) 184 if ( statusFile.right( 1 ) != "/" )
192 statusFile.append( "/" ); 185 statusFile.append( "/" );
193 statusFile.append( "usr/lib/ipkg/status" ); 186 statusFile.append( "usr/lib/ipkg/status" );
194 QString outStatusFile = statusFile; 187 QString outStatusFile = statusFile;
195 outStatusFile.append( ".tmp" ); 188 outStatusFile.append( ".tmp" );
196 189
197 emit outputText( "" ); 190 emit outputText( "" );
198 emit outputText( tr("Removing status entry...") ); 191 emit outputText( tr("Removing status entry...") );
199 QString tempstr = tr("status file - "); 192 QString tempstr = tr("status file - ");
200 tempstr.append( statusFile ); 193 tempstr.append( statusFile );
201 emit outputText( tempstr ); 194 emit outputText( tempstr );
202 tempstr = tr("package - "); 195 tempstr = tr("package - ");
203 tempstr.append( package ); 196 tempstr.append( package );
204 emit outputText( tempstr ); 197 emit outputText( tempstr );
205 198
206 ifstream in( statusFile ); 199 QFile readFile( statusFile );
207 ofstream out( outStatusFile ); 200 QFile writeFile( outStatusFile );
208 if ( !in.is_open() ) 201
202 if ( !readFile.open( IO_ReadOnly ) )
209 { 203 {
210 tempstr = tr("Couldn't open status file - "); 204 tempstr = tr("Couldn't open status file - ");
211 tempstr.append( statusFile ); 205 tempstr.append( statusFile );
212 emit outputText( tempstr ); 206 emit outputText( tempstr );
213 return; 207 return;
214 } 208 }
215 209
216 if ( !out.is_open() ) 210 if ( !writeFile.open( IO_WriteOnly ) )
217 { 211 {
218 tempstr = tr("Couldn't create tempory status file - "); 212 tempstr = tr("Couldn't create tempory status file - ");
219 tempstr.append( outStatusFile ); 213 tempstr.append( outStatusFile );
220 emit outputText( tempstr ); 214 emit outputText( tempstr );
221 return; 215 return;
222 } 216 }
223 217
224 char line[1001]; 218 int i = 0;
219
220 QTextStream readStream( &readFile );
221 QTextStream writeStream( &writeFile );
222 QString line;
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 vector<QString> lines; 228
230 int i = 0; 229 while ( !readStream.atEnd() )
231 do
232 { 230 {
233 in.getline( line, 1000 ); 231 //read new line
234 if ( in.eof() ) 232 line = readStream.readLine();
235 continue; 233
236 234 if ( line.contains( ":", TRUE ) )
237 k[0] = '\0';
238 v[0] = '\0';
239
240 sscanf( line, "%[^:]: %[^\n]", k, v );
241 key = k;
242 value = v;
243 key = key.stripWhiteSpace();
244 value = value.stripWhiteSpace();
245 if ( key == "Package" && value == package )
246 { 235 {
247 // Ignore all lines up to next empty 236 //grep key and value from line
248 do 237 k[0] = '\0';
249 { 238 v[0] = '\0';
250 in.getline( line, 1000 ); 239 sscanf( line, "%[^:]: %[^\n]", k, v );
251 if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) 240 key = k;
252 continue; 241 value = v;
253 } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); 242 key = key.stripWhiteSpace();
243 value = value.stripWhiteSpace();
244 } else {
245 key = "";
246 value = "";
254 } 247 }
255 248
256 lines.push_back( QString( line ) ); 249 if ( key == "Package" && value == package )
257 out << line << endl; 250 {
258 251 //skip lines from the deleted package
259 // Improve UI responsiveness 252 while ( ( !readStream.atEnd() ) && ( line.stripWhiteSpace() != "" ) )
260 i++; 253 {
261 if ( ( i % 50 ) == 0 ) 254 line = readStream.readLine();
262 qApp->processEvents(); 255 }
263 } while ( !in.eof() ); 256 } else {
264 257
265 // Write lines out 258 //write other lines into the tempfile
266 vector<QString>::iterator it; 259 writeStream << line << "\n";
267 for ( it = lines.begin() ; it != lines.end() ; ++it )
268 {
269 out << (const char *)(*it) << endl;
270 260
271 // Improve UI responsiveness 261 // Improve UI responsiveness
272 i++; 262 i++;
273 if ( ( i % 50 ) == 0 ) 263 if ( ( i % 50 ) == 0 )
274 qApp->processEvents(); 264 qApp->processEvents();
265 }
275 } 266 }
276 267
277 in.close(); 268 readFile.close();
278 out.close(); 269 writeFile.close();
279 270
280 // 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
281 remove( statusFile ); 272 remove( statusFile );
282 rename( outStatusFile, statusFile ); 273 rename( outStatusFile, statusFile );
283} 274 }
284 275
285int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ ) 276int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ )
286{ 277{
287 // If one is already running - should never be but just to be safe 278 // If one is already running - should never be but just to be safe
288 if ( proc ) 279 if ( proc )
289 { 280 {
290 delete proc; 281 delete proc;
291 proc = 0; 282 proc = 0;
292 } 283 }
293 284
294 // OK we're gonna use OProcess to run this thing 285 // OK we're gonna use OProcess to run this thing
295 proc = new OProcess(); 286 proc = new OProcess();
296 aborted = false; 287 aborted = false;
297 288
298 289
299 // Connect up our slots 290 // Connect up our slots
300 connect(proc, SIGNAL(processExited(OProcess *)), 291 connect(proc, SIGNAL(processExited(OProcess *)),
301 this, SLOT( processFinished())); 292 this, SLOT( processFinished()));
302 293
303 connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), 294 connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)),
304 this, SLOT(commandStdout(OProcess *, char *, int))); 295 this, SLOT(commandStdout(OProcess *, char *, int)));
305 296
306 connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), 297 connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)),
307 this, SLOT(commandStderr(OProcess *, char *, int))); 298 this, SLOT(commandStderr(OProcess *, char *, int)));
308 299
309 for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) 300 for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it )
310 { 301 {
311 *proc << (*it).latin1(); 302 *proc << (*it).latin1();
312 } 303 }
313 304
314 // Start the process going 305 // Start the process going
315 finished = false; 306 finished = false;
316 if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) 307 if(!proc->start(OProcess::NotifyOnExit, OProcess::All))
317 { 308 {
318 emit outputText( tr("Couldn't start ipkg process" ) ); 309 emit outputText( tr("Couldn't start ipkg process" ) );
319 } 310 }
320} 311}
321 312
322void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) 313void Ipkg::commandStdout(OProcess*, char *buffer, int buflen)
323{ 314{
324 QString lineStr = buffer; 315 QString lineStr = buffer;
325 if ( lineStr[buflen-1] == '\n' ) 316 if ( lineStr[buflen-1] == '\n' )
326 buflen --; 317 buflen --;
327 lineStr = lineStr.left( buflen ); 318 lineStr = lineStr.left( buflen );
328 emit outputText( lineStr ); 319 emit outputText( lineStr );
329 320
330 // check if we are installing dependant packages 321 // check if we are installing dependant packages
331 if ( option == "install" || option == "reinstall" ) 322 if ( option == "install" || option == "reinstall" )
332 { 323 {
333 // Need to keep track of any dependant packages that get installed 324 // Need to keep track of any dependant packages that get installed
334 // so that we can create links to them as necessary 325 // so that we can create links to them as necessary
335 if ( lineStr.startsWith( "Installing " ) ) 326 if ( lineStr.startsWith( "Installing " ) )
336 { 327 {
337 int start = lineStr.find( " " ) + 1; 328 int start = lineStr.find( " " ) + 1;
338 int end = lineStr.find( " ", start ); 329 int end = lineStr.find( " ", start );
339 QString *package = new QString( lineStr.mid( start, end-start ) ); 330 QString *package = new QString( lineStr.mid( start, end-start ) );
340 dependantPackages->append( package ); 331 dependantPackages->append( package );
341 } 332 }
342 } 333 }
343 else if ( option == "remove" && !( flags & FORCE_DEPENDS ) && 334 else if ( option == "remove" && !( flags & FORCE_DEPENDS ) &&
344 lineStr.find( "is depended upon by packages:" ) != -1 ) 335 lineStr.find( "is depended upon by packages:" ) != -1 )
345 { 336 {
346 // Ipkg should send this to STDERR, but doesn't - so trap here 337 // Ipkg should send this to STDERR, but doesn't - so trap here
347 error = true; 338 error = true;
348 } 339 }
349 340
350 buffer[0] = '\0'; 341 buffer[0] = '\0';
351} 342}
352 343
353void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) 344void Ipkg::commandStderr(OProcess*, char *buffer, int buflen)
354{ 345{
355 QString lineStr = buffer; 346 QString lineStr = buffer;
356 if ( lineStr[buflen-1] == '\n' ) 347 if ( lineStr[buflen-1] == '\n' )
357 buflen --; 348 buflen --;
358 lineStr=lineStr.left( buflen ); 349 lineStr=lineStr.left( buflen );
359 emit outputText( lineStr ); 350 emit outputText( lineStr );
360 buffer[0] = '\0'; 351 buffer[0] = '\0';
361 error = true; 352 error = true;
362} 353}
363 354
364void Ipkg::processFinished() 355void Ipkg::processFinished()
365{ 356{
366 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file 357 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file
367 // to workaround an ipkg bug which stops reinstall to a different location 358 // to workaround an ipkg bug which stops reinstall to a different location
368 359
369 if ( !error && option == "remove" ) 360 if ( !error && option == "remove" )
370 removeStatusEntry(); 361 removeStatusEntry();
371 362
372 delete proc; 363 delete proc;
373 proc = 0; 364 proc = 0;
374 finished = true; 365 finished = true;
375 366
376 emit ipkgFinished(); 367 emit ipkgFinished();
377} 368}
378 369
379 370
380void Ipkg :: abort() 371void Ipkg :: abort()
381{ 372{
382 if ( proc ) 373 if ( proc )
383 { 374 {
384 proc->kill(); 375 proc->kill();
385 aborted = true; 376 aborted = true;
386 } 377 }
387} 378}
388 379
389void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) 380void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir )
390{ 381{
391 if ( dest == "root" || dest == "/" ) 382 if ( dest == "root" || dest == "/" )
392 return; 383 return;
393 384
394 qApp->processEvents(); 385 qApp->processEvents();
395 QStringList *fileList = getList( packFileName, destDir ); 386 QStringList *fileList = getList( packFileName, destDir );
396 qApp->processEvents(); 387 qApp->processEvents();
397 processFileList( fileList, destDir ); 388 processFileList( fileList, destDir );
398 delete fileList; 389 delete fileList;
399} 390}
400 391
401QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) 392QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir )
402{ 393{
403 QString packageFileDir = destDir; 394 QString packageFileDir = destDir;
404 packageFileDir.append( "/usr/lib/ipkg/info/" ); 395 packageFileDir.append( "/usr/lib/ipkg/info/" );
405 packageFileDir.append( packageFilename ); 396 packageFileDir.append( packageFilename );
406 packageFileDir.append( ".list" ); 397 packageFileDir.append( ".list" );
407 QFile f( packageFileDir ); 398 QFile f( packageFileDir );
408 399
409 if ( !f.open(IO_ReadOnly) ) 400 if ( !f.open(IO_ReadOnly) )
410 { 401 {
411 // Couldn't open from dest, try from / 402 // Couldn't open from dest, try from /
412 f.close(); 403 f.close();
413 404
414 packageFileDir = "/usr/lib/ipkg/info/"; 405 packageFileDir = "/usr/lib/ipkg/info/";
415 packageFileDir.append( packageFilename ); 406 packageFileDir.append( packageFilename );
416 packageFileDir.append( ".list" ); 407 packageFileDir.append( ".list" );
417 f.setName( packageFileDir ); 408 f.setName( packageFileDir );
418 if ( ! f.open(IO_ReadOnly) ) 409 if ( ! f.open(IO_ReadOnly) )
419 { 410 {
420 QString tempstr = tr("Could not open :"); 411 QString tempstr = tr("Could not open :");
421 tempstr.append( packageFileDir ); 412 tempstr.append( packageFileDir );
422 emit outputText( tempstr ); 413 emit outputText( tempstr );
423 return (QStringList*)0; 414 return (QStringList*)0;
424 } 415 }
425 } 416 }
426 QStringList *fileList = new QStringList(); 417 QStringList *fileList = new QStringList();
427 QTextStream t( &f ); 418 QTextStream t( &f );
428 while ( !t.eof() ) 419 while ( !t.eof() )
429 *fileList += t.readLine(); 420 *fileList += t.readLine();
430 421
431 f.close(); 422 f.close();
432 return fileList; 423 return fileList;
433} 424}
434 425
435void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) 426void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir )
436{ 427{
437 if ( !fileList || fileList->isEmpty() ) 428 if ( !fileList || fileList->isEmpty() )
438 return; 429 return;
439 430
440 QString baseDir = ROOT; 431 QString baseDir = ROOT;
441 432
442 if ( createLinks == true ) 433 if ( createLinks == true )
443 { 434 {
444 for ( uint i=0; i < fileList->count(); i++ ) 435 for ( uint i=0; i < fileList->count(); i++ )
445 { 436 {
446 processLinkDir( (*fileList)[i], baseDir, destDir ); 437 processLinkDir( (*fileList)[i], baseDir, destDir );
447 qApp->processEvents(); 438 qApp->processEvents();
448 } 439 }
449 } 440 }
450 else 441 else
451 { 442 {
452 for ( int i = fileList->count()-1; i >= 0 ; i-- ) 443 for ( int i = fileList->count()-1; i >= 0 ; i-- )
453 { 444 {
454 processLinkDir( (*fileList)[i], baseDir, destDir ); 445 processLinkDir( (*fileList)[i], baseDir, destDir );
455 qApp->processEvents(); 446 qApp->processEvents();
456 } 447 }
457 } 448 }
458} 449}
459 450
460void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) 451void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir )
461{ 452{
462 453
463 QString sourceFile = baseDir; 454 QString sourceFile = baseDir;
464 sourceFile.append( file ); 455 sourceFile.append( file );
465 456
466 QString linkFile = destDir; 457 QString linkFile = destDir;
467 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) 458 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" )
468 { 459 {
469 linkFile.append( file.mid( 1 ) ); 460 linkFile.append( file.mid( 1 ) );
470 } 461 }
471 else 462 else
472 { 463 {
473 linkFile.append( file ); 464 linkFile.append( file );
474 } 465 }
475 QString text; 466 QString text;
diff --git a/noncore/settings/aqpkg/utils.cpp b/noncore/settings/aqpkg/utils.cpp
index 00607dd..be02b3a 100644
--- a/noncore/settings/aqpkg/utils.cpp
+++ b/noncore/settings/aqpkg/utils.cpp
@@ -1,105 +1,104 @@
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 <stdio.h>
31#include <sys/vfs.h> 30#include <sys/vfs.h>
32 31
33#include "utils.h" 32#include "utils.h"
34#include "global.h" 33#include "global.h"
35 34
36Utils :: Utils() 35Utils :: Utils()
37{ 36{
38} 37}
39 38
40Utils :: ~Utils() 39Utils :: ~Utils()
41{ 40{
42} 41}
43 42
44QString Utils :: getPathfromIpkFilename( const QString &file ) 43QString Utils :: getPathfromIpkFilename( const QString &file )
45{ 44{
46 int p = file.findRev( "/" ); 45 int p = file.findRev( "/" );
47 QString path = ""; 46 QString path = "";
48 if ( p != -1 ) 47 if ( p != -1 )
49 path = file.left( p ); 48 path = file.left( p );
50 49
51 return path; 50 return path;
52 51
53} 52}
54 53
55QString Utils :: getFilenameFromIpkFilename( const QString &file ) 54QString Utils :: getFilenameFromIpkFilename( const QString &file )
56{ 55{
57 int p = file.findRev( "/" ); 56 int p = file.findRev( "/" );
58 QString name = file; 57 QString name = file;
59 if ( p != -1 ) 58 if ( p != -1 )
60 name = name.mid( p + 1 ); 59 name = name.mid( p + 1 );
61 60
62 61
63 return name; 62 return name;
64} 63}
65 64
66QString Utils :: getPackageNameFromIpkFilename( const QString &file ) 65QString Utils :: getPackageNameFromIpkFilename( const QString &file )
67{ 66{
68 int p = file.findRev( "/" ); 67 int p = file.findRev( "/" );
69 QString name = file; 68 QString name = file;
70 if ( p != -1 ) 69 if ( p != -1 )
71 name = name.mid( p + 1 ); 70 name = name.mid( p + 1 );
72 p = name.find( "_" ); 71 p = name.find( "_" );
73 QString packageName = name.mid( 0, p ); 72 QString packageName = name.mid( 0, p );
74 return packageName; 73 return packageName;
75} 74}
76 75
77QString Utils :: getPackageVersionFromIpkFilename( const QString &file ) 76QString Utils :: getPackageVersionFromIpkFilename( const QString &file )
78{ 77{
79 int p = file.findRev( "/" ); 78 int p = file.findRev( "/" );
80 QString name = file; 79 QString name = file;
81 if ( p != -1 ) 80 if ( p != -1 )
82 name = name.mid( p + 1 ); 81 name = name.mid( p + 1 );
83 p = name.find( "_" ) + 1; 82 p = name.find( "_" ) + 1;
84 int p2 = name.find( "_", p ); 83 int p2 = name.find( "_", p );
85 QString version = name.mid( p, p2 - p ); 84 QString version = name.mid( p, p2 - p );
86 return version; 85 return version;
87} 86}
88 87
89 88
90bool Utils :: getStorageSpace( const char *path, long *blockSize, long *totalBlocks, long *availBlocks ) 89bool Utils :: getStorageSpace( const char *path, long *blockSize, long *totalBlocks, long *availBlocks )
91{ 90{
92 bool ret = false; 91 bool ret = false;
93 92
94 struct statfs fs; 93 struct statfs fs;
95 if ( !statfs( path, &fs ) ) 94 if ( !statfs( path, &fs ) )
96 { 95 {
97 *blockSize = fs.f_bsize; 96 *blockSize = fs.f_bsize;
98 *totalBlocks = fs.f_blocks; 97 *totalBlocks = fs.f_blocks;
99 *availBlocks = fs.f_bavail; 98 *availBlocks = fs.f_bavail;
100 ret = true; 99 ret = true;
101 } 100 }
102 101
103 return ret; 102 return ret;
104} 103}
105 104