Diffstat (limited to 'noncore/settings/aqpkg/ipkg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp index e906653..34999ad 100644 --- a/noncore/settings/aqpkg/ipkg.cpp +++ b/noncore/settings/aqpkg/ipkg.cpp | |||
@@ -34,52 +34,51 @@ using namespace std; | |||
34 | #include <opie/oprocess.h> | 34 | #include <opie/oprocess.h> |
35 | 35 | ||
36 | #include "utils.h" | 36 | #include "utils.h" |
37 | #include "ipkg.h" | 37 | #include "ipkg.h" |
38 | #include "global.h" | 38 | #include "global.h" |
39 | 39 | ||
40 | Ipkg :: Ipkg() | 40 | Ipkg :: Ipkg() |
41 | { | 41 | { |
42 | proc = 0; | 42 | proc = 0; |
43 | } | 43 | } |
44 | 44 | ||
45 | Ipkg :: ~Ipkg() | 45 | Ipkg :: ~Ipkg() |
46 | { | 46 | { |
47 | } | 47 | } |
48 | 48 | ||
49 | // Option is what we are going to do - install, upgrade, download, reinstall | 49 | // Option is what we are going to do - install, upgrade, download, reinstall |
50 | // package is the package name to install - either a fully qualified path and ipk | 50 | // package is the package name to install - either a fully qualified path and ipk |
51 | // file (if stored locally) or just the name of the package (for a network package) | 51 | // file (if stored locally) or just the name of the package (for a network package) |
52 | // packageName is the package name - (for a network package this will be the same as | 52 | // packageName is the package name - (for a network package this will be the same as |
53 | // package parameter) | 53 | // package parameter) |
54 | // dest is the destination alias (from ipk.conf) | 54 | // dest is the destination alias (from ipk.conf) |
55 | // destDir is the dir that the destination alias points to (used to link to root) | 55 | // destDir is the dir that the destination alias points to (used to link to root) |
56 | // flags is the ipkg options flags | 56 | // flags is the ipkg options flags |
57 | // dir is the directory to run ipkg in (defaults to "") | 57 | // dir is the directory to run ipkg in (defaults to "") |
58 | bool Ipkg :: runIpkg( ) | 58 | void Ipkg :: runIpkg() |
59 | { | 59 | { |
60 | error = false; | 60 | error = false; |
61 | bool ret = false; | ||
62 | QStringList commands; | 61 | QStringList commands; |
63 | 62 | ||
64 | QDir::setCurrent( "/tmp" ); | 63 | QDir::setCurrent( "/tmp" ); |
65 | 64 | ||
66 | if ( runtimeDir != "" ) | 65 | if ( runtimeDir != "" ) |
67 | { | 66 | { |
68 | commands << "cd "; | 67 | commands << "cd "; |
69 | commands << runtimeDir; | 68 | commands << runtimeDir; |
70 | commands << ";"; | 69 | commands << ";"; |
71 | } | 70 | } |
72 | commands << "ipkg" << "-V" << QString::number( infoLevel ) << "-force-defaults"; | 71 | commands << "ipkg" << "-V" << QString::number( infoLevel ) << "-force-defaults"; |
73 | 72 | ||
74 | // only set the destination for an install operation | 73 | // only set the destination for an install operation |
75 | if ( option == "install" ) | 74 | if ( option == "install" ) |
76 | commands << "-dest" << destination; | 75 | commands << "-dest" << destination; |
77 | 76 | ||
78 | 77 | ||
79 | if ( option != "update" && option != "download" ) | 78 | if ( option != "update" && option != "download" ) |
80 | { | 79 | { |
81 | if ( flags & FORCE_DEPENDS ) | 80 | if ( flags & FORCE_DEPENDS ) |
82 | commands << "-force-depends"; | 81 | commands << "-force-depends"; |
83 | if ( flags & FORCE_REINSTALL ) | 82 | if ( flags & FORCE_REINSTALL ) |
84 | commands << "-force-reinstall"; | 83 | commands << "-force-reinstall"; |
85 | if ( flags & FORCE_REMOVE ) | 84 | if ( flags & FORCE_REMOVE ) |
@@ -116,83 +115,83 @@ bool Ipkg :: runIpkg( ) | |||
116 | 115 | ||
117 | 116 | ||
118 | if ( package != "" ) | 117 | if ( package != "" ) |
119 | emit outputText( QString( "Dealing with package " ) + package ); | 118 | emit outputText( QString( "Dealing with package " ) + package ); |
120 | 119 | ||
121 | qApp->processEvents(); | 120 | qApp->processEvents(); |
122 | 121 | ||
123 | // If we are removing, reinstalling or upgrading packages and make links option is selected | 122 | // If we are removing, reinstalling or upgrading packages and make links option is selected |
124 | // create the links | 123 | // create the links |
125 | if ( option == "remove" || option == "reinstall" || option == "upgrade" ) | 124 | if ( option == "remove" || option == "reinstall" || option == "upgrade" ) |
126 | { | 125 | { |
127 | createLinks = false; | 126 | createLinks = false; |
128 | if ( flags & MAKE_LINKS ) | 127 | if ( flags & MAKE_LINKS ) |
129 | { | 128 | { |
130 | emit outputText( QString( "Removing symbolic links...\n" ) ); | 129 | emit outputText( QString( "Removing symbolic links...\n" ) ); |
131 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 130 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
132 | emit outputText( QString( " " ) ); | 131 | emit outputText( QString( " " ) ); |
133 | } | 132 | } |
134 | } | 133 | } |
135 | 134 | ||
136 | // Execute command | 135 | // Execute command |
137 | dependantPackages = new QList<QString>; | 136 | dependantPackages = new QList<QString>; |
138 | dependantPackages->setAutoDelete( true ); | 137 | dependantPackages->setAutoDelete( true ); |
139 | 138 | ||
140 | ret = executeIpkgCommand( commands, option ); | 139 | executeIpkgCommand( commands, option ); |
141 | 140 | ||
142 | if ( aborted ) | 141 | } |
143 | return false; | ||
144 | 142 | ||
143 | void Ipkg :: createSymLinks() | ||
144 | { | ||
145 | if ( option == "install" || option == "reinstall" || option == "upgrade" ) | 145 | if ( option == "install" || option == "reinstall" || option == "upgrade" ) |
146 | { | 146 | { |
147 | // If we are not removing packages and make links option is selected | 147 | // If we are not removing packages and make links option is selected |
148 | // create the links | 148 | // create the links |
149 | createLinks = true; | 149 | createLinks = true; |
150 | if ( flags & MAKE_LINKS ) | 150 | if ( flags & MAKE_LINKS ) |
151 | { | 151 | { |
152 | emit outputText( " " ); | 152 | emit outputText( " " ); |
153 | emit outputText( QString( "Creating symbolic links for " )+ package ); | 153 | emit outputText( QString( "Creating symbolic links for " )+ package ); |
154 | 154 | ||
155 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 155 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
156 | 156 | ||
157 | // link dependant packages that were installed with this release | 157 | // link dependant packages that were installed with this release |
158 | QString *pkg; | 158 | QString *pkg; |
159 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) | 159 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) |
160 | { | 160 | { |
161 | if ( *pkg == package ) | 161 | if ( *pkg == package ) |
162 | continue; | 162 | continue; |
163 | emit outputText( " " ); | 163 | emit outputText( " " ); |
164 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); | 164 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); |
165 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); | 165 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); |
166 | } | 166 | } |
167 | } | 167 | } |
168 | } | 168 | } |
169 | 169 | ||
170 | delete dependantPackages; | 170 | delete dependantPackages; |
171 | 171 | ||
172 | emit outputText( "Finished" ); | 172 | emit outputText( "Finished" ); |
173 | emit outputText( "" ); | 173 | emit outputText( "" ); |
174 | return ret; | ||
175 | } | 174 | } |
176 | 175 | ||
177 | void Ipkg :: removeStatusEntry() | 176 | void Ipkg :: removeStatusEntry() |
178 | { | 177 | { |
179 | QString statusFile = destDir; | 178 | QString statusFile = destDir; |
180 | if ( statusFile.right( 1 ) != "/" ) | 179 | if ( statusFile.right( 1 ) != "/" ) |
181 | statusFile.append( "/" ); | 180 | statusFile.append( "/" ); |
182 | statusFile.append( "usr/lib/ipkg/status" ); | 181 | statusFile.append( "usr/lib/ipkg/status" ); |
183 | QString outStatusFile = statusFile; | 182 | QString outStatusFile = statusFile; |
184 | outStatusFile.append( ".tmp" ); | 183 | outStatusFile.append( ".tmp" ); |
185 | 184 | ||
186 | emit outputText( "" ); | 185 | emit outputText( "" ); |
187 | emit outputText( "Removing status entry..." ); | 186 | emit outputText( "Removing status entry..." ); |
188 | QString tempstr = "status file - "; | 187 | QString tempstr = "status file - "; |
189 | tempstr.append( statusFile ); | 188 | tempstr.append( statusFile ); |
190 | emit outputText( tempstr ); | 189 | emit outputText( tempstr ); |
191 | tempstr = "package - "; | 190 | tempstr = "package - "; |
192 | tempstr.append( package ); | 191 | tempstr.append( package ); |
193 | emit outputText( tempstr ); | 192 | emit outputText( tempstr ); |
194 | 193 | ||
195 | ifstream in( statusFile ); | 194 | ifstream in( statusFile ); |
196 | ofstream out( outStatusFile ); | 195 | ofstream out( outStatusFile ); |
197 | if ( !in.is_open() ) | 196 | if ( !in.is_open() ) |
198 | { | 197 | { |
@@ -274,52 +273,48 @@ int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ ) | |||
274 | aborted = false; | 273 | aborted = false; |
275 | 274 | ||
276 | 275 | ||
277 | // Connect up our slots | 276 | // Connect up our slots |
278 | connect(proc, SIGNAL(processExited(OProcess *)), | 277 | connect(proc, SIGNAL(processExited(OProcess *)), |
279 | this, SLOT( processFinished())); | 278 | this, SLOT( processFinished())); |
280 | 279 | ||
281 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), | 280 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), |
282 | this, SLOT(commandStdout(OProcess *, char *, int))); | 281 | this, SLOT(commandStdout(OProcess *, char *, int))); |
283 | 282 | ||
284 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), | 283 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), |
285 | this, SLOT(commandStderr(OProcess *, char *, int))); | 284 | this, SLOT(commandStderr(OProcess *, char *, int))); |
286 | 285 | ||
287 | for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) | 286 | for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) |
288 | { | 287 | { |
289 | *proc << (*it).latin1(); | 288 | *proc << (*it).latin1(); |
290 | } | 289 | } |
291 | 290 | ||
292 | // Start the process going | 291 | // Start the process going |
293 | finished = false; | 292 | finished = false; |
294 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) | 293 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) |
295 | { | 294 | { |
296 | emit outputText( QString( "Couldn't start ipkg process" ) ); | 295 | emit outputText( QString( "Couldn't start ipkg process" ) ); |
297 | } | 296 | } |
298 | |||
299 | // Now wait for it to finish | ||
300 | while ( !finished ) | ||
301 | qApp->processEvents(); | ||
302 | } | 297 | } |
303 | 298 | ||
304 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) | 299 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) |
305 | { | 300 | { |
306 | QString lineStr = buffer; | 301 | QString lineStr = buffer; |
307 | if ( lineStr[buflen-1] == '\n' ) | 302 | if ( lineStr[buflen-1] == '\n' ) |
308 | buflen --; | 303 | buflen --; |
309 | lineStr = lineStr.left( buflen ); | 304 | lineStr = lineStr.left( buflen ); |
310 | emit outputText( lineStr ); | 305 | emit outputText( lineStr ); |
311 | 306 | ||
312 | // check if we are installing dependant packages | 307 | // check if we are installing dependant packages |
313 | if ( option == "install" || option == "reinstall" ) | 308 | if ( option == "install" || option == "reinstall" ) |
314 | { | 309 | { |
315 | // Need to keep track of any dependant packages that get installed | 310 | // Need to keep track of any dependant packages that get installed |
316 | // so that we can create links to them as necessary | 311 | // so that we can create links to them as necessary |
317 | if ( lineStr.startsWith( "Installing " ) ) | 312 | if ( lineStr.startsWith( "Installing " ) ) |
318 | { | 313 | { |
319 | int start = lineStr.find( " " ) + 1; | 314 | int start = lineStr.find( " " ) + 1; |
320 | int end = lineStr.find( " ", start ); | 315 | int end = lineStr.find( " ", start ); |
321 | QString *package = new QString( lineStr.mid( start, end-start ) ); | 316 | QString *package = new QString( lineStr.mid( start, end-start ) ); |
322 | dependantPackages->append( package ); | 317 | dependantPackages->append( package ); |
323 | } | 318 | } |
324 | } | 319 | } |
325 | else if ( option == "remove" && !( flags & FORCE_DEPENDS ) && | 320 | else if ( option == "remove" && !( flags & FORCE_DEPENDS ) && |
@@ -333,48 +328,50 @@ void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) | |||
333 | } | 328 | } |
334 | 329 | ||
335 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) | 330 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) |
336 | { | 331 | { |
337 | QString lineStr = buffer; | 332 | QString lineStr = buffer; |
338 | if ( lineStr[buflen-1] == '\n' ) | 333 | if ( lineStr[buflen-1] == '\n' ) |
339 | buflen --; | 334 | buflen --; |
340 | lineStr=lineStr.left( buflen ); | 335 | lineStr=lineStr.left( buflen ); |
341 | emit outputText( lineStr ); | 336 | emit outputText( lineStr ); |
342 | buffer[0] = '\0'; | 337 | buffer[0] = '\0'; |
343 | error = true; | 338 | error = true; |
344 | } | 339 | } |
345 | 340 | ||
346 | void Ipkg::processFinished() | 341 | void Ipkg::processFinished() |
347 | { | 342 | { |
348 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file | 343 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file |
349 | // to workaround an ipkg bug which stops reinstall to a different location | 344 | // to workaround an ipkg bug which stops reinstall to a different location |
350 | 345 | ||
351 | if ( !error && option == "remove" ) | 346 | if ( !error && option == "remove" ) |
352 | removeStatusEntry(); | 347 | removeStatusEntry(); |
353 | 348 | ||
354 | delete proc; | 349 | delete proc; |
355 | proc = 0; | 350 | proc = 0; |
356 | finished = true; | 351 | finished = true; |
352 | |||
353 | emit ipkgFinished(); | ||
357 | } | 354 | } |
358 | 355 | ||
359 | 356 | ||
360 | void Ipkg :: abort() | 357 | void Ipkg :: abort() |
361 | { | 358 | { |
362 | if ( proc ) | 359 | if ( proc ) |
363 | { | 360 | { |
364 | proc->kill(); | 361 | proc->kill(); |
365 | aborted = true; | 362 | aborted = true; |
366 | } | 363 | } |
367 | } | 364 | } |
368 | 365 | ||
369 | /* | 366 | /* |
370 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) | 367 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) |
371 | { | 368 | { |
372 | FILE *fp = NULL; | 369 | FILE *fp = NULL; |
373 | char line[130]; | 370 | char line[130]; |
374 | QString lineStr, lineStrOld; | 371 | QString lineStr, lineStrOld; |
375 | int ret = false; | 372 | int ret = false; |
376 | 373 | ||
377 | fp = popen( (const char *) cmd, "r"); | 374 | fp = popen( (const char *) cmd, "r"); |
378 | if ( fp == NULL ) | 375 | if ( fp == NULL ) |
379 | { | 376 | { |
380 | QString text; | 377 | QString text; |