summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/ipkg.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp
index d5157eb..f8513e4 100644
--- a/noncore/settings/aqpkg/ipkg.cpp
+++ b/noncore/settings/aqpkg/ipkg.cpp
@@ -1,345 +1,349 @@
1/*************************************************************************** 1/***************************************************************************
2 ipkg.cpp - description 2 ipkg.cpp - description
3 ------------------- 3 -------------------
4 begin : Sat Aug 31 2002 4 begin : Sat Aug 31 2002
5 copyright : (C) 2002 by Andy Qua 5 copyright : (C) 2002 by Andy Qua
6 email : andy.qua@blueyonder.co.uk 6 email : andy.qua@blueyonder.co.uk
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. * 14 * (at your option) any later version. *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17 17
18#include <fstream> 18#include <fstream>
19using namespace std; 19using namespace std;
20 20
21#include <stdio.h> 21#include <stdio.h>
22#include <unistd.h> 22#include <unistd.h>
23 23
24#ifdef QWS 24#ifdef QWS
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#else 26#else
27#include <qapplication.h> 27#include <qapplication.h>
28#endif 28#endif
29#include <qdir.h> 29#include <qdir.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31 31
32#include "utils.h" 32#include "utils.h"
33#include "ipkg.h" 33#include "ipkg.h"
34#include "global.h" 34#include "global.h"
35 35
36Ipkg :: Ipkg() 36Ipkg :: Ipkg()
37{ 37{
38} 38}
39 39
40Ipkg :: ~Ipkg() 40Ipkg :: ~Ipkg()
41{ 41{
42} 42}
43 43
44// Option is what we are going to do - install, upgrade, download 44// Option is what we are going to do - install, upgrade, download
45// package is the package name to install - either a fully qualified path and ipk 45// package is the package name to install - either a fully qualified path and ipk
46// file (if stored locally) or just the name of the package (for a network package) 46// file (if stored locally) or just the name of the package (for a network package)
47// packageName is the package name - (for a network package this will be the same as 47// packageName is the package name - (for a network package this will be the same as
48// package parameter) 48// package parameter)
49// dest is the destination alias (from ipk.conf) 49// dest is the destination alias (from ipk.conf)
50// destDir is the dir that the destination alias points to (used to link to root) 50// destDir is the dir that the destination alias points to (used to link to root)
51// flags is the ipkg options flags 51// flags is the ipkg options flags
52// dir is the directory to run ipkg in (defaults to "") 52// dir is the directory to run ipkg in (defaults to "")
53bool Ipkg :: runIpkg( ) 53bool Ipkg :: runIpkg( )
54{ 54{
55 bool ret = false; 55 bool ret = false;
56 56
57 QDir::setCurrent( "/tmp" ); 57 QDir::setCurrent( "/tmp" );
58 QString cmd = ""; 58 QString cmd = "";
59 59
60 if ( runtimeDir != "" ) 60 if ( runtimeDir != "" )
61 { 61 {
62 cmd += "cd "; 62 cmd += "cd ";
63 cmd += runtimeDir; 63 cmd += runtimeDir;
64 cmd += " ; "; 64 cmd += " ; ";
65 } 65 }
66 cmd += "ipkg"; 66 cmd += "ipkg";
67 67
68 if ( option != "update" && option != "download" ) 68 if ( option != "update" && option != "download" && option != "upgrade" )
69 { 69 {
70 cmd += " -dest "+ destination; 70 cmd += " -dest "+ destination;
71 cmd += " -force-defaults"; 71 cmd += " -force-defaults";
72 72
73 if ( flags & FORCE_DEPENDS ) 73 if ( flags & FORCE_DEPENDS )
74 cmd += " -force-depends"; 74 cmd += " -force-depends";
75 if ( flags & FORCE_REINSTALL ) 75 if ( flags & FORCE_REINSTALL )
76 cmd += " -force-reinstall"; 76 cmd += " -force-reinstall";
77 if ( flags & FORCE_REMOVE ) 77 if ( flags & FORCE_REMOVE )
78 cmd += " -force-removal-of-essential-packages"; 78 cmd += " -force-removal-of-essential-packages";
79 if ( flags & FORCE_OVERWRITE ) 79 if ( flags & FORCE_OVERWRITE )
80 cmd += " -force-overwrite"; 80 cmd += " -force-overwrite";
81 81
82 // Handle make links 82 // Handle make links
83 // Rules - If make links is switched on, create links to root 83 // Rules - If make links is switched on, create links to root
84 // if destDir is NOT / 84 // if destDir is NOT /
85 if ( flags & MAKE_LINKS ) 85 if ( flags & MAKE_LINKS )
86 { 86 {
87 // If destDir == / turn off make links as package is being insalled 87 // If destDir == / turn off make links as package is being insalled
88 // to root already. 88 // to root already.
89 if ( destDir == "/" ) 89 if ( destDir == "/" )
90 flags ^= MAKE_LINKS; 90 flags ^= MAKE_LINKS;
91 } 91 }
92 92
93 } 93 }
94 94
95#ifdef X86 95#ifdef X86
96 cmd += " -f "; 96 cmd += " -f ";
97 cmd += IPKG_CONF; 97 cmd += IPKG_CONF;
98#endif 98#endif
99 99
100 cmd += " " + option + " " + package + " 2>&1"; 100 cmd += " " + option;
101 if ( option != "upgrade" )
102 cmd += " " + package;
103 cmd += " 2>&1";
101 104
102 qApp->processEvents(); 105 qApp->processEvents();
103 106
104 // If we are removing packages and make links option is selected 107 // If we are removing packages and make links option is selected
105 // create the links 108 // create the links
106 if ( option == "remove" ) 109 if ( option == "remove" )
107 { 110 {
108 createLinks = false; 111 createLinks = false;
109 if ( flags & MAKE_LINKS ) 112 if ( flags & MAKE_LINKS )
110 { 113 {
111 emit outputText( QString( "Removing symbolic links...\n" ) ); 114 emit outputText( QString( "Removing symbolic links...\n" ) );
112 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 115 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
113 } 116 }
114 } 117 }
115 118
116 emit outputText( cmd ); 119 emit outputText( cmd );
117 120
118 // Execute command 121 // Execute command
119 dependantPackages = new QList<QString>; 122 dependantPackages = new QList<QString>;
120 dependantPackages->setAutoDelete( true ); 123 dependantPackages->setAutoDelete( true );
124
121 ret = executeIpkgCommand( cmd, option ); 125 ret = executeIpkgCommand( cmd, option );
122 126
123 if ( option == "install" ) 127 if ( option == "install" )
124 { 128 {
125 // If we are not removing packages and make links option is selected 129 // If we are not removing packages and make links option is selected
126 // create the links 130 // create the links
127 createLinks = true; 131 createLinks = true;
128 if ( flags & MAKE_LINKS ) 132 if ( flags & MAKE_LINKS )
129 { 133 {
130 emit outputText( " " ); 134 emit outputText( " " );
131 emit outputText( QString( "Creating symbolic links for " )+ package ); 135 emit outputText( QString( "Creating symbolic links for " )+ package );
132 136
133 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 137 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
134 138
135 // link dependant packages that were installed with this release 139 // link dependant packages that were installed with this release
136 QString *pkg; 140 QString *pkg;
137 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) 141 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() )
138 { 142 {
139 emit outputText( " " ); 143 emit outputText( " " );
140 emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); 144 emit outputText( QString( "Creating symbolic links for " )+ (*pkg) );
141 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); 145 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir );
142 } 146 }
143 } 147 }
144 } 148 }
145 149
146 delete dependantPackages; 150 delete dependantPackages;
147 151
148 emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") ); 152 emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") );
149 return ret; 153 return ret;
150} 154}
151 155
152 156
153int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) 157int Ipkg :: executeIpkgCommand( QString &cmd, const QString option )
154{ 158{
155 FILE *fp = NULL; 159 FILE *fp = NULL;
156 char line[130]; 160 char line[130];
157 QString lineStr, lineStrOld; 161 QString lineStr, lineStrOld;
158 int ret = false; 162 int ret = false;
159 163
160 fp = popen( (const char *) cmd, "r"); 164 fp = popen( (const char *) cmd, "r");
161 if ( fp == NULL ) 165 if ( fp == NULL )
162 { 166 {
163 cout << "Couldn't execute " << cmd << "! err = " << fp << endl; 167 cout << "Couldn't execute " << cmd << "! err = " << fp << endl;
164 QString text; 168 QString text;
165 text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); 169 text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd );
166 emit outputText( text ); 170 emit outputText( text );
167 } 171 }
168 else 172 else
169 { 173 {
170 while ( fgets( line, sizeof line, fp) != NULL ) 174 while ( fgets( line, sizeof line, fp) != NULL )
171 { 175 {
172 lineStr = line; 176 lineStr = line;
173 lineStr=lineStr.left( lineStr.length()-1 ); 177 lineStr=lineStr.left( lineStr.length()-1 );
174 178
175 if ( lineStr != lineStrOld ) 179 if ( lineStr != lineStrOld )
176 { 180 {
177 //See if we're finished 181 //See if we're finished
178 if ( option == "install" ) 182 if ( option == "install" )
179 { 183 {
180 // Need to keep track of any dependant packages that get installed 184 // Need to keep track of any dependant packages that get installed
181 // so that we can create links to them as necessary 185 // so that we can create links to them as necessary
182 if ( lineStr.startsWith( "Installing " ) ) 186 if ( lineStr.startsWith( "Installing " ) )
183 { 187 {
184 cout << "LineStr = " << lineStr << endl; 188 cout << "LineStr = " << lineStr << endl;
185 int start = lineStr.find( " " ) + 1; 189 int start = lineStr.find( " " ) + 1;
186 int end = lineStr.find( " ", start ); 190 int end = lineStr.find( " ", start );
187 QString *package = new QString( lineStr.mid( start, end-start ) ); 191 QString *package = new QString( lineStr.mid( start, end-start ) );
188 dependantPackages->append( package ); 192 dependantPackages->append( package );
189 cout << "installing dependant package <" << *package << ">" << endl; 193 cout << "installing dependant package <" << *package << ">" << endl;
190 } 194 }
191 } 195 }
192 196
193 if ( option == "update" ) 197 if ( option == "update" )
194 { 198 {
195 if (lineStr.contains("Updated list")) 199 if (lineStr.contains("Updated list"))
196 ret = true; 200 ret = true;
197 } 201 }
198 else if ( option == "download" ) 202 else if ( option == "download" )
199 { 203 {
200 if (lineStr.contains("Downloaded")) 204 if (lineStr.contains("Downloaded"))
201 ret = true; 205 ret = true;
202 } 206 }
203 else 207 else
204 { 208 {
205 if (lineStr.contains("Done")) 209 if (lineStr.contains("Done"))
206 ret = true; 210 ret = true;
207 } 211 }
208 212
209 emit outputText( lineStr ); 213 emit outputText( lineStr );
210 } 214 }
211 lineStrOld = lineStr; 215 lineStrOld = lineStr;
212 qApp->processEvents(); 216 qApp->processEvents();
213 } 217 }
214 pclose(fp); 218 pclose(fp);
215 } 219 }
216 220
217 return ret; 221 return ret;
218} 222}
219 223
220 224
221void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) 225void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir )
222{ 226{
223 if ( dest == "root" || dest == "/" ) 227 if ( dest == "root" || dest == "/" )
224 return; 228 return;
225 229
226 qApp->processEvents(); 230 qApp->processEvents();
227 QStringList *fileList = getList( packFileName, destDir ); 231 QStringList *fileList = getList( packFileName, destDir );
228 qApp->processEvents(); 232 qApp->processEvents();
229 processFileList( fileList, destDir ); 233 processFileList( fileList, destDir );
230 delete fileList; 234 delete fileList;
231} 235}
232 236
233QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) 237QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir )
234{ 238{
235 QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list"; 239 QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list";
236 QFile f( packageFileDir ); 240 QFile f( packageFileDir );
237 241
238 cout << "Try to open " << packageFileDir.latin1() << endl; 242 cout << "Try to open " << packageFileDir.latin1() << endl;
239 if ( !f.open(IO_ReadOnly) ) 243 if ( !f.open(IO_ReadOnly) )
240 { 244 {
241 // Couldn't open from dest, try from / 245 // Couldn't open from dest, try from /
242// cout << "Could not open:" << packageFileDir << endl; 246// cout << "Could not open:" << packageFileDir << endl;
243 f.close(); 247 f.close();
244 248
245 packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; 249 packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list";
246 f.setName( packageFileDir ); 250 f.setName( packageFileDir );
247// cout << "Try to open " << packageFileDir.latin1() << endl; 251// cout << "Try to open " << packageFileDir.latin1() << endl;
248 if ( ! f.open(IO_ReadOnly) ) 252 if ( ! f.open(IO_ReadOnly) )
249 { 253 {
250 cout << "Could not open:" << packageFileDir << endl; 254 cout << "Could not open:" << packageFileDir << endl;
251 emit outputText( QString( "Could not open :" ) + packageFileDir ); 255 emit outputText( QString( "Could not open :" ) + packageFileDir );
252 return (QStringList*)0; 256 return (QStringList*)0;
253 } 257 }
254 } 258 }
255 QStringList *fileList = new QStringList(); 259 QStringList *fileList = new QStringList();
256 QTextStream t( &f ); 260 QTextStream t( &f );
257 while ( !t.eof() ) 261 while ( !t.eof() )
258 *fileList += t.readLine(); 262 *fileList += t.readLine();
259 263
260 f.close(); 264 f.close();
261 return fileList; 265 return fileList;
262} 266}
263 267
264void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) 268void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir )
265{ 269{
266 if ( !fileList || fileList->isEmpty() ) 270 if ( !fileList || fileList->isEmpty() )
267 return; 271 return;
268 272
269 QString baseDir = ROOT; 273 QString baseDir = ROOT;
270 274
271 if ( createLinks == true ) 275 if ( createLinks == true )
272 { 276 {
273 for ( uint i=0; i < fileList->count(); i++ ) 277 for ( uint i=0; i < fileList->count(); i++ )
274 { 278 {
275 processLinkDir( (*fileList)[i], baseDir, destDir ); 279 processLinkDir( (*fileList)[i], baseDir, destDir );
276 qApp->processEvents(); 280 qApp->processEvents();
277 } 281 }
278 } 282 }
279 else 283 else
280 { 284 {
281 for ( int i = fileList->count()-1; i >= 0 ; i-- ) 285 for ( int i = fileList->count()-1; i >= 0 ; i-- )
282 { 286 {
283 cout << "i = " << i << ", Dealing with " << (*fileList)[i] << endl; 287 cout << "i = " << i << ", Dealing with " << (*fileList)[i] << endl;
284 processLinkDir( (*fileList)[i], baseDir, destDir ); 288 processLinkDir( (*fileList)[i], baseDir, destDir );
285 qApp->processEvents(); 289 qApp->processEvents();
286 } 290 }
287 } 291 }
288} 292}
289 293
290void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) 294void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir )
291{ 295{
292 QString sourceFile = baseDir + file; 296 QString sourceFile = baseDir + file;
293 QString linkFile = destDir + file; 297 QString linkFile = destDir + file;
294 QString text; 298 QString text;
295 if ( createLinks ) 299 if ( createLinks )
296 { 300 {
297 // If this file is a directory (ends with a /) and it doesn't exist, 301 // If this file is a directory (ends with a /) and it doesn't exist,
298 // we need to create it 302 // we need to create it
299 if ( file.right(1) == "/" ) 303 if ( file.right(1) == "/" )
300 { 304 {
301 QFileInfo f( linkFile ); 305 QFileInfo f( linkFile );
302 if ( !f.exists() ) 306 if ( !f.exists() )
303 { 307 {
304 emit outputText( QString( "Creating directory " ) + linkFile ); 308 emit outputText( QString( "Creating directory " ) + linkFile );
305 QDir d; 309 QDir d;
306 d.mkdir( linkFile, true ); 310 d.mkdir( linkFile, true );
307 } 311 }
308 else 312 else
309 emit outputText( QString( "Directory " ) + linkFile + " exists" ); 313 emit outputText( QString( "Directory " ) + linkFile + " exists" );
310 314
311 } 315 }
312 else 316 else
313 { 317 {
314 int rc = symlink( sourceFile, linkFile ); 318 int rc = symlink( sourceFile, linkFile );
315 text = (rc == 0 ? "Linked " : "Failed to link "); 319 text = (rc == 0 ? "Linked " : "Failed to link ");
316 text += sourceFile + " to " + linkFile; 320 text += sourceFile + " to " + linkFile;
317 emit outputText( text ); 321 emit outputText( text );
318 } 322 }
319 } 323 }
320 else 324 else
321 { 325 {
322 QFileInfo f( linkFile ); 326 QFileInfo f( linkFile );
323 if ( f.exists() ) 327 if ( f.exists() )
324 { 328 {
325 if ( f.isFile() ) 329 if ( f.isFile() )
326 { 330 {
327 QFile f( linkFile ); 331 QFile f( linkFile );
328 bool rc = f.remove(); 332 bool rc = f.remove();
329 333
330 text = (rc ? "Removed " : "Failed to remove "); 334 text = (rc ? "Removed " : "Failed to remove ");
331 text += linkFile; 335 text += linkFile;
332 emit outputText( text ); 336 emit outputText( text );
333 } 337 }
334 else if ( f.isDir() ) 338 else if ( f.isDir() )
335 { 339 {
336 QDir d; 340 QDir d;
337 bool rc = d.rmdir( linkFile, true ); 341 bool rc = d.rmdir( linkFile, true );
338 text = (rc ? "Removed " : "Failed to remove "); 342 text = (rc ? "Removed " : "Failed to remove ");
339 text += linkFile; 343 text += linkFile;
340 emit outputText( text ); 344 emit outputText( text );
341 } 345 }
342 } 346 }
343 } 347 }
344 348
345} 349}