summaryrefslogtreecommitdiff
path: root/noncore
authordrw <drw>2003-02-25 00:39:29 (UTC)
committer drw <drw>2003-02-25 00:39:29 (UTC)
commit8d80ed4f9cf8051b5566aaf3f639c76fe7d6de7c (patch) (unidiff)
tree95ac0e3df097d1d2af81dbb543502b0682043fc0 /noncore
parent45fc2c7089de9bbb7887ba9bdb56c974b19c1caf (diff)
downloadopie-8d80ed4f9cf8051b5566aaf3f639c76fe7d6de7c.zip
opie-8d80ed4f9cf8051b5566aaf3f639c76fe7d6de7c.tar.gz
opie-8d80ed4f9cf8051b5566aaf3f639c76fe7d6de7c.tar.bz2
Fix for bug #707 - remove package from status file only if package removal was successful.
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/ipkg.cpp13
-rw-r--r--noncore/settings/aqpkg/ipkg.h1
2 files changed, 8 insertions, 6 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp
index 51eca8b..e66c02d 100644
--- a/noncore/settings/aqpkg/ipkg.cpp
+++ b/noncore/settings/aqpkg/ipkg.cpp
@@ -36,48 +36,49 @@ using namespace std;
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 proc = 0;
43} 43}
44 44
45Ipkg :: ~Ipkg() 45Ipkg :: ~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 "")
58bool Ipkg :: runIpkg( ) 58bool Ipkg :: runIpkg( )
59{ 59{
60 error = false;
60 bool ret = false; 61 bool ret = false;
61 QStringList commands; 62 QStringList commands;
62 63
63 QDir::setCurrent( "/tmp" ); 64 QDir::setCurrent( "/tmp" );
64 65
65 if ( runtimeDir != "" ) 66 if ( runtimeDir != "" )
66 { 67 {
67 commands << "cd "; 68 commands << "cd ";
68 commands << runtimeDir; 69 commands << runtimeDir;
69 commands << ";"; 70 commands << ";";
70 } 71 }
71 commands << "ipkg" << "-force-defaults"; 72 commands << "ipkg" << "-force-defaults";
72 73
73 // only set the destination for an install operation 74 // only set the destination for an install operation
74 if ( option == "install" ) 75 if ( option == "install" )
75 commands << "-dest" << destination; 76 commands << "-dest" << destination;
76 77
77 78
78 if ( option != "update" && option != "download" ) 79 if ( option != "update" && option != "download" )
79 { 80 {
80 if ( flags & FORCE_DEPENDS ) 81 if ( flags & FORCE_DEPENDS )
81 commands << "-force-depends"; 82 commands << "-force-depends";
82 if ( flags & FORCE_REINSTALL ) 83 if ( flags & FORCE_REINSTALL )
83 commands << "-force-reinstall"; 84 commands << "-force-reinstall";
@@ -147,54 +148,48 @@ bool Ipkg :: runIpkg( )
147 // create the links 148 // create the links
148 createLinks = true; 149 createLinks = true;
149 if ( flags & MAKE_LINKS ) 150 if ( flags & MAKE_LINKS )
150 { 151 {
151 emit outputText( " " ); 152 emit outputText( " " );
152 emit outputText( QString( "Creating symbolic links for " )+ package ); 153 emit outputText( QString( "Creating symbolic links for " )+ package );
153 154
154 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 155 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
155 156
156 // link dependant packages that were installed with this release 157 // link dependant packages that were installed with this release
157 QString *pkg; 158 QString *pkg;
158 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) 159 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() )
159 { 160 {
160 if ( *pkg == package ) 161 if ( *pkg == package )
161 continue; 162 continue;
162 emit outputText( " " ); 163 emit outputText( " " );
163 emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); 164 emit outputText( QString( "Creating symbolic links for " )+ (*pkg) );
164 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); 165 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir );
165 } 166 }
166 } 167 }
167 } 168 }
168 169
169 delete dependantPackages; 170 delete dependantPackages;
170 171
171 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file
172 // to workaround an ipkg bug which stops reinstall to a different location
173 if ( option == "remove" )
174 removeStatusEntry();
175
176
177 emit outputText( "Finished" ); 172 emit outputText( "Finished" );
178 emit outputText( "" ); 173 emit outputText( "" );
179 return ret; 174 return ret;
180 175
181} 176}
182 177
183void Ipkg :: removeStatusEntry() 178void Ipkg :: removeStatusEntry()
184{ 179{
185 QString statusFile = destDir; 180 QString statusFile = destDir;
186 if ( statusFile.right( 1 ) != "/" ) 181 if ( statusFile.right( 1 ) != "/" )
187 statusFile += "/"; 182 statusFile += "/";
188 statusFile += "usr/lib/ipkg/status"; 183 statusFile += "usr/lib/ipkg/status";
189 QString outStatusFile = statusFile + ".tmp"; 184 QString outStatusFile = statusFile + ".tmp";
190 185
191 emit outputText( "" ); 186 emit outputText( "" );
192 emit outputText( "Removing status entry..." ); 187 emit outputText( "Removing status entry..." );
193 emit outputText( QString( "status file - " )+ statusFile ); 188 emit outputText( QString( "status file - " )+ statusFile );
194 emit outputText( QString( "package - " )+ package ); 189 emit outputText( QString( "package - " )+ package );
195 190
196 ifstream in( statusFile ); 191 ifstream in( statusFile );
197 ofstream out( outStatusFile ); 192 ofstream out( outStatusFile );
198 if ( !in.is_open() ) 193 if ( !in.is_open() )
199 { 194 {
200 emit outputText( QString( "Couldn't open status file - " )+ statusFile ); 195 emit outputText( QString( "Couldn't open status file - " )+ statusFile );
@@ -319,52 +314,58 @@ void Ipkg::commandStdout(OProcess*, char *buffer, int buflen)
319 // so that we can create links to them as necessary 314 // so that we can create links to them as necessary
320 if ( lineStr.startsWith( "Installing " ) ) 315 if ( lineStr.startsWith( "Installing " ) )
321 { 316 {
322 int start = lineStr.find( " " ) + 1; 317 int start = lineStr.find( " " ) + 1;
323 int end = lineStr.find( " ", start ); 318 int end = lineStr.find( " ", start );
324 QString *package = new QString( lineStr.mid( start, end-start ) ); 319 QString *package = new QString( lineStr.mid( start, end-start ) );
325 dependantPackages->append( package ); 320 dependantPackages->append( package );
326 } 321 }
327 } 322 }
328 323
329 qDebug(lineStr); 324 qDebug(lineStr);
330 buffer[0] = '\0'; 325 buffer[0] = '\0';
331} 326}
332 327
333void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) 328void Ipkg::commandStderr(OProcess*, char *buffer, int buflen)
334{ 329{
335 qDebug("received stderrt %d bytes", buflen); 330 qDebug("received stderrt %d bytes", 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';
338 error = true;
343} 339}
344 340
345void Ipkg::processFinished() 341void Ipkg::processFinished()
346{ 342{
343 // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file
344 // to workaround an ipkg bug which stops reinstall to a different location
345 if ( !error && option == "remove" )
346 removeStatusEntry();
347
347 delete proc; 348 delete proc;
348 proc = 0; 349 proc = 0;
349 finished = true; 350 finished = true;
350} 351}
351 352
352 353
353void Ipkg :: abort() 354void Ipkg :: abort()
354{ 355{
355 if ( proc ) 356 if ( proc )
356 { 357 {
357 proc->kill(); 358 proc->kill();
358 aborted = true; 359 aborted = true;
359 } 360 }
360} 361}
361 362
362/* 363/*
363int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) 364int Ipkg :: executeIpkgCommand( QString &cmd, const QString option )
364{ 365{
365 FILE *fp = NULL; 366 FILE *fp = NULL;
366 char line[130]; 367 char line[130];
367 QString lineStr, lineStrOld; 368 QString lineStr, lineStrOld;
368 int ret = false; 369 int ret = false;
369 370
370 fp = popen( (const char *) cmd, "r"); 371 fp = popen( (const char *) cmd, "r");
diff --git a/noncore/settings/aqpkg/ipkg.h b/noncore/settings/aqpkg/ipkg.h
index f08667b..d49bb04 100644
--- a/noncore/settings/aqpkg/ipkg.h
+++ b/noncore/settings/aqpkg/ipkg.h
@@ -44,45 +44,46 @@ public:
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 void abort();
63 63
64 64
65private: 65private:
66 bool createLinks; 66 bool createLinks;
67 bool aborted; 67 bool aborted;
68 bool error;
68 QString option; 69 QString option;
69 QString package; 70 QString package;
70 QString destination; 71 QString destination;
71 QString destDir; 72 QString destDir;
72 QString runtimeDir; 73 QString runtimeDir;
73 OProcess *proc; 74 OProcess *proc;
74 int flags; 75 int flags;
75 bool finished; 76 bool finished;
76 77
77 QList<QString> *dependantPackages; 78 QList<QString> *dependantPackages;
78 79
79 int executeIpkgCommand( QStringList &cmd, const QString option ); 80 int executeIpkgCommand( QStringList &cmd, const QString option );
80 void removeStatusEntry(); 81 void removeStatusEntry();
81 void linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ); 82 void linkPackage( const QString &packFileName, const QString &dest, const QString &destDir );
82 QStringList* getList( const QString &packageFilename, const QString &destDir ); 83 QStringList* getList( const QString &packageFilename, const QString &destDir );
83 void processFileList( const QStringList *fileList, const QString &destDir ); 84 void processFileList( const QStringList *fileList, const QString &destDir );
84 void processLinkDir( const QString &file, const QString &baseDir, const QString &destDir ); 85 void processLinkDir( const QString &file, const QString &baseDir, const QString &destDir );
85 86
86}; 87};
87 88
88#endif 89#endif