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