summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/ipkg.cpp4
1 files changed, 1 insertions, 3 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp
index eacef76..368548b 100644
--- a/noncore/settings/aqpkg/ipkg.cpp
+++ b/noncore/settings/aqpkg/ipkg.cpp
@@ -1,369 +1,367 @@
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, reinstall 44// Option is what we are going to do - install, upgrade, download, reinstall
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" && option != "upgrade" ) 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#ifdef X86 94#ifdef X86
95 cmd += " -f "; 95 cmd += " -f ";
96 cmd += IPKG_CONF; 96 cmd += IPKG_CONF;
97#endif 97#endif
98 98
99 99
100 if ( option == "reinstall" ) 100 if ( option == "reinstall" )
101 cmd += " install"; 101 cmd += " install";
102 else 102 else
103 cmd += " " + option; 103 cmd += " " + option;
104 if ( option != "upgrade" ) 104 if ( option != "upgrade" )
105 cmd += " " + package; 105 cmd += " " + package;
106 cmd += " 2>&1"; 106 cmd += " 2>&1";
107 107
108 108
109 if ( package != "" ) 109 if ( package != "" )
110 emit outputText( QString( "Dealing with package " ) + package ); 110 emit outputText( QString( "Dealing with package " ) + package );
111 111
112 qApp->processEvents(); 112 qApp->processEvents();
113 113
114 // If we are removing packages and make links option is selected 114 // If we are removing packages and make links option is selected
115 // create the links 115 // create the links
116 if ( option == "remove" || option == "reinstall" ) 116 if ( option == "remove" || option == "reinstall" )
117 { 117 {
118 createLinks = false; 118 createLinks = false;
119 if ( flags & MAKE_LINKS ) 119 if ( flags & MAKE_LINKS )
120 { 120 {
121 emit outputText( QString( "Removing symbolic links...\n" ) ); 121 emit outputText( QString( "Removing symbolic links...\n" ) );
122 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 122 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
123 emit outputText( QString( " " ) ); 123 emit outputText( QString( " " ) );
124 } 124 }
125 } 125 }
126 126
127 emit outputText( cmd ); 127 emit outputText( cmd );
128 128
129 // Execute command 129 // Execute command
130 dependantPackages = new QList<QString>; 130 dependantPackages = new QList<QString>;
131 dependantPackages->setAutoDelete( true ); 131 dependantPackages->setAutoDelete( true );
132 132
133 ret = executeIpkgCommand( cmd, option ); 133 ret = executeIpkgCommand( cmd, option );
134 134
135 if ( option == "install" || option == "reinstall" ) 135 if ( option == "install" || option == "reinstall" )
136 { 136 {
137 // If we are not removing packages and make links option is selected 137 // If we are not removing packages and make links option is selected
138 // create the links 138 // create the links
139 createLinks = true; 139 createLinks = true;
140 if ( flags & MAKE_LINKS ) 140 if ( flags & MAKE_LINKS )
141 { 141 {
142 emit outputText( " " ); 142 emit outputText( " " );
143 emit outputText( QString( "Creating symbolic links for " )+ package ); 143 emit outputText( QString( "Creating symbolic links for " )+ package );
144 144
145 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); 145 linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir );
146 146
147 // link dependant packages that were installed with this release 147 // link dependant packages that were installed with this release
148 QString *pkg; 148 QString *pkg;
149 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) 149 for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() )
150 { 150 {
151 if ( *pkg == package ) 151 if ( *pkg == package )
152 continue; 152 continue;
153 emit outputText( " " ); 153 emit outputText( " " );
154 emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); 154 emit outputText( QString( "Creating symbolic links for " )+ (*pkg) );
155 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); 155 linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir );
156 } 156 }
157 } 157 }
158 } 158 }
159 159
160 delete dependantPackages; 160 delete dependantPackages;
161 161
162 emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") ); 162 emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") );
163 emit outputText( "" ); 163 emit outputText( "" );
164 return ret; 164 return ret;
165} 165}
166 166
167 167
168int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) 168int Ipkg :: executeIpkgCommand( QString &cmd, const QString option )
169{ 169{
170 FILE *fp = NULL; 170 FILE *fp = NULL;
171 char line[130]; 171 char line[130];
172 QString lineStr, lineStrOld; 172 QString lineStr, lineStrOld;
173 int ret = false; 173 int ret = false;
174 174
175 fp = popen( (const char *) cmd, "r"); 175 fp = popen( (const char *) cmd, "r");
176 if ( fp == NULL ) 176 if ( fp == NULL )
177 { 177 {
178 cout << "Couldn't execute " << cmd << "! err = " << fp << endl; 178 cout << "Couldn't execute " << cmd << "! err = " << fp << endl;
179 QString text; 179 QString text;
180 text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); 180 text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd );
181 emit outputText( text ); 181 emit outputText( text );
182 } 182 }
183 else 183 else
184 { 184 {
185 while ( fgets( line, sizeof line, fp) != NULL ) 185 while ( fgets( line, sizeof line, fp) != NULL )
186 { 186 {
187 lineStr = line; 187 lineStr = line;
188 lineStr=lineStr.left( lineStr.length()-1 ); 188 lineStr=lineStr.left( lineStr.length()-1 );
189 189
190 if ( lineStr != lineStrOld ) 190 if ( lineStr != lineStrOld )
191 { 191 {
192 //See if we're finished 192 //See if we're finished
193 if ( option == "install" || option == "reinstall" ) 193 if ( option == "install" || option == "reinstall" )
194 { 194 {
195 // Need to keep track of any dependant packages that get installed 195 // Need to keep track of any dependant packages that get installed
196 // so that we can create links to them as necessary 196 // so that we can create links to them as necessary
197 if ( lineStr.startsWith( "Installing " ) ) 197 if ( lineStr.startsWith( "Installing " ) )
198 { 198 {
199 cout << "LineStr = " << lineStr << endl;
200 int start = lineStr.find( " " ) + 1; 199 int start = lineStr.find( " " ) + 1;
201 int end = lineStr.find( " ", start ); 200 int end = lineStr.find( " ", start );
202 QString *package = new QString( lineStr.mid( start, end-start ) ); 201 QString *package = new QString( lineStr.mid( start, end-start ) );
203 dependantPackages->append( package ); 202 dependantPackages->append( package );
204 cout << "installing dependant package <" << *package << ">" << endl;
205 } 203 }
206 } 204 }
207 205
208 if ( option == "update" ) 206 if ( option == "update" )
209 { 207 {
210 if (lineStr.contains("Updated list")) 208 if (lineStr.contains("Updated list"))
211 ret = true; 209 ret = true;
212 } 210 }
213 else if ( option == "download" ) 211 else if ( option == "download" )
214 { 212 {
215 if (lineStr.contains("Downloaded")) 213 if (lineStr.contains("Downloaded"))
216 ret = true; 214 ret = true;
217 } 215 }
218 else 216 else
219 { 217 {
220 if (lineStr.contains("Done")) 218 if (lineStr.contains("Done"))
221 ret = true; 219 ret = true;
222 } 220 }
223 221
224 emit outputText( lineStr ); 222 emit outputText( lineStr );
225 } 223 }
226 lineStrOld = lineStr; 224 lineStrOld = lineStr;
227 qApp->processEvents(); 225 qApp->processEvents();
228 } 226 }
229 pclose(fp); 227 pclose(fp);
230 } 228 }
231 229
232 return ret; 230 return ret;
233} 231}
234 232
235 233
236void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) 234void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir )
237{ 235{
238 if ( dest == "root" || dest == "/" ) 236 if ( dest == "root" || dest == "/" )
239 return; 237 return;
240 238
241 qApp->processEvents(); 239 qApp->processEvents();
242 QStringList *fileList = getList( packFileName, destDir ); 240 QStringList *fileList = getList( packFileName, destDir );
243 qApp->processEvents(); 241 qApp->processEvents();
244 processFileList( fileList, destDir ); 242 processFileList( fileList, destDir );
245 delete fileList; 243 delete fileList;
246} 244}
247 245
248QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) 246QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir )
249{ 247{
250 QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list"; 248 QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list";
251 QFile f( packageFileDir ); 249 QFile f( packageFileDir );
252 250
253 cout << "Try to open " << packageFileDir << endl; 251 cout << "Try to open " << packageFileDir << endl;
254 if ( !f.open(IO_ReadOnly) ) 252 if ( !f.open(IO_ReadOnly) )
255 { 253 {
256 // Couldn't open from dest, try from / 254 // Couldn't open from dest, try from /
257 cout << "Could not open:" << packageFileDir << endl; 255 cout << "Could not open:" << packageFileDir << endl;
258 f.close(); 256 f.close();
259 257
260 packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; 258 packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list";
261 f.setName( packageFileDir ); 259 f.setName( packageFileDir );
262// cout << "Try to open " << packageFileDir.latin1() << endl; 260// cout << "Try to open " << packageFileDir.latin1() << endl;
263 if ( ! f.open(IO_ReadOnly) ) 261 if ( ! f.open(IO_ReadOnly) )
264 { 262 {
265 cout << "Could not open:" << packageFileDir << endl; 263 cout << "Could not open:" << packageFileDir << endl;
266 emit outputText( QString( "Could not open :" ) + packageFileDir ); 264 emit outputText( QString( "Could not open :" ) + packageFileDir );
267 return (QStringList*)0; 265 return (QStringList*)0;
268 } 266 }
269 } 267 }
270 QStringList *fileList = new QStringList(); 268 QStringList *fileList = new QStringList();
271 QTextStream t( &f ); 269 QTextStream t( &f );
272 while ( !t.eof() ) 270 while ( !t.eof() )
273 *fileList += t.readLine(); 271 *fileList += t.readLine();
274 272
275 f.close(); 273 f.close();
276 return fileList; 274 return fileList;
277} 275}
278 276
279void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) 277void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir )
280{ 278{
281 if ( !fileList || fileList->isEmpty() ) 279 if ( !fileList || fileList->isEmpty() )
282 return; 280 return;
283 281
284 QString baseDir = ROOT; 282 QString baseDir = ROOT;
285 283
286 if ( createLinks == true ) 284 if ( createLinks == true )
287 { 285 {
288 for ( uint i=0; i < fileList->count(); i++ ) 286 for ( uint i=0; i < fileList->count(); i++ )
289 { 287 {
290 processLinkDir( (*fileList)[i], baseDir, destDir ); 288 processLinkDir( (*fileList)[i], baseDir, destDir );
291 qApp->processEvents(); 289 qApp->processEvents();
292 } 290 }
293 } 291 }
294 else 292 else
295 { 293 {
296 for ( int i = fileList->count()-1; i >= 0 ; i-- ) 294 for ( int i = fileList->count()-1; i >= 0 ; i-- )
297 { 295 {
298 processLinkDir( (*fileList)[i], baseDir, destDir ); 296 processLinkDir( (*fileList)[i], baseDir, destDir );
299 qApp->processEvents(); 297 qApp->processEvents();
300 } 298 }
301 } 299 }
302} 300}
303 301
304void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) 302void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir )
305{ 303{
306 304
307 QString sourceFile = baseDir + file; 305 QString sourceFile = baseDir + file;
308 306
309 QString linkFile = destDir; 307 QString linkFile = destDir;
310 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) 308 if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" )
311 { 309 {
312 linkFile += file.mid( 1 ); 310 linkFile += file.mid( 1 );
313 } 311 }
314 else 312 else
315 { 313 {
316 linkFile += file; 314 linkFile += file;
317 } 315 }
318 QString text; 316 QString text;
319 if ( createLinks ) 317 if ( createLinks )
320 { 318 {
321 // If this file is a directory (ends with a /) and it doesn't exist, 319 // If this file is a directory (ends with a /) and it doesn't exist,
322 // we need to create it 320 // we need to create it
323 if ( file.right(1) == "/" ) 321 if ( file.right(1) == "/" )
324 { 322 {
325 QFileInfo f( linkFile ); 323 QFileInfo f( linkFile );
326 if ( !f.exists() ) 324 if ( !f.exists() )
327 { 325 {
328 emit outputText( QString( "Creating directory " ) + linkFile ); 326 emit outputText( QString( "Creating directory " ) + linkFile );
329 QDir d; 327 QDir d;
330 d.mkdir( linkFile, true ); 328 d.mkdir( linkFile, true );
331 } 329 }
332 else 330 else
333 emit outputText( QString( "Directory " ) + linkFile + " exists" ); 331 emit outputText( QString( "Directory " ) + linkFile + " exists" );
334 332
335 } 333 }
336 else 334 else
337 { 335 {
338 int rc = symlink( sourceFile, linkFile ); 336 int rc = symlink( sourceFile, linkFile );
339 text = (rc == 0 ? "Linked " : "Failed to link "); 337 text = (rc == 0 ? "Linked " : "Failed to link ");
340 text += sourceFile + " to " + linkFile; 338 text += sourceFile + " to " + linkFile;
341 emit outputText( text ); 339 emit outputText( text );
342 } 340 }
343 } 341 }
344 else 342 else
345 { 343 {
346 QFileInfo f( linkFile ); 344 QFileInfo f( linkFile );
347 if ( f.exists() ) 345 if ( f.exists() )
348 { 346 {
349 if ( f.isFile() ) 347 if ( f.isFile() )
350 { 348 {
351 QFile f( linkFile ); 349 QFile f( linkFile );
352 bool rc = f.remove(); 350 bool rc = f.remove();
353 351
354 text = (rc ? "Removed " : "Failed to remove "); 352 text = (rc ? "Removed " : "Failed to remove ");
355 text += linkFile; 353 text += linkFile;
356 emit outputText( text ); 354 emit outputText( text );
357 } 355 }
358 else if ( f.isDir() ) 356 else if ( f.isDir() )
359 { 357 {
360 QDir d; 358 QDir d;
361 bool rc = d.rmdir( linkFile, true ); 359 bool rc = d.rmdir( linkFile, true );
362 text = (rc ? "Removed " : "Failed to remove "); 360 text = (rc ? "Removed " : "Failed to remove ");
363 text += linkFile; 361 text += linkFile;
364 emit outputText( text ); 362 emit outputText( text );
365 } 363 }
366 } 364 }
367 } 365 }
368 366
369} 367}