author | drw <drw> | 2003-02-25 00:39:29 (UTC) |
---|---|---|
committer | drw <drw> | 2003-02-25 00:39:29 (UTC) |
commit | 8d80ed4f9cf8051b5566aaf3f639c76fe7d6de7c (patch) (unidiff) | |
tree | 95ac0e3df097d1d2af81dbb543502b0682043fc0 | |
parent | 45fc2c7089de9bbb7887ba9bdb56c974b19c1caf (diff) | |
download | opie-8d80ed4f9cf8051b5566aaf3f639c76fe7d6de7c.zip opie-8d80ed4f9cf8051b5566aaf3f639c76fe7d6de7c.tar.gz opie-8d80ed4f9cf8051b5566aaf3f639c76fe7d6de7c.tar.bz2 |
Fix for bug #707 - remove package from status file only if package removal was successful.
-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 13 | ||||
-rw-r--r-- | noncore/settings/aqpkg/ipkg.h | 1 |
2 files changed, 8 insertions, 6 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp index 51eca8b..e66c02d 100644 --- a/noncore/settings/aqpkg/ipkg.cpp +++ b/noncore/settings/aqpkg/ipkg.cpp | |||
@@ -1,442 +1,443 @@ | |||
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 | proc = 0; |
43 | } | 43 | } |
44 | 44 | ||
45 | Ipkg :: ~Ipkg() | 45 | Ipkg :: ~Ipkg() |
46 | { | 46 | { |
47 | } | 47 | } |
48 | 48 | ||
49 | // 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 |
50 | // 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 |
51 | // 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) |
52 | // 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 |
53 | // package parameter) | 53 | // package parameter) |
54 | // dest is the destination alias (from ipk.conf) | 54 | // dest is the destination alias (from ipk.conf) |
55 | // 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) |
56 | // flags is the ipkg options flags | 56 | // flags is the ipkg options flags |
57 | // dir is the directory to run ipkg in (defaults to "") | 57 | // dir is the directory to run ipkg in (defaults to "") |
58 | bool Ipkg :: runIpkg( ) | 58 | bool Ipkg :: runIpkg( ) |
59 | { | 59 | { |
60 | error = false; | ||
60 | bool ret = false; | 61 | bool ret = false; |
61 | QStringList commands; | 62 | QStringList commands; |
62 | 63 | ||
63 | QDir::setCurrent( "/tmp" ); | 64 | QDir::setCurrent( "/tmp" ); |
64 | 65 | ||
65 | if ( runtimeDir != "" ) | 66 | if ( runtimeDir != "" ) |
66 | { | 67 | { |
67 | commands << "cd "; | 68 | commands << "cd "; |
68 | commands << runtimeDir; | 69 | commands << runtimeDir; |
69 | commands << ";"; | 70 | commands << ";"; |
70 | } | 71 | } |
71 | commands << "ipkg" << "-force-defaults"; | 72 | commands << "ipkg" << "-force-defaults"; |
72 | 73 | ||
73 | // only set the destination for an install operation | 74 | // only set the destination for an install operation |
74 | if ( option == "install" ) | 75 | if ( option == "install" ) |
75 | commands << "-dest" << destination; | 76 | commands << "-dest" << destination; |
76 | 77 | ||
77 | 78 | ||
78 | if ( option != "update" && option != "download" ) | 79 | if ( option != "update" && option != "download" ) |
79 | { | 80 | { |
80 | if ( flags & FORCE_DEPENDS ) | 81 | if ( flags & FORCE_DEPENDS ) |
81 | commands << "-force-depends"; | 82 | commands << "-force-depends"; |
82 | if ( flags & FORCE_REINSTALL ) | 83 | if ( flags & FORCE_REINSTALL ) |
83 | commands << "-force-reinstall"; | 84 | commands << "-force-reinstall"; |
84 | if ( flags & FORCE_REMOVE ) | 85 | if ( flags & FORCE_REMOVE ) |
85 | commands << "-force-removal-of-essential-packages"; | 86 | commands << "-force-removal-of-essential-packages"; |
86 | if ( flags & FORCE_OVERWRITE ) | 87 | if ( flags & FORCE_OVERWRITE ) |
87 | commands << "-force-overwrite"; | 88 | commands << "-force-overwrite"; |
88 | if ( flags & VERBOSE_WGET ) | 89 | if ( flags & VERBOSE_WGET ) |
89 | commands << "-verbose_wget"; | 90 | commands << "-verbose_wget"; |
90 | 91 | ||
91 | // Handle make links | 92 | // Handle make links |
92 | // Rules - If make links is switched on, create links to root | 93 | // Rules - If make links is switched on, create links to root |
93 | // if destDir is NOT / | 94 | // if destDir is NOT / |
94 | if ( flags & MAKE_LINKS ) | 95 | if ( flags & MAKE_LINKS ) |
95 | { | 96 | { |
96 | // If destDir == / turn off make links as package is being insalled | 97 | // If destDir == / turn off make links as package is being insalled |
97 | // to root already. | 98 | // to root already. |
98 | if ( destDir == "/" ) | 99 | if ( destDir == "/" ) |
99 | flags ^= MAKE_LINKS; | 100 | flags ^= MAKE_LINKS; |
100 | } | 101 | } |
101 | } | 102 | } |
102 | 103 | ||
103 | #ifdef X86 | 104 | #ifdef X86 |
104 | commands << "-f"; | 105 | commands << "-f"; |
105 | commands << IPKG_CONF; | 106 | commands << IPKG_CONF; |
106 | #endif | 107 | #endif |
107 | 108 | ||
108 | 109 | ||
109 | if ( option == "reinstall" ) | 110 | if ( option == "reinstall" ) |
110 | commands << "install"; | 111 | commands << "install"; |
111 | else | 112 | else |
112 | commands << option; | 113 | commands << option; |
113 | if ( package != "" ) | 114 | if ( package != "" ) |
114 | commands << package; | 115 | commands << package; |
115 | 116 | ||
116 | 117 | ||
117 | if ( package != "" ) | 118 | if ( package != "" ) |
118 | emit outputText( QString( "Dealing with package " ) + package ); | 119 | emit outputText( QString( "Dealing with package " ) + package ); |
119 | 120 | ||
120 | qApp->processEvents(); | 121 | qApp->processEvents(); |
121 | 122 | ||
122 | // If we are removing, reinstalling or upgrading packages and make links option is selected | 123 | // If we are removing, reinstalling or upgrading packages and make links option is selected |
123 | // create the links | 124 | // create the links |
124 | if ( option == "remove" || option == "reinstall" || option == "upgrade" ) | 125 | if ( option == "remove" || option == "reinstall" || option == "upgrade" ) |
125 | { | 126 | { |
126 | createLinks = false; | 127 | createLinks = false; |
127 | if ( flags & MAKE_LINKS ) | 128 | if ( flags & MAKE_LINKS ) |
128 | { | 129 | { |
129 | emit outputText( QString( "Removing symbolic links...\n" ) ); | 130 | emit outputText( QString( "Removing symbolic links...\n" ) ); |
130 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 131 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
131 | emit outputText( QString( " " ) ); | 132 | emit outputText( QString( " " ) ); |
132 | } | 133 | } |
133 | } | 134 | } |
134 | 135 | ||
135 | // Execute command | 136 | // Execute command |
136 | dependantPackages = new QList<QString>; | 137 | dependantPackages = new QList<QString>; |
137 | dependantPackages->setAutoDelete( true ); | 138 | dependantPackages->setAutoDelete( true ); |
138 | 139 | ||
139 | ret = executeIpkgCommand( commands, option ); | 140 | ret = executeIpkgCommand( commands, option ); |
140 | 141 | ||
141 | if ( aborted ) | 142 | if ( aborted ) |
142 | return false; | 143 | return false; |
143 | 144 | ||
144 | if ( option == "install" || option == "reinstall" || option == "upgrade" ) | 145 | if ( option == "install" || option == "reinstall" || option == "upgrade" ) |
145 | { | 146 | { |
146 | // If we are not removing packages and make links option is selected | 147 | // If we are not removing packages and make links option is selected |
147 | // create the links | 148 | // create the links |
148 | createLinks = true; | 149 | createLinks = true; |
149 | if ( flags & MAKE_LINKS ) | 150 | if ( flags & MAKE_LINKS ) |
150 | { | 151 | { |
151 | emit outputText( " " ); | 152 | emit outputText( " " ); |
152 | emit outputText( QString( "Creating symbolic links for " )+ package ); | 153 | emit outputText( QString( "Creating symbolic links for " )+ package ); |
153 | 154 | ||
154 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 155 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
155 | 156 | ||
156 | // link dependant packages that were installed with this release | 157 | // link dependant packages that were installed with this release |
157 | QString *pkg; | 158 | QString *pkg; |
158 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) | 159 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) |
159 | { | 160 | { |
160 | if ( *pkg == package ) | 161 | if ( *pkg == package ) |
161 | continue; | 162 | continue; |
162 | emit outputText( " " ); | 163 | emit outputText( " " ); |
163 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); | 164 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); |
164 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); | 165 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); |
165 | } | 166 | } |
166 | } | 167 | } |
167 | } | 168 | } |
168 | 169 | ||
169 | delete dependantPackages; | 170 | delete dependantPackages; |
170 | 171 | ||
171 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file | ||
172 | // to workaround an ipkg bug which stops reinstall to a different location | ||
173 | if ( option == "remove" ) | ||
174 | removeStatusEntry(); | ||
175 | |||
176 | |||
177 | emit outputText( "Finished" ); | 172 | emit outputText( "Finished" ); |
178 | emit outputText( "" ); | 173 | emit outputText( "" ); |
179 | return ret; | 174 | return ret; |
180 | 175 | ||
181 | } | 176 | } |
182 | 177 | ||
183 | void Ipkg :: removeStatusEntry() | 178 | void Ipkg :: removeStatusEntry() |
184 | { | 179 | { |
185 | QString statusFile = destDir; | 180 | QString statusFile = destDir; |
186 | if ( statusFile.right( 1 ) != "/" ) | 181 | if ( statusFile.right( 1 ) != "/" ) |
187 | statusFile += "/"; | 182 | statusFile += "/"; |
188 | statusFile += "usr/lib/ipkg/status"; | 183 | statusFile += "usr/lib/ipkg/status"; |
189 | QString outStatusFile = statusFile + ".tmp"; | 184 | QString outStatusFile = statusFile + ".tmp"; |
190 | 185 | ||
191 | emit outputText( "" ); | 186 | emit outputText( "" ); |
192 | emit outputText( "Removing status entry..." ); | 187 | emit outputText( "Removing status entry..." ); |
193 | emit outputText( QString( "status file - " )+ statusFile ); | 188 | emit outputText( QString( "status file - " )+ statusFile ); |
194 | emit outputText( QString( "package - " )+ package ); | 189 | emit outputText( QString( "package - " )+ package ); |
195 | 190 | ||
196 | ifstream in( statusFile ); | 191 | ifstream in( statusFile ); |
197 | ofstream out( outStatusFile ); | 192 | ofstream out( outStatusFile ); |
198 | if ( !in.is_open() ) | 193 | if ( !in.is_open() ) |
199 | { | 194 | { |
200 | emit outputText( QString( "Couldn't open status file - " )+ statusFile ); | 195 | emit outputText( QString( "Couldn't open status file - " )+ statusFile ); |
201 | return; | 196 | return; |
202 | } | 197 | } |
203 | 198 | ||
204 | if ( !out.is_open() ) | 199 | if ( !out.is_open() ) |
205 | { | 200 | { |
206 | emit outputText( QString( "Couldn't create tempory status file - " )+ outStatusFile ); | 201 | emit outputText( QString( "Couldn't create tempory status file - " )+ outStatusFile ); |
207 | return; | 202 | return; |
208 | } | 203 | } |
209 | 204 | ||
210 | char line[1001]; | 205 | char line[1001]; |
211 | char k[21]; | 206 | char k[21]; |
212 | char v[1001]; | 207 | char v[1001]; |
213 | QString key; | 208 | QString key; |
214 | QString value; | 209 | QString value; |
215 | vector<QString> lines; | 210 | vector<QString> lines; |
216 | do | 211 | do |
217 | { | 212 | { |
218 | in.getline( line, 1000 ); | 213 | in.getline( line, 1000 ); |
219 | if ( in.eof() ) | 214 | if ( in.eof() ) |
220 | continue; | 215 | continue; |
221 | 216 | ||
222 | k[0] = '\0'; | 217 | k[0] = '\0'; |
223 | v[0] = '\0'; | 218 | v[0] = '\0'; |
224 | 219 | ||
225 | sscanf( line, "%[^:]: %[^\n]", k, v ); | 220 | sscanf( line, "%[^:]: %[^\n]", k, v ); |
226 | key = k; | 221 | key = k; |
227 | value = v; | 222 | value = v; |
228 | key = key.stripWhiteSpace(); | 223 | key = key.stripWhiteSpace(); |
229 | value = value.stripWhiteSpace(); | 224 | value = value.stripWhiteSpace(); |
230 | if ( key == "Package" && value == package ) | 225 | if ( key == "Package" && value == package ) |
231 | { | 226 | { |
232 | // Ignore all lines up to next empty | 227 | // Ignore all lines up to next empty |
233 | do | 228 | do |
234 | { | 229 | { |
235 | in.getline( line, 1000 ); | 230 | in.getline( line, 1000 ); |
236 | if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) | 231 | if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) |
237 | continue; | 232 | continue; |
238 | } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); | 233 | } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); |
239 | } | 234 | } |
240 | 235 | ||
241 | lines.push_back( QString( line ) ); | 236 | lines.push_back( QString( line ) ); |
242 | // out << line << endl; | 237 | // out << line << endl; |
243 | } while ( !in.eof() ); | 238 | } while ( !in.eof() ); |
244 | 239 | ||
245 | // Write lines out | 240 | // Write lines out |
246 | vector<QString>::iterator it; | 241 | vector<QString>::iterator it; |
247 | for ( it = lines.begin() ; it != lines.end() ; ++it ) | 242 | for ( it = lines.begin() ; it != lines.end() ; ++it ) |
248 | { | 243 | { |
249 | cout << "Writing " << (const char *)(*it) << endl; | 244 | cout << "Writing " << (const char *)(*it) << endl; |
250 | out << (const char *)(*it) << endl; | 245 | out << (const char *)(*it) << endl; |
251 | } | 246 | } |
252 | 247 | ||
253 | in.close(); | 248 | in.close(); |
254 | out.close(); | 249 | out.close(); |
255 | 250 | ||
256 | // Remove old status file and put tmp stats file in its place | 251 | // Remove old status file and put tmp stats file in its place |
257 | remove( statusFile ); | 252 | remove( statusFile ); |
258 | rename( outStatusFile, statusFile ); | 253 | rename( outStatusFile, statusFile ); |
259 | } | 254 | } |
260 | 255 | ||
261 | int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString option ) | 256 | int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString option ) |
262 | { | 257 | { |
263 | // If one is already running - should never be but just to be safe | 258 | // If one is already running - should never be but just to be safe |
264 | if ( proc ) | 259 | if ( proc ) |
265 | { | 260 | { |
266 | delete proc; | 261 | delete proc; |
267 | proc = 0; | 262 | proc = 0; |
268 | } | 263 | } |
269 | 264 | ||
270 | // OK we're gonna use OProcess to run this thing | 265 | // OK we're gonna use OProcess to run this thing |
271 | proc = new OProcess(); | 266 | proc = new OProcess(); |
272 | aborted = false; | 267 | aborted = false; |
273 | 268 | ||
274 | 269 | ||
275 | // Connect up our slots | 270 | // Connect up our slots |
276 | connect(proc, SIGNAL(processExited(OProcess *)), | 271 | connect(proc, SIGNAL(processExited(OProcess *)), |
277 | this, SLOT( processFinished())); | 272 | this, SLOT( processFinished())); |
278 | 273 | ||
279 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), | 274 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), |
280 | this, SLOT(commandStdout(OProcess *, char *, int))); | 275 | this, SLOT(commandStdout(OProcess *, char *, int))); |
281 | 276 | ||
282 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), | 277 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), |
283 | this, SLOT(commandStderr(OProcess *, char *, int))); | 278 | this, SLOT(commandStderr(OProcess *, char *, int))); |
284 | 279 | ||
285 | for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) | 280 | for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) |
286 | { | 281 | { |
287 | qDebug( "%s ", (*it).latin1() ); | 282 | qDebug( "%s ", (*it).latin1() ); |
288 | *proc << (*it).latin1(); | 283 | *proc << (*it).latin1(); |
289 | } | 284 | } |
290 | cout << endl; | 285 | cout << endl; |
291 | 286 | ||
292 | // Start the process going | 287 | // Start the process going |
293 | finished = false; | 288 | finished = false; |
294 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) | 289 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) |
295 | { | 290 | { |
296 | emit outputText( QString( "Couldn't start ipkg process" ) ); | 291 | emit outputText( QString( "Couldn't start ipkg process" ) ); |
297 | qDebug( "Couldn't start ipkg process!" ); | 292 | qDebug( "Couldn't start ipkg process!" ); |
298 | } | 293 | } |
299 | 294 | ||
300 | // Now wait for it to finish | 295 | // Now wait for it to finish |
301 | while ( !finished ) | 296 | while ( !finished ) |
302 | qApp->processEvents(); | 297 | qApp->processEvents(); |
303 | } | 298 | } |
304 | 299 | ||
305 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) | 300 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) |
306 | { | 301 | { |
307 | qDebug("received stdout %d bytes", buflen); | 302 | qDebug("received stdout %d bytes", buflen); |
308 | 303 | ||
309 | QString lineStr = buffer; | 304 | QString lineStr = buffer; |
310 | if ( lineStr[buflen-1] == '\n' ) | 305 | if ( lineStr[buflen-1] == '\n' ) |
311 | buflen --; | 306 | buflen --; |
312 | lineStr = lineStr.left( buflen ); | 307 | lineStr = lineStr.left( buflen ); |
313 | emit outputText( lineStr ); | 308 | emit outputText( lineStr ); |
314 | 309 | ||
315 | // check if we are installing dependant packages | 310 | // check if we are installing dependant packages |
316 | if ( option == "install" || option == "reinstall" ) | 311 | if ( option == "install" || option == "reinstall" ) |
317 | { | 312 | { |
318 | // Need to keep track of any dependant packages that get installed | 313 | // Need to keep track of any dependant packages that get installed |
319 | // so that we can create links to them as necessary | 314 | // so that we can create links to them as necessary |
320 | if ( lineStr.startsWith( "Installing " ) ) | 315 | if ( lineStr.startsWith( "Installing " ) ) |
321 | { | 316 | { |
322 | int start = lineStr.find( " " ) + 1; | 317 | int start = lineStr.find( " " ) + 1; |
323 | int end = lineStr.find( " ", start ); | 318 | int end = lineStr.find( " ", start ); |
324 | QString *package = new QString( lineStr.mid( start, end-start ) ); | 319 | QString *package = new QString( lineStr.mid( start, end-start ) ); |
325 | dependantPackages->append( package ); | 320 | dependantPackages->append( package ); |
326 | } | 321 | } |
327 | } | 322 | } |
328 | 323 | ||
329 | qDebug(lineStr); | 324 | qDebug(lineStr); |
330 | buffer[0] = '\0'; | 325 | buffer[0] = '\0'; |
331 | } | 326 | } |
332 | 327 | ||
333 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) | 328 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) |
334 | { | 329 | { |
335 | qDebug("received stderrt %d bytes", buflen); | 330 | qDebug("received stderrt %d bytes", buflen); |
336 | 331 | ||
337 | QString lineStr = buffer; | 332 | QString lineStr = buffer; |
338 | if ( lineStr[buflen-1] == '\n' ) | 333 | if ( lineStr[buflen-1] == '\n' ) |
339 | buflen --; | 334 | buflen --; |
340 | lineStr=lineStr.left( buflen ); | 335 | lineStr=lineStr.left( buflen ); |
341 | emit outputText( lineStr ); | 336 | emit outputText( lineStr ); |
342 | buffer[0] = '\0'; | 337 | buffer[0] = '\0'; |
338 | error = true; | ||
343 | } | 339 | } |
344 | 340 | ||
345 | void Ipkg::processFinished() | 341 | void Ipkg::processFinished() |
346 | { | 342 | { |
343 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file | ||
344 | // to workaround an ipkg bug which stops reinstall to a different location | ||
345 | if ( !error && option == "remove" ) | ||
346 | removeStatusEntry(); | ||
347 | |||
347 | delete proc; | 348 | delete proc; |
348 | proc = 0; | 349 | proc = 0; |
349 | finished = true; | 350 | finished = true; |
350 | } | 351 | } |
351 | 352 | ||
352 | 353 | ||
353 | void Ipkg :: abort() | 354 | void Ipkg :: abort() |
354 | { | 355 | { |
355 | if ( proc ) | 356 | if ( proc ) |
356 | { | 357 | { |
357 | proc->kill(); | 358 | proc->kill(); |
358 | aborted = true; | 359 | aborted = true; |
359 | } | 360 | } |
360 | } | 361 | } |
361 | 362 | ||
362 | /* | 363 | /* |
363 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) | 364 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) |
364 | { | 365 | { |
365 | FILE *fp = NULL; | 366 | FILE *fp = NULL; |
366 | char line[130]; | 367 | char line[130]; |
367 | QString lineStr, lineStrOld; | 368 | QString lineStr, lineStrOld; |
368 | int ret = false; | 369 | int ret = false; |
369 | 370 | ||
370 | fp = popen( (const char *) cmd, "r"); | 371 | fp = popen( (const char *) cmd, "r"); |
371 | if ( fp == NULL ) | 372 | if ( fp == NULL ) |
372 | { | 373 | { |
373 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; | 374 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; |
374 | QString text; | 375 | QString text; |
375 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); | 376 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); |
376 | emit outputText( text ); | 377 | emit outputText( text ); |
377 | } | 378 | } |
378 | else | 379 | else |
379 | { | 380 | { |
380 | while ( fgets( line, sizeof line, fp) != NULL ) | 381 | while ( fgets( line, sizeof line, fp) != NULL ) |
381 | { | 382 | { |
382 | lineStr = line; | 383 | lineStr = line; |
383 | lineStr=lineStr.left( lineStr.length()-1 ); | 384 | lineStr=lineStr.left( lineStr.length()-1 ); |
384 | 385 | ||
385 | if ( lineStr != lineStrOld ) | 386 | if ( lineStr != lineStrOld ) |
386 | { | 387 | { |
387 | //See if we're finished | 388 | //See if we're finished |
388 | if ( option == "install" || option == "reinstall" ) | 389 | if ( option == "install" || option == "reinstall" ) |
389 | { | 390 | { |
390 | // Need to keep track of any dependant packages that get installed | 391 | // Need to keep track of any dependant packages that get installed |
391 | // so that we can create links to them as necessary | 392 | // so that we can create links to them as necessary |
392 | if ( lineStr.startsWith( "Installing " ) ) | 393 | if ( lineStr.startsWith( "Installing " ) ) |
393 | { | 394 | { |
394 | int start = lineStr.find( " " ) + 1; | 395 | int start = lineStr.find( " " ) + 1; |
395 | int end = lineStr.find( " ", start ); | 396 | int end = lineStr.find( " ", start ); |
396 | QString *package = new QString( lineStr.mid( start, end-start ) ); | 397 | QString *package = new QString( lineStr.mid( start, end-start ) ); |
397 | dependantPackages->append( package ); | 398 | dependantPackages->append( package ); |
398 | } | 399 | } |
399 | } | 400 | } |
400 | 401 | ||
401 | if ( option == "update" ) | 402 | if ( option == "update" ) |
402 | { | 403 | { |
403 | if (lineStr.contains("Updated list")) | 404 | if (lineStr.contains("Updated list")) |
404 | ret = true; | 405 | ret = true; |
405 | } | 406 | } |
406 | else if ( option == "download" ) | 407 | else if ( option == "download" ) |
407 | { | 408 | { |
408 | if (lineStr.contains("Downloaded")) | 409 | if (lineStr.contains("Downloaded")) |
409 | ret = true; | 410 | ret = true; |
410 | } | 411 | } |
411 | else | 412 | else |
412 | { | 413 | { |
413 | if (lineStr.contains("Done")) | 414 | if (lineStr.contains("Done")) |
414 | ret = true; | 415 | ret = true; |
415 | } | 416 | } |
416 | 417 | ||
417 | emit outputText( lineStr ); | 418 | emit outputText( lineStr ); |
418 | } | 419 | } |
419 | lineStrOld = lineStr; | 420 | lineStrOld = lineStr; |
420 | qApp->processEvents(); | 421 | qApp->processEvents(); |
421 | } | 422 | } |
422 | pclose(fp); | 423 | pclose(fp); |
423 | } | 424 | } |
424 | 425 | ||
425 | return ret; | 426 | return ret; |
426 | } | 427 | } |
427 | */ | 428 | */ |
428 | 429 | ||
429 | void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) | 430 | void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) |
430 | { | 431 | { |
431 | if ( dest == "root" || dest == "/" ) | 432 | if ( dest == "root" || dest == "/" ) |
432 | return; | 433 | return; |
433 | 434 | ||
434 | qApp->processEvents(); | 435 | qApp->processEvents(); |
435 | QStringList *fileList = getList( packFileName, destDir ); | 436 | QStringList *fileList = getList( packFileName, destDir ); |
436 | qApp->processEvents(); | 437 | qApp->processEvents(); |
437 | processFileList( fileList, destDir ); | 438 | processFileList( fileList, destDir ); |
438 | delete fileList; | 439 | delete fileList; |
439 | } | 440 | } |
440 | 441 | ||
441 | QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) | 442 | QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) |
442 | { | 443 | { |
diff --git a/noncore/settings/aqpkg/ipkg.h b/noncore/settings/aqpkg/ipkg.h index f08667b..d49bb04 100644 --- a/noncore/settings/aqpkg/ipkg.h +++ b/noncore/settings/aqpkg/ipkg.h | |||
@@ -1,88 +1,89 @@ | |||
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 | void abort(); |
63 | 63 | ||
64 | 64 | ||
65 | private: | 65 | private: |
66 | bool createLinks; | 66 | bool createLinks; |
67 | bool aborted; | 67 | bool aborted; |
68 | bool error; | ||
68 | QString option; | 69 | QString option; |
69 | QString package; | 70 | QString package; |
70 | QString destination; | 71 | QString destination; |
71 | QString destDir; | 72 | QString destDir; |
72 | QString runtimeDir; | 73 | QString runtimeDir; |
73 | OProcess *proc; | 74 | OProcess *proc; |
74 | int flags; | 75 | int flags; |
75 | bool finished; | 76 | bool finished; |
76 | 77 | ||
77 | QList<QString> *dependantPackages; | 78 | QList<QString> *dependantPackages; |
78 | 79 | ||
79 | int executeIpkgCommand( QStringList &cmd, const QString option ); | 80 | int executeIpkgCommand( QStringList &cmd, const QString option ); |
80 | void removeStatusEntry(); | 81 | void removeStatusEntry(); |
81 | void linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ); | 82 | void linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ); |
82 | QStringList* getList( const QString &packageFilename, const QString &destDir ); | 83 | QStringList* getList( const QString &packageFilename, const QString &destDir ); |
83 | void processFileList( const QStringList *fileList, const QString &destDir ); | 84 | void processFileList( const QStringList *fileList, const QString &destDir ); |
84 | void processLinkDir( const QString &file, const QString &baseDir, const QString &destDir ); | 85 | void processLinkDir( const QString &file, const QString &baseDir, const QString &destDir ); |
85 | 86 | ||
86 | }; | 87 | }; |
87 | 88 | ||
88 | #endif | 89 | #endif |