summaryrefslogtreecommitdiff
authorandyq <andyq>2002-12-17 22:31:10 (UTC)
committer andyq <andyq>2002-12-17 22:31:10 (UTC)
commit995f9ff51e4a687471500765ff40aea27a677197 (patch) (unidiff)
tree376f3f7351a0192d42f0c2e351f39b1e1e0a38f7
parent01640bfdce16d2fd23722a59004a6efd4600c0cf (diff)
downloadopie-995f9ff51e4a687471500765ff40aea27a677197.zip
opie-995f9ff51e4a687471500765ff40aea27a677197.tar.gz
opie-995f9ff51e4a687471500765ff40aea27a677197.tar.bz2
Added abort functionality
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
@@ -30,24 +30,25 @@ using namespace std;
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)
@@ -128,24 +129,27 @@ bool Ipkg :: runIpkg( )
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
@@ -247,26 +251,35 @@ void Ipkg :: removeStatusEntry()
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 )
@@ -308,28 +321,37 @@ void Ipkg::commandStderr(OProcess*, char *buffer, int 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 {
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
@@ -50,28 +50,30 @@ public:
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 );