-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 82 | ||||
-rw-r--r-- | noncore/settings/aqpkg/ipkg.h | 1 |
2 files changed, 81 insertions, 2 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp index c762633..452eca3 100644 --- a/noncore/settings/aqpkg/ipkg.cpp +++ b/noncore/settings/aqpkg/ipkg.cpp | |||
@@ -51,36 +51,40 @@ Ipkg :: ~Ipkg() | |||
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 "") |
53 | bool Ipkg :: runIpkg( ) | 53 | bool 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 | |
68 | { | 68 | // only set the destination for an install operation |
69 | if ( option == "install" ) | ||
69 | cmd += " -dest "+ destination; | 70 | cmd += " -dest "+ destination; |
70 | 71 | ||
72 | |||
73 | if ( option != "update" && option != "download" ) | ||
74 | { | ||
71 | if ( flags & FORCE_DEPENDS ) | 75 | if ( flags & FORCE_DEPENDS ) |
72 | cmd += " -force-depends"; | 76 | cmd += " -force-depends"; |
73 | if ( flags & FORCE_REINSTALL ) | 77 | if ( flags & FORCE_REINSTALL ) |
74 | cmd += " -force-reinstall"; | 78 | cmd += " -force-reinstall"; |
75 | if ( flags & FORCE_REMOVE ) | 79 | if ( flags & FORCE_REMOVE ) |
76 | cmd += " -force-removal-of-essential-packages"; | 80 | cmd += " -force-removal-of-essential-packages"; |
77 | if ( flags & FORCE_OVERWRITE ) | 81 | if ( flags & FORCE_OVERWRITE ) |
78 | cmd += " -force-overwrite"; | 82 | cmd += " -force-overwrite"; |
79 | 83 | ||
80 | // Handle make links | 84 | // Handle make links |
81 | // Rules - If make links is switched on, create links to root | 85 | // Rules - If make links is switched on, create links to root |
82 | // if destDir is NOT / | 86 | // if destDir is NOT / |
83 | if ( flags & MAKE_LINKS ) | 87 | if ( flags & MAKE_LINKS ) |
84 | { | 88 | { |
85 | // If destDir == / turn off make links as package is being insalled | 89 | // If destDir == / turn off make links as package is being insalled |
86 | // to root already. | 90 | // to root already. |
@@ -143,39 +147,113 @@ bool Ipkg :: runIpkg( ) | |||
143 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); | 147 | linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); |
144 | 148 | ||
145 | // link dependant packages that were installed with this release | 149 | // link dependant packages that were installed with this release |
146 | QString *pkg; | 150 | QString *pkg; |
147 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) | 151 | for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) |
148 | { | 152 | { |
149 | if ( *pkg == package ) | 153 | if ( *pkg == package ) |
150 | continue; | 154 | continue; |
151 | emit outputText( " " ); | 155 | emit outputText( " " ); |
152 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); | 156 | emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); |
153 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); | 157 | linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); |
154 | } | 158 | } |
155 | } | 159 | } |
156 | } | 160 | } |
157 | 161 | ||
158 | delete dependantPackages; | 162 | delete dependantPackages; |
163 | |||
164 | // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file | ||
165 | // to workaround an ipkg bug which stops reinstall to a different location | ||
166 | if ( option == "remove" ) | ||
167 | removeStatusEntry(); | ||
159 | 168 | ||
169 | |||
160 | // emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") ); | 170 | // emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") ); |
161 | emit outputText( "Finished" ); | 171 | emit outputText( "Finished" ); |
162 | emit outputText( "" ); | 172 | emit outputText( "" ); |
163 | return ret; | 173 | return ret; |
164 | } | 174 | } |
165 | 175 | ||
176 | void Ipkg :: removeStatusEntry() | ||
177 | { | ||
178 | QString statusFile = destDir; | ||
179 | if ( statusFile.right( 1 ) != "/" ) | ||
180 | statusFile += "/"; | ||
181 | statusFile += "usr/lib/ipkg/status"; | ||
182 | QString outStatusFile = statusFile + ".tmp"; | ||
183 | |||
184 | emit outputText( "" ); | ||
185 | emit outputText( "Removing status entry..." ); | ||
186 | emit outputText( QString( "status file - " )+ statusFile ); | ||
187 | emit outputText( QString( "package - " )+ package ); | ||
188 | |||
189 | ifstream in( statusFile ); | ||
190 | ofstream out( outStatusFile ); | ||
191 | if ( !in.is_open() ) | ||
192 | { | ||
193 | emit outputText( QString( "Couldn't open status file - " )+ statusFile ); | ||
194 | return; | ||
195 | } | ||
196 | |||
197 | if ( !out.is_open() ) | ||
198 | { | ||
199 | emit outputText( QString( "Couldn't create tempory status file - " )+ outStatusFile ); | ||
200 | return; | ||
201 | } | ||
202 | |||
203 | char line[1001]; | ||
204 | char k[21]; | ||
205 | char v[1001]; | ||
206 | QString key; | ||
207 | QString value; | ||
208 | do | ||
209 | { | ||
210 | in.getline( line, 1000 ); | ||
211 | if ( in.eof() ) | ||
212 | continue; | ||
213 | |||
214 | k[0] = '\0'; | ||
215 | v[0] = '\0'; | ||
216 | |||
217 | sscanf( line, "%[^:]: %[^\n]", k, v ); | ||
218 | key = k; | ||
219 | value = v; | ||
220 | key = key.stripWhiteSpace(); | ||
221 | value = value.stripWhiteSpace(); | ||
222 | if ( key == "Package" && value == package ) | ||
223 | { | ||
224 | // Ignore all lines up to next empty | ||
225 | do | ||
226 | { | ||
227 | in.getline( line, 1000 ); | ||
228 | if ( in.eof() || QString( line ).stripWhiteSpace() == "" ) | ||
229 | continue; | ||
230 | } while ( !in.eof() && QString( line ).stripWhiteSpace() != "" ); | ||
231 | } | ||
232 | |||
233 | out << line << endl; | ||
234 | } while ( !in.eof() ); | ||
235 | |||
236 | in.close(); | ||
237 | out.close(); | ||
238 | |||
239 | // Remove old status file and put tmp stats file in its place | ||
240 | remove( statusFile ); | ||
241 | rename( outStatusFile, statusFile ); | ||
242 | } | ||
243 | |||
166 | 244 | ||
167 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) | 245 | int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) |
168 | { | 246 | { |
169 | FILE *fp = NULL; | 247 | FILE *fp = NULL; |
170 | char line[130]; | 248 | char line[130]; |
171 | QString lineStr, lineStrOld; | 249 | QString lineStr, lineStrOld; |
172 | int ret = false; | 250 | int ret = false; |
173 | 251 | ||
174 | fp = popen( (const char *) cmd, "r"); | 252 | fp = popen( (const char *) cmd, "r"); |
175 | if ( fp == NULL ) | 253 | if ( fp == NULL ) |
176 | { | 254 | { |
177 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; | 255 | cout << "Couldn't execute " << cmd << "! err = " << fp << endl; |
178 | QString text; | 256 | QString text; |
179 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); | 257 | text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); |
180 | emit outputText( text ); | 258 | emit outputText( text ); |
181 | } | 259 | } |
diff --git a/noncore/settings/aqpkg/ipkg.h b/noncore/settings/aqpkg/ipkg.h index 63588c4..55e9ff4 100644 --- a/noncore/settings/aqpkg/ipkg.h +++ b/noncore/settings/aqpkg/ipkg.h | |||
@@ -50,23 +50,24 @@ public: | |||
50 | 50 | ||
51 | signals: | 51 | signals: |
52 | void outputText( const QString &text ); | 52 | void outputText( const QString &text ); |
53 | 53 | ||
54 | private: | 54 | private: |
55 | bool createLinks; | 55 | bool createLinks; |
56 | QString option; | 56 | QString option; |
57 | QString package; | 57 | QString package; |
58 | QString destination; | 58 | QString destination; |
59 | QString destDir; | 59 | QString destDir; |
60 | int flags; | 60 | int flags; |
61 | QString runtimeDir; | 61 | QString runtimeDir; |
62 | 62 | ||
63 | QList<QString> *dependantPackages; | 63 | QList<QString> *dependantPackages; |
64 | 64 | ||
65 | int executeIpkgCommand( QString &cmd, const QString option ); | 65 | int executeIpkgCommand( QString &cmd, const QString option ); |
66 | void removeStatusEntry(); | ||
66 | void linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ); | 67 | void linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ); |
67 | QStringList* getList( const QString &packageFilename, const QString &destDir ); | 68 | QStringList* getList( const QString &packageFilename, const QString &destDir ); |
68 | void processFileList( const QStringList *fileList, const QString &destDir ); | 69 | void processFileList( const QStringList *fileList, const QString &destDir ); |
69 | void processLinkDir( const QString &file, const QString &baseDir, const QString &destDir ); | 70 | void processLinkDir( const QString &file, const QString &baseDir, const QString &destDir ); |
70 | }; | 71 | }; |
71 | 72 | ||
72 | #endif | 73 | #endif |