author | andyq <andyq> | 2002-11-23 15:27:33 (UTC) |
---|---|---|
committer | andyq <andyq> | 2002-11-23 15:27:33 (UTC) |
commit | 7763c095d81f44cd3012d894da6b17eb0b0cc194 (patch) (unidiff) | |
tree | 286c3392f3ad9b06429a136413590ec99ebefadf /noncore/settings/aqpkg/ipkg.cpp | |
parent | dd850ee9705b0329d49c3e1b0f22d76ce62f7a0b (diff) | |
download | opie-7763c095d81f44cd3012d894da6b17eb0b0cc194.zip opie-7763c095d81f44cd3012d894da6b17eb0b0cc194.tar.gz opie-7763c095d81f44cd3012d894da6b17eb0b0cc194.tar.bz2 |
1.6 Beta - Changed ipg process to use OProcess instead of popen for async io
Diffstat (limited to 'noncore/settings/aqpkg/ipkg.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 115 |
1 files changed, 91 insertions, 24 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp index dad34b0..1efe030 100644 --- a/noncore/settings/aqpkg/ipkg.cpp +++ b/noncore/settings/aqpkg/ipkg.cpp | |||
@@ -28,12 +28,14 @@ using namespace std; | |||
28 | #else | 28 | #else |
29 | #include <qapplication.h> | 29 | #include <qapplication.h> |
30 | #endif | 30 | #endif |
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
33 | 33 | ||
34 | #include <opie/oprocess.h> | ||
35 | |||
34 | #include "utils.h" | 36 | #include "utils.h" |
35 | #include "ipkg.h" | 37 | #include "ipkg.h" |
36 | #include "global.h" | 38 | #include "global.h" |
37 | 39 | ||
38 | Ipkg :: Ipkg() | 40 | Ipkg :: Ipkg() |
39 | { | 41 | { |
@@ -52,41 +54,41 @@ Ipkg :: ~Ipkg() | |||
52 | // destDir is the dir that the destination alias points to (used to link to root) | 54 | // destDir is the dir that the destination alias points to (used to link to root) |
53 | // flags is the ipkg options flags | 55 | // flags is the ipkg options flags |
54 | // dir is the directory to run ipkg in (defaults to "") | 56 | // dir is the directory to run ipkg in (defaults to "") |
55 | bool Ipkg :: runIpkg( ) | 57 | bool Ipkg :: runIpkg( ) |
56 | { | 58 | { |
57 | bool ret = false; | 59 | bool ret = false; |
60 | QStringList commands; | ||
58 | 61 | ||
59 | QDir::setCurrent( "/tmp" ); | 62 | QDir::setCurrent( "/tmp" ); |
60 | QString cmd = ""; | ||
61 | 63 | ||
62 | if ( runtimeDir != "" ) | 64 | if ( runtimeDir != "" ) |
63 | { | 65 | { |
64 | cmd += "cd "; | 66 | commands << "cd "; |
65 | cmd += runtimeDir; | 67 | commands << runtimeDir; |
66 | cmd += " ; "; | 68 | commands << ";"; |
67 | } | 69 | } |
68 | cmd += "ipkg -force-defaults"; | 70 | commands << "ipkg" << "-force-defaults"; |
69 | 71 | ||
70 | // only set the destination for an install operation | 72 | // only set the destination for an install operation |
71 | if ( option == "install" ) | 73 | if ( option == "install" ) |
72 | cmd += " -dest "+ destination; | 74 | commands << "-dest" << destination; |
73 | 75 | ||
74 | 76 | ||
75 | if ( option != "update" && option != "download" ) | 77 | if ( option != "update" && option != "download" ) |
76 | { | 78 | { |
77 | if ( flags & FORCE_DEPENDS ) | 79 | if ( flags & FORCE_DEPENDS ) |
78 | cmd += " -force-depends"; | 80 | commands << "-force-depends"; |
79 | if ( flags & FORCE_REINSTALL ) | 81 | if ( flags & FORCE_REINSTALL ) |
80 | cmd += " -force-reinstall"; | 82 | commands << "-force-reinstall"; |
81 | if ( flags & FORCE_REMOVE ) | 83 | if ( flags & FORCE_REMOVE ) |
82 | cmd += " -force-removal-of-essential-packages"; | 84 | commands << "-force-removal-of-essential-packages"; |
83 | if ( flags & FORCE_OVERWRITE ) | 85 | if ( flags & FORCE_OVERWRITE ) |
84 | cmd += " -force-overwrite"; | 86 | commands << "-force-overwrite"; |
85 | if ( flags & VERBOSE_WGET ) | 87 | if ( flags & VERBOSE_WGET ) |
86 | cmd += " -verbose_wget"; | 88 | commands << "-verbose_wget"; |
87 | 89 | ||
88 | // Handle make links | 90 | // Handle make links |
89 | // Rules - If make links is switched on, create links to root | 91 | // Rules - If make links is switched on, create links to root |
90 | // if destDir is NOT / | 92 | // if destDir is NOT / |
91 | if ( flags & MAKE_LINKS ) | 93 | if ( flags & MAKE_LINKS ) |
92 | { | 94 | { |
@@ -95,24 +97,23 @@ bool Ipkg :: runIpkg( ) | |||
95 | if ( destDir == "/" ) | 97 | if ( destDir == "/" ) |
96 | flags ^= MAKE_LINKS; | 98 | flags ^= MAKE_LINKS; |
97 | } | 99 | } |
98 | } | 100 | } |
99 | 101 | ||
100 | #ifdef X86 | 102 | #ifdef X86 |
101 | cmd += " -f "; | 103 | commands << "-f"; |
102 | cmd += IPKG_CONF; | 104 | commands << IPKG_CONF; |
103 | #endif | 105 | #endif |
104 | 106 | ||
105 | 107 | ||
106 | if ( option == "reinstall" ) | 108 | if ( option == "reinstall" ) |
107 | cmd += " install"; | 109 | commands << "install"; |
108 | else | 110 | else |
109 | cmd += " " + option; | 111 | commands << option; |
110 | if ( package != "" ) | 112 | if ( package != "" ) |
111 | cmd += " " + package; | 113 | commands << package; |
112 | cmd += " 2>&1"; | ||
113 | 114 | ||
114 | 115 | ||
115 | if ( package != "" ) | 116 | if ( package != "" ) |
116 | emit outputText( QString( "Dealing with package " ) + package ); | 117 | emit outputText( QString( "Dealing with package " ) + package ); |
117 | 118 | ||
118 | qApp->processEvents(); | 119 | qApp->processEvents(); |
@@ -127,19 +128,17 @@ bool Ipkg :: runIpkg( ) | |||
127 | emit outputText( QString( "Removing symbolic links...\n" ) ); | 128 | emit outputText( QString( "Removing symbolic links...\n" ) ); |
128 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 129 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
129 | emit outputText( QString( " " ) ); | 130 | emit outputText( QString( " " ) ); |
130 | } | 131 | } |
131 | } | 132 | } |
132 | 133 | ||
133 | emit outputText( cmd ); | ||
134 | |||
135 | // Execute command | 134 | // Execute command |
136 | dependantPackages = new QList<QString>; | 135 | dependantPackages = new QList<QString>; |
137 | dependantPackages->setAutoDelete( true ); | 136 | dependantPackages->setAutoDelete( true ); |
138 | 137 | ||
139 | ret = executeIpkgCommand( cmd, option ); | 138 | ret = executeIpkgCommand( commands, option ); |
140 | 139 | ||
141 | if ( option == "install" || option == "reinstall" ) | 140 | if ( option == "install" || option == "reinstall" ) |
142 | { | 141 | { |
143 | // If we are not removing packages and make links option is selected | 142 | // If we are not removing packages and make links option is selected |
144 | // create the links | 143 | // create the links |
145 | createLinks = true; | 144 | createLinks = true; |
@@ -168,16 +167,16 @@ bool Ipkg :: runIpkg( ) | |||
168 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file | 167 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file |
169 | // to workaround an ipkg bug which stops reinstall to a different location | 168 | // to workaround an ipkg bug which stops reinstall to a different location |
170 | if ( option == "remove" ) | 169 | if ( option == "remove" ) |
171 | removeStatusEntry(); | 170 | removeStatusEntry(); |
172 | 171 | ||
173 | 172 | ||
174 | // emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") ); | ||
175 | emit outputText( "Finished" ); | 173 | emit outputText( "Finished" ); |
176 | emit outputText( "" ); | 174 | emit outputText( "" ); |
177 | return ret; | 175 | return ret; |
176 | |||
178 | } | 177 | } |
179 | 178 | ||
180 | void Ipkg :: removeStatusEntry() | 179 | void Ipkg :: removeStatusEntry() |
181 | { | 180 | { |
182 | QString statusFile = destDir; | 181 | QString statusFile = destDir; |
183 | if ( statusFile.right( 1 ) != "/" ) | 182 | if ( statusFile.right( 1 ) != "/" ) |
@@ -252,13 +251,81 @@ void Ipkg :: removeStatusEntry() | |||
252 | 251 | ||
253 | // Remove old status file and put tmp stats file in its place | 252 | // Remove old status file and put tmp stats file in its place |
254 | remove( statusFile ); | 253 | remove( statusFile ); |
255 | rename( outStatusFile, statusFile ); | 254 | rename( outStatusFile, statusFile ); |
256 | } | 255 | } |
257 | 256 | ||
257 | int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString option ) | ||
258 | { | ||
259 | // OK we're gonna use OProcess to run this thing | ||
260 | proc = new OProcess(); | ||
261 | |||
262 | // Connect up our slots | ||
263 | connect(proc, SIGNAL(processExited(OProcess *)), | ||
264 | this, SLOT( processFinished())); | ||
258 | 265 | ||
266 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), | ||
267 | this, SLOT(commandStdout(OProcess *, char *, int))); | ||
268 | |||
269 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), | ||
270 | this, SLOT(commandStderr(OProcess *, char *, int))); | ||
271 | |||
272 | for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) | ||
273 | { | ||
274 | qDebug( "%s ", (*it).latin1() ); | ||
275 | *proc << (*it).latin1(); | ||
276 | } | ||
277 | cout << endl; | ||
278 | |||
279 | // Start the process going | ||
280 | finished = false; | ||
281 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) | ||
282 | { | ||
283 | emit outputText( QString( "Couldn't start ipkg process" ) ); | ||
284 | qDebug( "Couldn't start ipkg process!" ); | ||
285 | } | ||
286 | |||
287 | // Now wait for it to finish | ||
288 | while ( !finished ) | ||
289 | qApp->processEvents(); | ||
290 | } | ||
291 | |||
292 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) | ||
293 | { | ||
294 | qDebug("received stdout %d bytes", buflen); | ||
295 | |||
296 | QString lineStr = buffer; | ||
297 | if ( lineStr[buflen-1] == '\n' ) | ||
298 | buflen --; | ||
299 | lineStr = lineStr.left( buflen ); | ||
300 | emit outputText( lineStr ); | ||
301 | qDebug(lineStr); | ||
302 | buffer[0] = '\0'; | ||
303 | } | ||
304 | |||
305 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) | ||
306 | { | ||
307 | qDebug("received stderrt %d bytes", buflen); | ||
308 | |||
309 | QString lineStr = buffer; | ||
310 | if ( lineStr[buflen-1] == '\n' ) | ||
311 | buflen --; | ||
312 | lineStr=lineStr.left( buflen ); | ||
313 | emit outputText( lineStr ); | ||
314 | buffer[0] = '\0'; | ||
315 | } | ||
316 | |||
317 | void Ipkg::processFinished() | ||
318 | { | ||
319 | delete proc; | ||
320 | finished = true; | ||
321 | } | ||
322 | |||
323 | |||
324 | |||
325 | /* | ||
259 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) | 326 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) |
260 | { | 327 | { |
261 | FILE *fp = NULL; | 328 | FILE *fp = NULL; |
262 | char line[130]; | 329 | char line[130]; |
263 | QString lineStr, lineStrOld; | 330 | QString lineStr, lineStrOld; |
264 | int ret = false; | 331 | int ret = false; |
@@ -317,13 +384,13 @@ int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) | |||
317 | } | 384 | } |
318 | pclose(fp); | 385 | pclose(fp); |
319 | } | 386 | } |
320 | 387 | ||
321 | return ret; | 388 | return ret; |
322 | } | 389 | } |
323 | 390 | */ | |
324 | 391 | ||
325 | void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) | 392 | void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) |
326 | { | 393 | { |
327 | if ( dest == "root" || dest == "/" ) | 394 | if ( dest == "root" || dest == "/" ) |
328 | return; | 395 | return; |
329 | 396 | ||
@@ -345,16 +412,16 @@ QStringList* Ipkg :: getList( const QString &packageFilename, const QString &des | |||
345 | // Couldn't open from dest, try from / | 412 | // Couldn't open from dest, try from / |
346 | cout << "Could not open:" << packageFileDir << endl; | 413 | cout << "Could not open:" << packageFileDir << endl; |
347 | f.close(); | 414 | f.close(); |
348 | 415 | ||
349 | packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; | 416 | packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; |
350 | f.setName( packageFileDir ); | 417 | f.setName( packageFileDir ); |
351 | // cout << "Try to open " << packageFileDir.latin1() << endl; | 418 | qDebug( "Try to open %s", packageFileDir.latin1() ); |
352 | if ( ! f.open(IO_ReadOnly) ) | 419 | if ( ! f.open(IO_ReadOnly) ) |
353 | { | 420 | { |
354 | cout << "Could not open:" << packageFileDir << endl; | 421 | qDebug( "Could not open: %s", packageFileDir ); |
355 | emit outputText( QString( "Could not open :" ) + packageFileDir ); | 422 | emit outputText( QString( "Could not open :" ) + packageFileDir ); |
356 | return (QStringList*)0; | 423 | return (QStringList*)0; |
357 | } | 424 | } |
358 | } | 425 | } |
359 | QStringList *fileList = new QStringList(); | 426 | QStringList *fileList = new QStringList(); |
360 | QTextStream t( &f ); | 427 | QTextStream t( &f ); |