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