summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/ipkg.cpp22
-rw-r--r--noncore/settings/aqpkg/ipkg.h2
2 files changed, 24 insertions, 0 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp
index 407abe9..7afe04f 100644
--- a/noncore/settings/aqpkg/ipkg.cpp
+++ b/noncore/settings/aqpkg/ipkg.cpp
@@ -18,48 +18,49 @@
18#include <fstream> 18#include <fstream>
19#include <iostream> 19#include <iostream>
20#include <vector> 20#include <vector>
21using namespace std; 21using namespace std;
22 22
23#include <stdio.h> 23#include <stdio.h>
24#include <unistd.h> 24#include <unistd.h>
25 25
26#ifdef QWS 26#ifdef QWS
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
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> 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
40Ipkg :: Ipkg() 40Ipkg :: Ipkg()
41{ 41{
42 proc = 0;
42} 43}
43 44
44Ipkg :: ~Ipkg() 45Ipkg :: ~Ipkg()
45{ 46{
46} 47}
47 48
48// 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
49// 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
50// 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)
51// 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
52// package parameter) 53// package parameter)
53// dest is the destination alias (from ipk.conf) 54// dest is the destination alias (from ipk.conf)
54// 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)
55// flags is the ipkg options flags 56// flags is the ipkg options flags
56// dir is the directory to run ipkg in (defaults to "") 57// dir is the directory to run ipkg in (defaults to "")
57bool Ipkg :: runIpkg( ) 58bool Ipkg :: runIpkg( )
58{ 59{
59 bool ret = false; 60 bool ret = false;
60 QStringList commands; 61 QStringList commands;
61 62
62 QDir::setCurrent( "/tmp" ); 63 QDir::setCurrent( "/tmp" );
63 64
64 if ( runtimeDir != "" ) 65 if ( runtimeDir != "" )
65 { 66 {
@@ -116,48 +117,51 @@ bool Ipkg :: runIpkg( )
116 if ( package != "" ) 117 if ( package != "" )
117 emit outputText( QString( "Dealing with package " ) + package ); 118 emit outputText( QString( "Dealing with package " ) + package );
118 119
119 qApp->processEvents(); 120 qApp->processEvents();
120 121
121 // If we are removing packages and make links option is selected 122 // If we are removing packages and make links option is selected
122 // create the links 123 // create the links
123 if ( option == "remove" || option == "reinstall" ) 124 if ( option == "remove" || option == "reinstall" )
124 { 125 {
125 createLinks = false; 126 createLinks = false;
126 if ( flags & MAKE_LINKS ) 127 if ( flags & MAKE_LINKS )
127 { 128 {
128 emit outputText( QString( "Removing symbolic links...\n" ) ); 129 emit outputText( QString( "Removing symbolic links...\n" ) );
129 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 130 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
130 emit outputText( QString( " " ) ); 131 emit outputText( QString( " " ) );
131 } 132 }
132 } 133 }
133 134
134 // Execute command 135 // Execute command
135 dependantPackages = new QList<QString>; 136 dependantPackages = new QList<QString>;
136 dependantPackages->setAutoDelete( true ); 137 dependantPackages->setAutoDelete( true );
137 138
138 ret = executeIpkgCommand( commands, option ); 139 ret = executeIpkgCommand( commands, option );
139 140
141 if ( aborted )
142 return false;
143
140 if ( option == "install" || option == "reinstall" ) 144 if ( option == "install" || option == "reinstall" )
141 { 145 {
142 // If we are not removing packages and make links option is selected 146 // If we are not removing packages and make links option is selected
143 // create the links 147 // create the links
144 createLinks = true; 148 createLinks = true;
145 if ( flags & MAKE_LINKS ) 149 if ( flags & MAKE_LINKS )
146 { 150 {
147 emit outputText( " " ); 151 emit outputText( " " );
148 emit outputText( QString( "Creating symbolic links for " )+ package ); 152 emit outputText( QString( "Creating symbolic links for " )+ package );
149 153
150 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 154 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
151 155
152 // link dependant packages that were installed with this release 156 // link dependant packages that were installed with this release
153 QString *pkg; 157 QString *pkg;
154 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) 158 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() )
155 { 159 {
156 if ( *pkg == package ) 160 if ( *pkg == package )
157 continue; 161 continue;
158 emit outputText( " " ); 162 emit outputText( " " );
159 emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); 163 emit outputText( QString( "Creating symbolic links for " )+ (*pkg) );
160 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); 164 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir );
161 } 165 }
162 } 166 }
163 } 167 }
@@ -235,50 +239,59 @@ void Ipkg :: removeStatusEntry()
235 } 239 }
236 240
237 lines.push_back( QString( line ) ); 241 lines.push_back( QString( line ) );
238// out << line << endl; 242// out << line << endl;
239 } while ( !in.eof() ); 243 } while ( !in.eof() );
240 244
241 // Write lines out 245 // Write lines out
242 vector<QString>::iterator it; 246 vector<QString>::iterator it;
243 for ( it = lines.begin() ; it != lines.end() ; ++it ) 247 for ( it = lines.begin() ; it != lines.end() ; ++it )
244 { 248 {
245 cout << "Writing " << (const char *)(*it) << endl; 249 cout << "Writing " << (const char *)(*it) << endl;
246 out << (const char *)(*it) << endl; 250 out << (const char *)(*it) << endl;
247 } 251 }
248 252
249 in.close(); 253 in.close();
250 out.close(); 254 out.close();
251 255
252 // Remove old status file and put tmp stats file in its place 256 // Remove old status file and put tmp stats file in its place
253 remove( statusFile ); 257 remove( statusFile );
254 rename( outStatusFile, statusFile ); 258 rename( outStatusFile, statusFile );
255} 259}
256 260
257int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString option ) 261int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString option )
258{ 262{
263 // If one is already running - should never be but just to be safe
264 if ( proc )
265 {
266 delete proc;
267 proc = 0;
268 }
269
259 // OK we're gonna use OProcess to run this thing 270 // OK we're gonna use OProcess to run this thing
260 proc = new OProcess(); 271 proc = new OProcess();
272 aborted = false;
273
261 274
262 // Connect up our slots 275 // Connect up our slots
263 connect(proc, SIGNAL(processExited(OProcess *)), 276 connect(proc, SIGNAL(processExited(OProcess *)),
264 this, SLOT( processFinished())); 277 this, SLOT( processFinished()));
265 278
266 connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), 279 connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)),
267 this, SLOT(commandStdout(OProcess *, char *, int))); 280 this, SLOT(commandStdout(OProcess *, char *, int)));
268 281
269 connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), 282 connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)),
270 this, SLOT(commandStderr(OProcess *, char *, int))); 283 this, SLOT(commandStderr(OProcess *, char *, int)));
271 284
272 for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) 285 for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it )
273 { 286 {
274 qDebug( "%s ", (*it).latin1() ); 287 qDebug( "%s ", (*it).latin1() );
275 *proc << (*it).latin1(); 288 *proc << (*it).latin1();
276 } 289 }
277 cout << endl; 290 cout << endl;
278 291
279 // Start the process going 292 // Start the process going
280 finished = false; 293 finished = false;
281 if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) 294 if(!proc->start(OProcess::NotifyOnExit, OProcess::All))
282 { 295 {
283 emit outputText( QString( "Couldn't start ipkg process" ) ); 296 emit outputText( QString( "Couldn't start ipkg process" ) );
284 qDebug( "Couldn't start ipkg process!" ); 297 qDebug( "Couldn't start ipkg process!" );
@@ -296,52 +309,61 @@ void Ipkg::commandStdout(OProcess*, char *buffer, int buflen)
296 QString lineStr = buffer; 309 QString lineStr = buffer;
297 if ( lineStr[buflen-1] == '\n' ) 310 if ( lineStr[buflen-1] == '\n' )
298 buflen --; 311 buflen --;
299 lineStr = lineStr.left( buflen ); 312 lineStr = lineStr.left( buflen );
300 emit outputText( lineStr ); 313 emit outputText( lineStr );
301 qDebug(lineStr); 314 qDebug(lineStr);
302 buffer[0] = '\0'; 315 buffer[0] = '\0';
303} 316}
304 317
305void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) 318void Ipkg::commandStderr(OProcess*, char *buffer, int buflen)
306{ 319{
307 qDebug("received stderrt %d bytes", buflen); 320 qDebug("received stderrt %d bytes", buflen);
308 321
309 QString lineStr = buffer; 322 QString lineStr = buffer;
310 if ( lineStr[buflen-1] == '\n' ) 323 if ( lineStr[buflen-1] == '\n' )
311 buflen --; 324 buflen --;
312 lineStr=lineStr.left( buflen ); 325 lineStr=lineStr.left( buflen );
313 emit outputText( lineStr ); 326 emit outputText( lineStr );
314 buffer[0] = '\0'; 327 buffer[0] = '\0';
315} 328}
316 329
317void Ipkg::processFinished() 330void Ipkg::processFinished()
318{ 331{
319 delete proc; 332 delete proc;
333 proc = 0;
320 finished = true; 334 finished = true;
321} 335}
322 336
323 337
338void Ipkg :: abort()
339{
340 if ( proc )
341 {
342 proc->kill();
343 aborted = true;
344 }
345}
324 346
325/* 347/*
326int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) 348int Ipkg :: executeIpkgCommand( QString &cmd, const QString option )
327{ 349{
328 FILE *fp = NULL; 350 FILE *fp = NULL;
329 char line[130]; 351 char line[130];
330 QString lineStr, lineStrOld; 352 QString lineStr, lineStrOld;
331 int ret = false; 353 int ret = false;
332 354
333 fp = popen( (const char *) cmd, "r"); 355 fp = popen( (const char *) cmd, "r");
334 if ( fp == NULL ) 356 if ( fp == NULL )
335 { 357 {
336 cout << "Couldn't execute " << cmd << "! err = " << fp << endl; 358 cout << "Couldn't execute " << cmd << "! err = " << fp << endl;
337 QString text; 359 QString text;
338 text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); 360 text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd );
339 emit outputText( text ); 361 emit outputText( text );
340 } 362 }
341 else 363 else
342 { 364 {
343 while ( fgets( line, sizeof line, fp) != NULL ) 365 while ( fgets( line, sizeof line, fp) != NULL )
344 { 366 {
345 lineStr = line; 367 lineStr = line;
346 lineStr=lineStr.left( lineStr.length()-1 ); 368 lineStr=lineStr.left( lineStr.length()-1 );
347 369
diff --git a/noncore/settings/aqpkg/ipkg.h b/noncore/settings/aqpkg/ipkg.h
index 25bae59..f08667b 100644
--- a/noncore/settings/aqpkg/ipkg.h
+++ b/noncore/settings/aqpkg/ipkg.h
@@ -38,49 +38,51 @@
38class OProcess; 38class OProcess;
39 39
40class Ipkg : public QObject 40class Ipkg : public QObject
41{ 41{
42 Q_OBJECT 42 Q_OBJECT
43public: 43public:
44 Ipkg(); 44 Ipkg();
45 ~Ipkg(); 45 ~Ipkg();
46 bool runIpkg( ); 46 bool runIpkg( );
47 47
48 void setOption( const char *opt ) { option = opt; } 48 void setOption( const char *opt ) { option = opt; }
49 void setPackage( const char *pkg ) { package = pkg; } 49 void setPackage( const char *pkg ) { package = pkg; }
50 void setDestination( const char *dest ) { destination = dest; } 50 void setDestination( const char *dest ) { destination = dest; }
51 void setDestinationDir( const char *dir ) { destDir = dir; } 51 void setDestinationDir( const char *dir ) { destDir = dir; }
52 void setFlags( int fl ) { flags = fl; } 52 void setFlags( int fl ) { flags = fl; }
53 void setRuntimeDirectory( const char *dir ) { runtimeDir = dir; } 53 void setRuntimeDirectory( const char *dir ) { runtimeDir = dir; }
54 54
55signals: 55signals:
56 void outputText( const QString &text ); 56 void outputText( const QString &text );
57 57
58public slots: 58public slots:
59 void commandStdout(OProcess*, char *buffer, int buflen); 59 void commandStdout(OProcess*, char *buffer, int buflen);
60 void commandStderr(OProcess*, char *buffer, int buflen); 60 void commandStderr(OProcess*, char *buffer, int buflen);
61 void processFinished(); 61 void processFinished();
62 void abort();
62 63
63 64
64private: 65private:
65 bool createLinks; 66 bool createLinks;
67 bool aborted;
66 QString option; 68 QString option;
67 QString package; 69 QString package;
68 QString destination; 70 QString destination;
69 QString destDir; 71 QString destDir;
70 QString runtimeDir; 72 QString runtimeDir;
71 OProcess *proc; 73 OProcess *proc;
72 int flags; 74 int flags;
73 bool finished; 75 bool finished;
74 76
75 QList<QString> *dependantPackages; 77 QList<QString> *dependantPackages;
76 78
77 int executeIpkgCommand( QStringList &cmd, const QString option ); 79 int executeIpkgCommand( QStringList &cmd, const QString option );
78 void removeStatusEntry(); 80 void removeStatusEntry();
79 void linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ); 81 void linkPackage( const QString &packFileName, const QString &dest, const QString &destDir );
80 QStringList* getList( const QString &packageFilename, const QString &destDir ); 82 QStringList* getList( const QString &packageFilename, const QString &destDir );
81 void processFileList( const QStringList *fileList, const QString &destDir ); 83 void processFileList( const QStringList *fileList, const QString &destDir );
82 void processLinkDir( const QString &file, const QString &baseDir, const QString &destDir ); 84 void processLinkDir( const QString &file, const QString &baseDir, const QString &destDir );
83 85
84}; 86};
85 87
86#endif 88#endif