-rw-r--r-- | noncore/settings/aqpkg/global.h | 2 | ||||
-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 121 | ||||
-rw-r--r-- | noncore/settings/aqpkg/ipkg.h | 18 |
3 files changed, 110 insertions, 31 deletions
diff --git a/noncore/settings/aqpkg/global.h b/noncore/settings/aqpkg/global.h index e1a4ed4..cec9aa5 100644 --- a/noncore/settings/aqpkg/global.h +++ b/noncore/settings/aqpkg/global.h | |||
@@ -1,80 +1,80 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | global.h - description | 2 | global.h - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Aug 26 2002 | 4 | begin : Mon Aug 26 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 | #ifndef __GLOBAL_H | 18 | #ifndef __GLOBAL_H |
19 | #define __GLOBAL_H | 19 | #define __GLOBAL_H |
20 | 20 | ||
21 | #define VERSION_TEXT "AQPkg Version 1.5" | 21 | #define VERSION_TEXT "AQPkg Version 1.6 BETA" |
22 | 22 | ||
23 | // Uncomment the below line to run on a Linux box rather than a Zaurus | 23 | // Uncomment the below line to run on a Linux box rather than a Zaurus |
24 | // box this allows you to change where root is, and where to load config files from | 24 | // box this allows you to change where root is, and where to load config files from |
25 | // #define X86 | 25 | // #define X86 |
26 | 26 | ||
27 | // Sets up location of ipkg.conf and root directory | 27 | // Sets up location of ipkg.conf and root directory |
28 | #ifdef QWS | 28 | #ifdef QWS |
29 | 29 | ||
30 | #ifndef X86 | 30 | #ifndef X86 |
31 | 31 | ||
32 | // Running QT/Embedded on an arm processor | 32 | // Running QT/Embedded on an arm processor |
33 | #define IPKG_CONF "/etc/ipkg.conf" | 33 | #define IPKG_CONF "/etc/ipkg.conf" |
34 | #define ROOT "/" | 34 | #define ROOT "/" |
35 | #define IPKG_DIR "/usr/lib/ipkg/" | 35 | #define IPKG_DIR "/usr/lib/ipkg/" |
36 | 36 | ||
37 | #else | 37 | #else |
38 | 38 | ||
39 | // Running QT/Embedded on a X86 linux box | 39 | // Running QT/Embedded on a X86 linux box |
40 | #define IPKG_CONF "/home/andy/projects/aqpkg/aqpkg/data/ipkg.conf" | 40 | #define IPKG_CONF "/home/andy/projects/aqpkg/aqpkg/data/ipkg.conf" |
41 | #define ROOT "/home/andy/projects/aqpkg/aqpkg/data/root" | 41 | #define ROOT "/home/andy/projects/aqpkg/aqpkg/data/root" |
42 | #define IPKG_DIR "/home/andy/projects/aqpkg/aqpkg/data/" | 42 | #define IPKG_DIR "/home/andy/projects/aqpkg/aqpkg/data/" |
43 | 43 | ||
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | #else | 46 | #else |
47 | 47 | ||
48 | // Running QT on a X86 linux box | 48 | // Running QT on a X86 linux box |
49 | #define IPKG_CONF "/home/andy/projects/aqpkg/aqpkg/data/ipkg.conf" | 49 | #define IPKG_CONF "/home/andy/projects/aqpkg/aqpkg/data/ipkg.conf" |
50 | #define ROOT "/home/andy/projects/aqpkg/aqpkg/data/root" | 50 | #define ROOT "/home/andy/projects/aqpkg/aqpkg/data/root" |
51 | #define IPKG_DIR "/home/andy/projects/aqpkg/aqpkg/data/" | 51 | #define IPKG_DIR "/home/andy/projects/aqpkg/aqpkg/data/" |
52 | 52 | ||
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | 55 | ||
56 | // Uncomment the below line to turn on memory checking | 56 | // Uncomment the below line to turn on memory checking |
57 | //#define _DEBUG 1 | 57 | //#define _DEBUG 1 |
58 | 58 | ||
59 | #ifndef __MEMFILE_C | 59 | #ifndef __MEMFILE_C |
60 | #ifdef _DEBUG | 60 | #ifdef _DEBUG |
61 | void * operator new(unsigned int size,const char *file, int line); | 61 | void * operator new(unsigned int size,const char *file, int line); |
62 | void operator delete(void *p); | 62 | void operator delete(void *p); |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | #ifdef _DEBUG | 65 | #ifdef _DEBUG |
66 | #define DEBUG_NEW new(__FILE__, __LINE__) | 66 | #define DEBUG_NEW new(__FILE__, __LINE__) |
67 | //#define DEBUG_NEW new | 67 | //#define DEBUG_NEW new |
68 | #else | 68 | #else |
69 | #define DEBUG_NEW new | 69 | #define DEBUG_NEW new |
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | #define new DEBUG_NEW | 72 | #define new DEBUG_NEW |
73 | #endif | 73 | #endif |
74 | 74 | ||
75 | 75 | ||
76 | void AddTrack(long addr, long asize, const char *fname, long lnum); | 76 | void AddTrack(long addr, long asize, const char *fname, long lnum); |
77 | void RemoveTrack(long addr); | 77 | void RemoveTrack(long addr); |
78 | void DumpUnfreed(); | 78 | void DumpUnfreed(); |
79 | 79 | ||
80 | #endif | 80 | #endif |
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp index dad34b0..1efe030 100644 --- a/noncore/settings/aqpkg/ipkg.cpp +++ b/noncore/settings/aqpkg/ipkg.cpp | |||
@@ -1,450 +1,517 @@ | |||
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> |
19 | #include <iostream> | 19 | #include <iostream> |
20 | #include <vector> | 20 | #include <vector> |
21 | using namespace std; | 21 | using namespace std; |
22 | 22 | ||
23 | #include <stdio.h> | 23 | #include <stdio.h> |
24 | #include <unistd.h> | 24 | #include <unistd.h> |
25 | 25 | ||
26 | #ifdef QWS | 26 | #ifdef QWS |
27 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
28 | #else | 28 | #else |
29 | #include <qapplication.h> | 29 | #include <qapplication.h> |
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> | ||
35 | |||
34 | #include "utils.h" | 36 | #include "utils.h" |
35 | #include "ipkg.h" | 37 | #include "ipkg.h" |
36 | #include "global.h" | 38 | #include "global.h" |
37 | 39 | ||
38 | Ipkg :: Ipkg() | 40 | Ipkg :: Ipkg() |
39 | { | 41 | { |
40 | } | 42 | } |
41 | 43 | ||
42 | Ipkg :: ~Ipkg() | 44 | Ipkg :: ~Ipkg() |
43 | { | 45 | { |
44 | } | 46 | } |
45 | 47 | ||
46 | // Option is what we are going to do - install, upgrade, download, reinstall | 48 | // Option is what we are going to do - install, upgrade, download, reinstall |
47 | // package is the package name to install - either a fully qualified path and ipk | 49 | // package is the package name to install - either a fully qualified path and ipk |
48 | // file (if stored locally) or just the name of the package (for a network package) | 50 | // file (if stored locally) or just the name of the package (for a network package) |
49 | // packageName is the package name - (for a network package this will be the same as | 51 | // packageName is the package name - (for a network package this will be the same as |
50 | // package parameter) | 52 | // package parameter) |
51 | // dest is the destination alias (from ipk.conf) | 53 | // dest is the destination alias (from ipk.conf) |
52 | // destDir is the dir that the destination alias points to (used to link to root) | 54 | // destDir is the dir that the destination alias points to (used to link to root) |
53 | // flags is the ipkg options flags | 55 | // flags is the ipkg options flags |
54 | // dir is the directory to run ipkg in (defaults to "") | 56 | // dir is the directory to run ipkg in (defaults to "") |
55 | bool Ipkg :: runIpkg( ) | 57 | bool Ipkg :: runIpkg( ) |
56 | { | 58 | { |
57 | bool ret = false; | 59 | bool ret = false; |
60 | QStringList commands; | ||
58 | 61 | ||
59 | QDir::setCurrent( "/tmp" ); | 62 | QDir::setCurrent( "/tmp" ); |
60 | QString cmd = ""; | ||
61 | 63 | ||
62 | if ( runtimeDir != "" ) | 64 | if ( runtimeDir != "" ) |
63 | { | 65 | { |
64 | cmd += "cd "; | 66 | commands << "cd "; |
65 | cmd += runtimeDir; | 67 | commands << runtimeDir; |
66 | cmd += " ; "; | 68 | commands << ";"; |
67 | } | 69 | } |
68 | cmd += "ipkg -force-defaults"; | 70 | commands << "ipkg" << "-force-defaults"; |
69 | 71 | ||
70 | // only set the destination for an install operation | 72 | // only set the destination for an install operation |
71 | if ( option == "install" ) | 73 | if ( option == "install" ) |
72 | cmd += " -dest "+ destination; | 74 | commands << "-dest" << destination; |
73 | 75 | ||
74 | 76 | ||
75 | if ( option != "update" && option != "download" ) | 77 | if ( option != "update" && option != "download" ) |
76 | { | 78 | { |
77 | if ( flags & FORCE_DEPENDS ) | 79 | if ( flags & FORCE_DEPENDS ) |
78 | cmd += " -force-depends"; | 80 | commands << "-force-depends"; |
79 | if ( flags & FORCE_REINSTALL ) | 81 | if ( flags & FORCE_REINSTALL ) |
80 | cmd += " -force-reinstall"; | 82 | commands << "-force-reinstall"; |
81 | if ( flags & FORCE_REMOVE ) | 83 | if ( flags & FORCE_REMOVE ) |
82 | cmd += " -force-removal-of-essential-packages"; | 84 | commands << "-force-removal-of-essential-packages"; |
83 | if ( flags & FORCE_OVERWRITE ) | 85 | if ( flags & FORCE_OVERWRITE ) |
84 | cmd += " -force-overwrite"; | 86 | commands << "-force-overwrite"; |
85 | if ( flags & VERBOSE_WGET ) | 87 | if ( flags & VERBOSE_WGET ) |
86 | cmd += " -verbose_wget"; | 88 | commands << "-verbose_wget"; |
87 | 89 | ||
88 | // Handle make links | 90 | // Handle make links |
89 | // Rules - If make links is switched on, create links to root | 91 | // Rules - If make links is switched on, create links to root |
90 | // if destDir is NOT / | 92 | // if destDir is NOT / |
91 | if ( flags & MAKE_LINKS ) | 93 | if ( flags & MAKE_LINKS ) |
92 | { | 94 | { |
93 | // If destDir == / turn off make links as package is being insalled | 95 | // If destDir == / turn off make links as package is being insalled |
94 | // to root already. | 96 | // to root already. |
95 | if ( destDir == "/" ) | 97 | if ( destDir == "/" ) |
96 | flags ^= MAKE_LINKS; | 98 | flags ^= MAKE_LINKS; |
97 | } | 99 | } |
98 | } | 100 | } |
99 | 101 | ||
100 | #ifdef X86 | 102 | #ifdef X86 |
101 | cmd += " -f "; | 103 | commands << "-f"; |
102 | cmd += IPKG_CONF; | 104 | commands << IPKG_CONF; |
103 | #endif | 105 | #endif |
104 | 106 | ||
105 | 107 | ||
106 | if ( option == "reinstall" ) | 108 | if ( option == "reinstall" ) |
107 | cmd += " install"; | 109 | commands << "install"; |
108 | else | 110 | else |
109 | cmd += " " + option; | 111 | commands << option; |
110 | if ( package != "" ) | 112 | if ( package != "" ) |
111 | cmd += " " + package; | 113 | commands << package; |
112 | cmd += " 2>&1"; | ||
113 | 114 | ||
114 | 115 | ||
115 | if ( package != "" ) | 116 | if ( package != "" ) |
116 | emit outputText( QString( "Dealing with package " ) + package ); | 117 | emit outputText( QString( "Dealing with package " ) + package ); |
117 | 118 | ||
118 | qApp->processEvents(); | 119 | qApp->processEvents(); |
119 | 120 | ||
120 | // If we are removing packages and make links option is selected | 121 | // If we are removing packages and make links option is selected |
121 | // create the links | 122 | // create the links |
122 | if ( option == "remove" || option == "reinstall" ) | 123 | if ( option == "remove" || option == "reinstall" ) |
123 | { | 124 | { |
124 | createLinks = false; | 125 | createLinks = false; |
125 | if ( flags & MAKE_LINKS ) | 126 | if ( flags & MAKE_LINKS ) |
126 | { | 127 | { |
127 | emit outputText( QString( "Removing symbolic links...\n" ) ); | 128 | emit outputText( QString( "Removing symbolic links...\n" ) ); |
128 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 129 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
129 | emit outputText( QString( " " ) ); | 130 | emit outputText( QString( " " ) ); |
130 | } | 131 | } |
131 | } | 132 | } |
132 | 133 | ||
133 | emit outputText( cmd ); | ||
134 | |||
135 | // Execute command | 134 | // Execute command |
136 | dependantPackages = new QList<QString>; | 135 | dependantPackages = new QList<QString>; |
137 | dependantPackages->setAutoDelete( true ); | 136 | dependantPackages->setAutoDelete( true ); |
138 | 137 | ||
139 | ret = executeIpkgCommand( cmd, option ); | 138 | ret = executeIpkgCommand( commands, option ); |
140 | 139 | ||
141 | if ( option == "install" || option == "reinstall" ) | 140 | if ( option == "install" || option == "reinstall" ) |
142 | { | 141 | { |
143 | // If we are not removing packages and make links option is selected | 142 | // If we are not removing packages and make links option is selected |
144 | // create the links | 143 | // create the links |
145 | createLinks = true; | 144 | createLinks = true; |
146 | if ( flags & MAKE_LINKS ) | 145 | if ( flags & MAKE_LINKS ) |
147 | { | 146 | { |
148 | emit outputText( " " ); | 147 | emit outputText( " " ); |
149 | emit outputText( QString( "Creating symbolic links for " )+ package ); | 148 | emit outputText( QString( "Creating symbolic links for " )+ package ); |
150 | 149 | ||
151 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 150 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
152 | 151 | ||
153 | // link dependant packages that were installed with this release | 152 | // link dependant packages that were installed with this release |
154 | QString *pkg; | 153 | QString *pkg; |
155 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) | 154 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) |
156 | { | 155 | { |
157 | if ( *pkg == package ) | 156 | if ( *pkg == package ) |
158 | continue; | 157 | continue; |
159 | emit outputText( " " ); | 158 | emit outputText( " " ); |
160 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); | 159 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); |
161 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); | 160 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); |
162 | } | 161 | } |
163 | } | 162 | } |
164 | } | 163 | } |
165 | 164 | ||
166 | delete dependantPackages; | 165 | delete dependantPackages; |
167 | 166 | ||
168 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file | 167 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file |
169 | // to workaround an ipkg bug which stops reinstall to a different location | 168 | // to workaround an ipkg bug which stops reinstall to a different location |
170 | if ( option == "remove" ) | 169 | if ( option == "remove" ) |
171 | removeStatusEntry(); | 170 | removeStatusEntry(); |
172 | |||
173 | 171 | ||
174 | // emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") ); | 172 | |
175 | emit outputText( "Finished" ); | 173 | emit outputText( "Finished" ); |
176 | emit outputText( "" ); | 174 | emit outputText( "" ); |
177 | return ret; | 175 | return ret; |
176 | |||
178 | } | 177 | } |
179 | 178 | ||
180 | void Ipkg :: removeStatusEntry() | 179 | void Ipkg :: removeStatusEntry() |
181 | { | 180 | { |
182 | QString statusFile = destDir; | 181 | QString statusFile = destDir; |
183 | if ( statusFile.right( 1 ) != "/" ) | 182 | if ( statusFile.right( 1 ) != "/" ) |
184 | statusFile += "/"; | 183 | statusFile += "/"; |
185 | statusFile += "usr/lib/ipkg/status"; | 184 | statusFile += "usr/lib/ipkg/status"; |
186 | QString outStatusFile = statusFile + ".tmp"; | 185 | QString outStatusFile = statusFile + ".tmp"; |
187 | 186 | ||
188 | emit outputText( "" ); | 187 | emit outputText( "" ); |
189 | emit outputText( "Removing status entry..." ); | 188 | emit outputText( "Removing status entry..." ); |
190 | emit outputText( QString( "status file - " )+ statusFile ); | 189 | emit outputText( QString( "status file - " )+ statusFile ); |
191 | emit outputText( QString( "package - " )+ package ); | 190 | emit outputText( QString( "package - " )+ package ); |
192 | 191 | ||
193 | ifstream in( statusFile ); | 192 | ifstream in( statusFile ); |
194 | ofstream out( outStatusFile ); | 193 | ofstream out( outStatusFile ); |
195 | if ( !in.is_open() ) | 194 | if ( !in.is_open() ) |
196 | { | 195 | { |
197 | emit outputText( QString( "Couldn't open status file - " )+ statusFile ); | 196 | emit outputText( QString( "Couldn't open status file - " )+ statusFile ); |
198 | return; | 197 | return; |
199 | } | 198 | } |
200 | 199 | ||
201 | if ( !out.is_open() ) | 200 | if ( !out.is_open() ) |
202 | { | 201 | { |
203 | emit outputText( QString( "Couldn't create tempory status file - " )+ outStatusFile ); | 202 | emit outputText( QString( "Couldn't create tempory status file - " )+ outStatusFile ); |
204 | return; | 203 | return; |
205 | } | 204 | } |
206 | 205 | ||
207 | char line[1001]; | 206 | char line[1001]; |
208 | char k[21]; | 207 | char k[21]; |
209 | char v[1001]; | 208 | char v[1001]; |
210 | QString key; | 209 | QString key; |
211 | QString value; | 210 | QString value; |
212 | vector<QString> lines; | 211 | vector<QString> lines; |
213 | do | 212 | do |
214 | { | 213 | { |
215 | in.getline( line, 1000 ); | 214 | in.getline( line, 1000 ); |
216 | if ( in.eof() ) | 215 | if ( in.eof() ) |
217 | continue; | 216 | continue; |
218 | 217 | ||
219 | k[0] = '\0'; | 218 | k[0] = '\0'; |
220 | v[0] = '\0'; | 219 | v[0] = '\0'; |
221 | 220 | ||
222 | sscanf( line, "%[^:]: %[^\n]", k, v ); | 221 | sscanf( line, "%[^:]: %[^\n]", k, v ); |
223 | key = k; | 222 | key = k; |
224 | value = v; | 223 | value = v; |
225 | key = key.stripWhiteSpace(); | 224 | key = key.stripWhiteSpace(); |
226 | value = value.stripWhiteSpace(); | 225 | value = value.stripWhiteSpace(); |
227 | if ( key == "Package" && value == package ) | 226 | if ( key == "Package" && value == package ) |
228 | { | 227 | { |
229 | // Ignore all lines up to next empty | 228 | // Ignore all lines up to next empty |
230 | do | 229 | do |
231 | { | 230 | { |
232 | in.getline( line, 1000 ); | 231 | in.getline( line, 1000 ); |
233 | if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) | 232 | if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) |
234 | continue; | 233 | continue; |
235 | } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); | 234 | } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); |
236 | } | 235 | } |
237 | 236 | ||
238 | lines.push_back( QString( line ) ); | 237 | lines.push_back( QString( line ) ); |
239 | // out << line << endl; | 238 | // out << line << endl; |
240 | } while ( !in.eof() ); | 239 | } while ( !in.eof() ); |
241 | 240 | ||
242 | // Write lines out | 241 | // Write lines out |
243 | vector<QString>::iterator it; | 242 | vector<QString>::iterator it; |
244 | for ( it = lines.begin() ; it != lines.end() ; ++it ) | 243 | for ( it = lines.begin() ; it != lines.end() ; ++it ) |
245 | { | 244 | { |
246 | cout << "Writing " << (const char *)(*it) << endl; | 245 | cout << "Writing " << (const char *)(*it) << endl; |
247 | out << (const char *)(*it) << endl; | 246 | out << (const char *)(*it) << endl; |
248 | } | 247 | } |
249 | 248 | ||
250 | in.close(); | 249 | in.close(); |
251 | out.close(); | 250 | out.close(); |
252 | 251 | ||
253 | // Remove old status file and put tmp stats file in its place | 252 | // Remove old status file and put tmp stats file in its place |
254 | remove( statusFile ); | 253 | remove( statusFile ); |
255 | rename( outStatusFile, statusFile ); | 254 | rename( outStatusFile, statusFile ); |
256 | } | 255 | } |
257 | 256 | ||
257 | int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString option ) | ||
258 | { | ||
259 | // OK we're gonna use OProcess to run this thing | ||
260 | proc = new OProcess(); | ||
261 | |||
262 | // Connect up our slots | ||
263 | connect(proc, SIGNAL(processExited(OProcess *)), | ||
264 | this, SLOT( processFinished())); | ||
265 | |||
266 | connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), | ||
267 | this, SLOT(commandStdout(OProcess *, char *, int))); | ||
268 | |||
269 | connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), | ||
270 | this, SLOT(commandStderr(OProcess *, char *, int))); | ||
271 | |||
272 | for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) | ||
273 | { | ||
274 | qDebug( "%s ", (*it).latin1() ); | ||
275 | *proc << (*it).latin1(); | ||
276 | } | ||
277 | cout << endl; | ||
278 | |||
279 | // Start the process going | ||
280 | finished = false; | ||
281 | if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) | ||
282 | { | ||
283 | emit outputText( QString( "Couldn't start ipkg process" ) ); | ||
284 | qDebug( "Couldn't start ipkg process!" ); | ||
285 | } | ||
286 | |||
287 | // Now wait for it to finish | ||
288 | while ( !finished ) | ||
289 | qApp->processEvents(); | ||
290 | } | ||
291 | |||
292 | void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) | ||
293 | { | ||
294 | qDebug("received stdout %d bytes", buflen); | ||
295 | |||
296 | QString lineStr = buffer; | ||
297 | if ( lineStr[buflen-1] == '\n' ) | ||
298 | buflen --; | ||
299 | lineStr = lineStr.left( buflen ); | ||
300 | emit outputText( lineStr ); | ||
301 | qDebug(lineStr); | ||
302 | buffer[0] = '\0'; | ||
303 | } | ||
304 | |||
305 | void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) | ||
306 | { | ||
307 | qDebug("received stderrt %d bytes", buflen); | ||
308 | |||
309 | QString lineStr = buffer; | ||
310 | if ( lineStr[buflen-1] == '\n' ) | ||
311 | buflen --; | ||
312 | lineStr=lineStr.left( buflen ); | ||
313 | emit outputText( lineStr ); | ||
314 | buffer[0] = '\0'; | ||
315 | } | ||
316 | |||
317 | void Ipkg::processFinished() | ||
318 | { | ||
319 | delete proc; | ||
320 | finished = true; | ||
321 | } | ||
322 | |||
323 | |||
258 | 324 | ||
325 | /* | ||
259 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) | 326 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) |
260 | { | 327 | { |
261 | FILE *fp = NULL; | 328 | FILE *fp = NULL; |
262 | char line[130]; | 329 | char line[130]; |
263 | QString lineStr, lineStrOld; | 330 | QString lineStr, lineStrOld; |
264 | int ret = false; | 331 | int ret = false; |
265 | 332 | ||
266 | fp = popen( (const char *) cmd, "r"); | 333 | fp = popen( (const char *) cmd, "r"); |
267 | if ( fp == NULL ) | 334 | if ( fp == NULL ) |
268 | { | 335 | { |
269 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; | 336 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; |
270 | QString text; | 337 | QString text; |
271 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); | 338 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); |
272 | emit outputText( text ); | 339 | emit outputText( text ); |
273 | } | 340 | } |
274 | else | 341 | else |
275 | { | 342 | { |
276 | while ( fgets( line, sizeof line, fp) != NULL ) | 343 | while ( fgets( line, sizeof line, fp) != NULL ) |
277 | { | 344 | { |
278 | lineStr = line; | 345 | lineStr = line; |
279 | lineStr=lineStr.left( lineStr.length()-1 ); | 346 | lineStr=lineStr.left( lineStr.length()-1 ); |
280 | 347 | ||
281 | if ( lineStr != lineStrOld ) | 348 | if ( lineStr != lineStrOld ) |
282 | { | 349 | { |
283 | //See if we're finished | 350 | //See if we're finished |
284 | if ( option == "install" || option == "reinstall" ) | 351 | if ( option == "install" || option == "reinstall" ) |
285 | { | 352 | { |
286 | // Need to keep track of any dependant packages that get installed | 353 | // Need to keep track of any dependant packages that get installed |
287 | // so that we can create links to them as necessary | 354 | // so that we can create links to them as necessary |
288 | if ( lineStr.startsWith( "Installing " ) ) | 355 | if ( lineStr.startsWith( "Installing " ) ) |
289 | { | 356 | { |
290 | int start = lineStr.find( " " ) + 1; | 357 | int start = lineStr.find( " " ) + 1; |
291 | int end = lineStr.find( " ", start ); | 358 | int end = lineStr.find( " ", start ); |
292 | QString *package = new QString( lineStr.mid( start, end-start ) ); | 359 | QString *package = new QString( lineStr.mid( start, end-start ) ); |
293 | dependantPackages->append( package ); | 360 | dependantPackages->append( package ); |
294 | } | 361 | } |
295 | } | 362 | } |
296 | 363 | ||
297 | if ( option == "update" ) | 364 | if ( option == "update" ) |
298 | { | 365 | { |
299 | if (lineStr.contains("Updated list")) | 366 | if (lineStr.contains("Updated list")) |
300 | ret = true; | 367 | ret = true; |
301 | } | 368 | } |
302 | else if ( option == "download" ) | 369 | else if ( option == "download" ) |
303 | { | 370 | { |
304 | if (lineStr.contains("Downloaded")) | 371 | if (lineStr.contains("Downloaded")) |
305 | ret = true; | 372 | ret = true; |
306 | } | 373 | } |
307 | else | 374 | else |
308 | { | 375 | { |
309 | if (lineStr.contains("Done")) | 376 | if (lineStr.contains("Done")) |
310 | ret = true; | 377 | ret = true; |
311 | } | 378 | } |
312 | 379 | ||
313 | emit outputText( lineStr ); | 380 | emit outputText( lineStr ); |
314 | } | 381 | } |
315 | lineStrOld = lineStr; | 382 | lineStrOld = lineStr; |
316 | qApp->processEvents(); | 383 | qApp->processEvents(); |
317 | } | 384 | } |
318 | pclose(fp); | 385 | pclose(fp); |
319 | } | 386 | } |
320 | 387 | ||
321 | return ret; | 388 | return ret; |
322 | } | 389 | } |
323 | 390 | */ | |
324 | 391 | ||
325 | void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) | 392 | void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) |
326 | { | 393 | { |
327 | if ( dest == "root" || dest == "/" ) | 394 | if ( dest == "root" || dest == "/" ) |
328 | return; | 395 | return; |
329 | 396 | ||
330 | qApp->processEvents(); | 397 | qApp->processEvents(); |
331 | QStringList *fileList = getList( packFileName, destDir ); | 398 | QStringList *fileList = getList( packFileName, destDir ); |
332 | qApp->processEvents(); | 399 | qApp->processEvents(); |
333 | processFileList( fileList, destDir ); | 400 | processFileList( fileList, destDir ); |
334 | delete fileList; | 401 | delete fileList; |
335 | } | 402 | } |
336 | 403 | ||
337 | QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) | 404 | QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) |
338 | { | 405 | { |
339 | QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list"; | 406 | QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list"; |
340 | QFile f( packageFileDir ); | 407 | QFile f( packageFileDir ); |
341 | 408 | ||
342 | cout << "Try to open " << packageFileDir << endl; | 409 | cout << "Try to open " << packageFileDir << endl; |
343 | if ( !f.open(IO_ReadOnly) ) | 410 | if ( !f.open(IO_ReadOnly) ) |
344 | { | 411 | { |
345 | // Couldn't open from dest, try from / | 412 | // Couldn't open from dest, try from / |
346 | cout << "Could not open:" << packageFileDir << endl; | 413 | cout << "Could not open:" << packageFileDir << endl; |
347 | f.close(); | 414 | f.close(); |
348 | 415 | ||
349 | packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; | 416 | packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; |
350 | f.setName( packageFileDir ); | 417 | f.setName( packageFileDir ); |
351 | // cout << "Try to open " << packageFileDir.latin1() << endl; | 418 | qDebug( "Try to open %s", packageFileDir.latin1() ); |
352 | if ( ! f.open(IO_ReadOnly) ) | 419 | if ( ! f.open(IO_ReadOnly) ) |
353 | { | 420 | { |
354 | cout << "Could not open:" << packageFileDir << endl; | 421 | qDebug( "Could not open: %s", packageFileDir ); |
355 | emit outputText( QString( "Could not open :" ) + packageFileDir ); | 422 | emit outputText( QString( "Could not open :" ) + packageFileDir ); |
356 | return (QStringList*)0; | 423 | return (QStringList*)0; |
357 | } | 424 | } |
358 | } | 425 | } |
359 | QStringList *fileList = new QStringList(); | 426 | QStringList *fileList = new QStringList(); |
360 | QTextStream t( &f ); | 427 | QTextStream t( &f ); |
361 | while ( !t.eof() ) | 428 | while ( !t.eof() ) |
362 | *fileList += t.readLine(); | 429 | *fileList += t.readLine(); |
363 | 430 | ||
364 | f.close(); | 431 | f.close(); |
365 | return fileList; | 432 | return fileList; |
366 | } | 433 | } |
367 | 434 | ||
368 | void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) | 435 | void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) |
369 | { | 436 | { |
370 | if ( !fileList || fileList->isEmpty() ) | 437 | if ( !fileList || fileList->isEmpty() ) |
371 | return; | 438 | return; |
372 | 439 | ||
373 | QString baseDir = ROOT; | 440 | QString baseDir = ROOT; |
374 | 441 | ||
375 | if ( createLinks == true ) | 442 | if ( createLinks == true ) |
376 | { | 443 | { |
377 | for ( uint i=0; i < fileList->count(); i++ ) | 444 | for ( uint i=0; i < fileList->count(); i++ ) |
378 | { | 445 | { |
379 | processLinkDir( (*fileList)[i], baseDir, destDir ); | 446 | processLinkDir( (*fileList)[i], baseDir, destDir ); |
380 | qApp->processEvents(); | 447 | qApp->processEvents(); |
381 | } | 448 | } |
382 | } | 449 | } |
383 | else | 450 | else |
384 | { | 451 | { |
385 | for ( int i = fileList->count()-1; i >= 0 ; i-- ) | 452 | for ( int i = fileList->count()-1; i >= 0 ; i-- ) |
386 | { | 453 | { |
387 | processLinkDir( (*fileList)[i], baseDir, destDir ); | 454 | processLinkDir( (*fileList)[i], baseDir, destDir ); |
388 | qApp->processEvents(); | 455 | qApp->processEvents(); |
389 | } | 456 | } |
390 | } | 457 | } |
391 | } | 458 | } |
392 | 459 | ||
393 | void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) | 460 | void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) |
394 | { | 461 | { |
395 | 462 | ||
396 | QString sourceFile = baseDir + file; | 463 | QString sourceFile = baseDir + file; |
397 | 464 | ||
398 | QString linkFile = destDir; | 465 | QString linkFile = destDir; |
399 | if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) | 466 | if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) |
400 | { | 467 | { |
401 | linkFile += file.mid( 1 ); | 468 | linkFile += file.mid( 1 ); |
402 | } | 469 | } |
403 | else | 470 | else |
404 | { | 471 | { |
405 | linkFile += file; | 472 | linkFile += file; |
406 | } | 473 | } |
407 | QString text; | 474 | QString text; |
408 | if ( createLinks ) | 475 | if ( createLinks ) |
409 | { | 476 | { |
410 | // If this file is a directory (ends with a /) and it doesn't exist, | 477 | // If this file is a directory (ends with a /) and it doesn't exist, |
411 | // we need to create it | 478 | // we need to create it |
412 | if ( file.right(1) == "/" ) | 479 | if ( file.right(1) == "/" ) |
413 | { | 480 | { |
414 | QFileInfo f( linkFile ); | 481 | QFileInfo f( linkFile ); |
415 | if ( !f.exists() ) | 482 | if ( !f.exists() ) |
416 | { | 483 | { |
417 | emit outputText( QString( "Creating directory " ) + linkFile ); | 484 | emit outputText( QString( "Creating directory " ) + linkFile ); |
418 | QDir d; | 485 | QDir d; |
419 | d.mkdir( linkFile, true ); | 486 | d.mkdir( linkFile, true ); |
420 | } | 487 | } |
421 | else | 488 | else |
422 | emit outputText( QString( "Directory " ) + linkFile + " already exists" ); | 489 | emit outputText( QString( "Directory " ) + linkFile + " already exists" ); |
423 | 490 | ||
424 | } | 491 | } |
425 | else | 492 | else |
426 | { | 493 | { |
427 | int rc = symlink( sourceFile, linkFile ); | 494 | int rc = symlink( sourceFile, linkFile ); |
428 | text = (rc == 0 ? "Linked " : "Failed to link "); | 495 | text = (rc == 0 ? "Linked " : "Failed to link "); |
429 | text += sourceFile + " to " + linkFile; | 496 | text += sourceFile + " to " + linkFile; |
430 | emit outputText( text ); | 497 | emit outputText( text ); |
431 | } | 498 | } |
432 | } | 499 | } |
433 | else | 500 | else |
434 | { | 501 | { |
435 | QFileInfo f( linkFile ); | 502 | QFileInfo f( linkFile ); |
436 | if ( f.exists() ) | 503 | if ( f.exists() ) |
437 | { | 504 | { |
438 | if ( f.isFile() ) | 505 | if ( f.isFile() ) |
439 | { | 506 | { |
440 | QFile f( linkFile ); | 507 | QFile f( linkFile ); |
441 | bool rc = f.remove(); | 508 | bool rc = f.remove(); |
442 | 509 | ||
443 | text = (rc ? "Removed " : "Failed to remove "); | 510 | text = (rc ? "Removed " : "Failed to remove "); |
444 | text += linkFile; | 511 | text += linkFile; |
445 | emit outputText( text ); | 512 | emit outputText( text ); |
446 | } | 513 | } |
447 | else if ( f.isDir() ) | 514 | else if ( f.isDir() ) |
448 | { | 515 | { |
449 | QDir d; | 516 | QDir d; |
450 | bool rc = d.rmdir( linkFile, true ); | 517 | bool rc = d.rmdir( linkFile, true ); |
diff --git a/noncore/settings/aqpkg/ipkg.h b/noncore/settings/aqpkg/ipkg.h index 7099ca7..25bae59 100644 --- a/noncore/settings/aqpkg/ipkg.h +++ b/noncore/settings/aqpkg/ipkg.h | |||
@@ -1,74 +1,86 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | ipkg.h - description | 2 | ipkg.h - 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 | #ifndef IPKG_H | 18 | #ifndef IPKG_H |
19 | #define IPKG_H | 19 | #define IPKG_H |
20 | 20 | ||
21 | 21 | ||
22 | /** | 22 | /** |
23 | *@author Andy Qua | 23 | *@author Andy Qua |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <qobject.h> | 26 | #include <qobject.h> |
27 | #include <qstring.h> | 27 | #include <qstring.h> |
28 | #include <qstringlist.h> | ||
28 | #include <qlist.h> | 29 | #include <qlist.h> |
29 | 30 | ||
30 | #define FORCE_DEPENDS 0x0001 | 31 | #define FORCE_DEPENDS 0x0001 |
31 | #define FORCE_REMOVE 0x0002 | 32 | #define FORCE_REMOVE 0x0002 |
32 | #define FORCE_REINSTALL 0x0004 | 33 | #define FORCE_REINSTALL 0x0004 |
33 | #define FORCE_OVERWRITE 0x0008 | 34 | #define FORCE_OVERWRITE 0x0008 |
34 | #define MAKE_LINKS 0x0010 | 35 | #define MAKE_LINKS 0x0010 |
35 | #define VERBOSE_WGET 0x0020 | 36 | #define VERBOSE_WGET 0x0020 |
36 | 37 | ||
38 | class OProcess; | ||
39 | |||
37 | class Ipkg : public QObject | 40 | class Ipkg : public QObject |
38 | { | 41 | { |
39 | Q_OBJECT | 42 | Q_OBJECT |
40 | public: | 43 | public: |
41 | Ipkg(); | 44 | Ipkg(); |
42 | ~Ipkg(); | 45 | ~Ipkg(); |
43 | bool runIpkg( ); | 46 | bool runIpkg( ); |
44 | 47 | ||
45 | void setOption( const char *opt ) { option = opt; } | 48 | void setOption( const char *opt ) { option = opt; } |
46 | void setPackage( const char *pkg ) { package = pkg; } | 49 | void setPackage( const char *pkg ) { package = pkg; } |
47 | void setDestination( const char *dest ) { destination = dest; } | 50 | void setDestination( const char *dest ) { destination = dest; } |
48 | void setDestinationDir( const char *dir ) { destDir = dir; } | 51 | void setDestinationDir( const char *dir ) { destDir = dir; } |
49 | void setFlags( int fl ) { flags = fl; } | 52 | void setFlags( int fl ) { flags = fl; } |
50 | void setRuntimeDirectory( const char *dir ) { runtimeDir = dir; } | 53 | void setRuntimeDirectory( const char *dir ) { runtimeDir = dir; } |
51 | 54 | ||
52 | signals: | 55 | signals: |
53 | void outputText( const QString &text ); | 56 | void outputText( const QString &text ); |
57 | |||
58 | public slots: | ||
59 | void commandStdout(OProcess*, char *buffer, int buflen); | ||
60 | void commandStderr(OProcess*, char *buffer, int buflen); | ||
61 | void processFinished(); | ||
62 | |||
54 | 63 | ||
55 | private: | 64 | private: |
56 | bool createLinks; | 65 | bool createLinks; |
57 | QString option; | 66 | QString option; |
58 | QString package; | 67 | QString package; |
59 | QString destination; | 68 | QString destination; |
60 | QString destDir; | 69 | QString destDir; |
61 | int flags; | ||
62 | QString runtimeDir; | 70 | QString runtimeDir; |
71 | OProcess *proc; | ||
72 | int flags; | ||
73 | bool finished; | ||
63 | 74 | ||
64 | QList<QString> *dependantPackages; | 75 | QList<QString> *dependantPackages; |
65 | 76 | ||
66 | int executeIpkgCommand( QString &cmd, const QString option ); | 77 | int executeIpkgCommand( QStringList &cmd, const QString option ); |
67 | void removeStatusEntry(); | 78 | void removeStatusEntry(); |
68 | void linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ); | 79 | void linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ); |
69 | QStringList* getList( const QString &packageFilename, const QString &destDir ); | 80 | QStringList* getList( const QString &packageFilename, const QString &destDir ); |
70 | void processFileList( const QStringList *fileList, const QString &destDir ); | 81 | void processFileList( const QStringList *fileList, const QString &destDir ); |
71 | void processLinkDir( const QString &file, const QString &baseDir, const QString &destDir ); | 82 | void processLinkDir( const QString &file, const QString &baseDir, const QString &destDir ); |
83 | |||
72 | }; | 84 | }; |
73 | 85 | ||
74 | #endif | 86 | #endif |