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