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