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