Diffstat (limited to 'core/launcher/packageslave.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/launcher/packageslave.cpp | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/core/launcher/packageslave.cpp b/core/launcher/packageslave.cpp index abbc610..965020e 100644 --- a/core/launcher/packageslave.cpp +++ b/core/launcher/packageslave.cpp | |||
@@ -121,218 +121,226 @@ void PackageHandler::installPackage( const QString &package, const QString &dest | |||
121 | currentProcessError=""; | 121 | currentProcessError=""; |
122 | sendReply( "installStarted(QString)", package ); | 122 | sendReply( "installStarted(QString)", package ); |
123 | currentProcess->start(); | 123 | currentProcess->start(); |
124 | } | 124 | } |
125 | 125 | ||
126 | void PackageHandler::removePackage( const QString &package ) | 126 | void PackageHandler::removePackage( const QString &package ) |
127 | { | 127 | { |
128 | currentProcess = new QProcess( QStringList() << "ipkg" << "remove" << package ); // No tr | 128 | currentProcess = new QProcess( QStringList() << "ipkg" << "remove" << package ); // No tr |
129 | connect( currentProcess, SIGNAL( processExited() ), SLOT( rmProcessExited() ) ); | 129 | connect( currentProcess, SIGNAL( processExited() ), SLOT( rmProcessExited() ) ); |
130 | connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); | 130 | connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); |
131 | connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); | 131 | connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); |
132 | currentPackage = package; | 132 | currentPackage = package; |
133 | 133 | ||
134 | currentProcessError=""; | 134 | currentProcessError=""; |
135 | sendReply( "removeStarted(QString)", package ); | 135 | sendReply( "removeStarted(QString)", package ); |
136 | currentProcess->start(); | 136 | currentProcess->start(); |
137 | } | 137 | } |
138 | 138 | ||
139 | void PackageHandler::sendReply( const QCString& msg, const QString& arg ) | 139 | void PackageHandler::sendReply( const QCString& msg, const QString& arg ) |
140 | { | 140 | { |
141 | #ifndef QT_NO_COP | 141 | #ifndef QT_NO_COP |
142 | QCopEnvelope e( "QPE/Desktop", msg ); | 142 | QCopEnvelope e( "QPE/Desktop", msg ); |
143 | e << arg; | 143 | e << arg; |
144 | #endif | 144 | #endif |
145 | } | 145 | } |
146 | 146 | ||
147 | void PackageHandler::addPackageFiles( const QString &location, | 147 | void PackageHandler::addPackageFiles( const QString &location, |
148 | const QString &listfile ) | 148 | const QString &listfile ) |
149 | { | 149 | { |
150 | QFile f(listfile); | 150 | QFile f(listfile); |
151 | #ifndef Q_OS_WIN32 | 151 | #ifndef Q_OS_WIN32 |
152 | //make a copy so we can remove the symlinks later | 152 | //make a copy so we can remove the symlinks later |
153 | mkdir( ("/usr/lib/ipkg/info/"+location).ascii(), 0777 ); | 153 | mkdir( ("/usr/lib/ipkg/info/"+location).ascii(), 0777 ); |
154 | system(("cp " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); | 154 | system(("cp " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); |
155 | #else | 155 | #else |
156 | QDir d; | 156 | QDir d; |
157 | //#### revise | 157 | //#### revise |
158 | odebug << "Copy file at " << __FILE__ << ": " << __LINE__ << "" << oendl; | 158 | odebug << "Copy file at " << __FILE__ << ": " << __LINE__ << "" << oendl; |
159 | d.mkdir(("/usr/lib/ipkg/info/" + location).ascii()); | 159 | d.mkdir(("/usr/lib/ipkg/info/" + location).ascii()); |
160 | system(("copy " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); | 160 | system(("copy " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); |
161 | #endif | 161 | #endif |
162 | 162 | ||
163 | 163 | ||
164 | if ( f.open(IO_ReadOnly) ) { | 164 | if ( f.open(IO_ReadOnly) ) { |
165 | QTextStream ts(&f); | 165 | QTextStream ts(&f); |
166 | 166 | ||
167 | QString s; | 167 | QString s; |
168 | while ( !ts.eof() ) { // until end of file... | 168 | while ( !ts.eof() ) { // until end of file... |
169 | s = ts.readLine(); // line of text excluding '\n' | 169 | s = ts.readLine(); // line of text excluding '\n' |
170 | // for s, do link/mkdir. | 170 | // for s, do link/mkdir. |
171 | if ( s.right(1) == "/" ) { | 171 | if ( s.right(1) == "/" ) { |
172 | odebug << "do mkdir for " << s.ascii() << "" << oendl; | 172 | odebug << "do mkdir for " << s.ascii() << "" << oendl; |
173 | #ifndef Q_OS_WIN32 | 173 | #ifndef Q_OS_WIN32 |
174 | mkdir( s.ascii(), 0777 ); | 174 | mkdir( s.ascii(), 0777 ); |
175 | //possible optimization: symlink directories | 175 | //possible optimization: symlink directories |
176 | //that don't exist already. -- Risky. | 176 | //that don't exist already. -- Risky. |
177 | #else | 177 | #else |
178 | d.mkdir( s.ascii()); | 178 | d.mkdir( s.ascii()); |
179 | #endif | 179 | #endif |
180 | 180 | ||
181 | } else { | 181 | } else { |
182 | #ifndef Q_OS_WIN32 | 182 | #ifndef Q_OS_WIN32 |
183 | odebug << "do symlink for " << s.ascii() << "" << oendl; | 183 | odebug << "do symlink for " << s.ascii() << "" << oendl; |
184 | symlink( (location + s).ascii(), s.ascii() ); | 184 | symlink( (location + s).ascii(), s.ascii() ); |
185 | #else | 185 | #else |
186 | odebug << "Copy file instead of a symlink for WIN32" << oendl; | 186 | odebug << "Copy file instead of a symlink for WIN32" << oendl; |
187 | if (!CopyFile((TCHAR*)qt_winTchar((location + s), TRUE), (TCHAR*)qt_winTchar(s, TRUE), FALSE)) | 187 | if (!CopyFile((TCHAR*)qt_winTchar((location + s), TRUE), (TCHAR*)qt_winTchar(s, TRUE), FALSE)) |
188 | owarn << "Unable to create symlinkfor " << (location + s).ascii() << oendl; | 188 | owarn << "Unable to create symlinkfor " << (location + s).ascii() << oendl; |
189 | #endif | 189 | #endif |
190 | } | 190 | } |
191 | } | 191 | } |
192 | f.close(); | 192 | f.close(); |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | void PackageHandler::addPackages( const QString &location ) | 196 | void PackageHandler::addPackages( const QString &location ) |
197 | { | 197 | { |
198 | // get list of *.list in location/usr/lib/ipkg/info/*.list | 198 | // get list of *.list in location/usr/lib/ipkg/info/*.list |
199 | QDir dir(location + "/usr/lib/ipkg/info", "*.list", // No tr | 199 | QDir dir(location + "/usr/lib/ipkg/info", "*.list", // No tr |
200 | QDir::Name, QDir::Files); | 200 | QDir::Name, QDir::Files); |
201 | if ( !dir.exists() ) | 201 | if ( !dir.exists() ) |
202 | return; | 202 | return; |
203 | 203 | ||
204 | QStringList packages = dir.entryList(); | 204 | QStringList packages = dir.entryList(); |
205 | for ( QStringList::Iterator it = packages.begin(); | 205 | for ( QStringList::Iterator it = packages.begin(); |
206 | it != packages.end(); ++it ) { | 206 | it != packages.end(); ++it ) { |
207 | addPackageFiles( location, *it ); | 207 | addPackageFiles( location, *it ); |
208 | } | 208 | } |
209 | } | 209 | } |
210 | 210 | ||
211 | 211 | ||
212 | void PackageHandler::cleanupPackageFiles( const QString &listfile ) | 212 | void PackageHandler::cleanupPackageFiles( const QString &listfile ) |
213 | { | 213 | { |
214 | QFile f(listfile); | 214 | QFile f(listfile); |
215 | 215 | ||
216 | if ( f.open(IO_ReadOnly) ) { | 216 | if ( f.open(IO_ReadOnly) ) { |
217 | QTextStream ts(&f); | 217 | QTextStream ts(&f); |
218 | 218 | ||
219 | QString s; | 219 | QString s; |
220 | while ( !ts.eof() ) { // until end of file... | 220 | while ( !ts.eof() ) { // until end of file... |
221 | s = ts.readLine(); // line of text excluding '\n' | 221 | s = ts.readLine(); // line of text excluding '\n' |
222 | // for s, do link/mkdir. | 222 | // for s, do link/mkdir. |
223 | if ( s.right(1) == "/" ) { | 223 | // @todo Right now we just move on if the name of the file we |
224 | //should rmdir if empty, after all files have been removed | 224 | // find is actually a directory. What we ought to do is check |
225 | } else { | 225 | // to see if the directory is empty and if so remove it. |
226 | if ( s.right(1) != "/" ) { | ||
226 | #ifndef Q_OS_WIN32 | 227 | #ifndef Q_OS_WIN32 |
227 | odebug << "remove symlink for " << s.ascii() << "" << oendl; | 228 | odebug << "remove symlink for " << s << oendl; |
228 | //check if it is a symlink first (don't remove /etc/passwd...) | 229 | QFile symFile(s); |
229 | char buf[10]; //we don't care about the contents | 230 | QFileInfo symFileInfo(symFile); |
230 | if ( ::readlink( s.ascii(),buf, 10 >= 0 ) ) | 231 | //check if it is a symlink first (don't remove /etc/passwd...) |
231 | ::unlink( s.ascii() ); | 232 | if ( !symFileInfo.readLink().isNull()) |
233 | if (!symFile.remove()) | ||
234 | owarn << "Unable to remove symlink " << symFile.name() | ||
235 | << " " << __FILE__ << ":" << __LINE__ << oendl; | ||
232 | #else | 236 | #else |
233 | // ### revise | 237 | // @todo If we actually want to be portable to other operating |
234 | owarn << "Unable to remove symlink " << __FILE__ << ":" << __LINE__ << "" << oendl; | 238 | // systems we ought to at least have a portable way of removing |
239 | // their notion of symlinks. | ||
240 | owarn << "Unable to remove symlink " << s " " << __FILE__ | ||
241 | << ":" << __LINE__ << oendl; | ||
235 | #endif | 242 | #endif |
243 | } | ||
236 | } | 244 | } |
237 | } | 245 | f.close(); |
238 | f.close(); | ||
239 | 246 | ||
240 | //remove the list file | 247 | //remove the list file |
241 | ::unlink( listfile.ascii() ); | 248 | if (!f.remove()) |
242 | 249 | owarn << "Unable to remove list file " << f.name() << " " | |
250 | << __FILE__ << ":" << __LINE__ << oendl; | ||
243 | } | 251 | } |
244 | } | 252 | } |
245 | 253 | ||
246 | void PackageHandler::cleanupPackages( const QString &location ) | 254 | void PackageHandler::cleanupPackages( const QString &location ) |
247 | { | 255 | { |
248 | // get list of *.list in location/usr/lib/ipkg/info/*.list | 256 | // get list of *.list in location/usr/lib/ipkg/info/*.list |
249 | QDir dir( "/usr/lib/ipkg/info/"+location, "*.list", // No tr | 257 | QDir dir( "/usr/lib/ipkg/info/"+location, "*.list", // No tr |
250 | QDir::Name, QDir::Files); | 258 | QDir::Name, QDir::Files); |
251 | if ( !dir.exists() ) | 259 | if ( !dir.exists() ) |
252 | return; | 260 | return; |
253 | 261 | ||
254 | QStringList packages = dir.entryList(); | 262 | QStringList packages = dir.entryList(); |
255 | for ( QStringList::Iterator it = packages.begin(); | 263 | for ( QStringList::Iterator it = packages.begin(); |
256 | it != packages.end(); ++it ) { | 264 | it != packages.end(); ++it ) { |
257 | cleanupPackageFiles( *it ); | 265 | cleanupPackageFiles( *it ); |
258 | } | 266 | } |
259 | 267 | ||
260 | //remove the backup directory | 268 | //remove the backup directory |
261 | //### | 269 | //### |
262 | } | 270 | } |
263 | 271 | ||
264 | void PackageHandler::prepareInstall( const QString& size, const QString& path ) | 272 | void PackageHandler::prepareInstall( const QString& size, const QString& path ) |
265 | { | 273 | { |
266 | // Check whether there will be enough space to install the next package. | 274 | // Check whether there will be enough space to install the next package. |
267 | bool ok; | 275 | bool ok; |
268 | unsigned int s = size.toUInt( &ok ); | 276 | unsigned int s = size.toUInt( &ok ); |
269 | 277 | ||
270 | if ( !ok ) | 278 | if ( !ok ) |
271 | return; | 279 | return; |
272 | 280 | ||
273 | // Shamelessly stolen from the sysinfo application (Werner) | 281 | // Shamelessly stolen from the sysinfo application (Werner) |
274 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 282 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
275 | struct statfs fs; | 283 | struct statfs fs; |
276 | if ( statfs( path.latin1(), &fs ) == 0 ) | 284 | if ( statfs( path.latin1(), &fs ) == 0 ) |
277 | if ( s > fs.f_bsize * fs.f_bavail ) { | 285 | if ( s > fs.f_bsize * fs.f_bavail ) { |
278 | //odebug << "############### Not enough space left ###############" << oendl; | 286 | //odebug << "############### Not enough space left ###############" << oendl; |
279 | mNoSpaceLeft = TRUE; | 287 | mNoSpaceLeft = TRUE; |
280 | } | 288 | } |
281 | #endif | 289 | #endif |
282 | } | 290 | } |
283 | 291 | ||
284 | void PackageHandler::iProcessExited() | 292 | void PackageHandler::iProcessExited() |
285 | { | 293 | { |
286 | if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) | 294 | if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) |
287 | sendReply( "installDone(QString)", currentPackage ); | 295 | sendReply( "installDone(QString)", currentPackage ); |
288 | else { | 296 | else { |
289 | #ifndef QT_NO_COP | 297 | #ifndef QT_NO_COP |
290 | QCopEnvelope e( "QPE/Desktop", "installFailed(QString,int,QString)" ); | 298 | QCopEnvelope e( "QPE/Desktop", "installFailed(QString,int,QString)" ); |
291 | e << currentPackage << currentProcess->exitStatus() | 299 | e << currentPackage << currentProcess->exitStatus() |
292 | << currentProcessError; | 300 | << currentProcessError; |
293 | #endif | 301 | #endif |
294 | } | 302 | } |
295 | 303 | ||
296 | delete currentProcess; | 304 | delete currentProcess; |
297 | currentProcess = 0; | 305 | currentProcess = 0; |
298 | 306 | ||
299 | #ifndef QT_NO_COP | 307 | #ifndef QT_NO_COP |
300 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 308 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
301 | QString lf = QString::null; | 309 | QString lf = QString::null; |
302 | e << lf; | 310 | e << lf; |
303 | #endif | 311 | #endif |
304 | unlink( currentPackage ); | 312 | unlink( currentPackage ); |
305 | } | 313 | } |
306 | 314 | ||
307 | void PackageHandler::rmProcessExited() | 315 | void PackageHandler::rmProcessExited() |
308 | { | 316 | { |
309 | if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) | 317 | if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) |
310 | sendReply( "removeDone(QString)", currentPackage ); | 318 | sendReply( "removeDone(QString)", currentPackage ); |
311 | else | 319 | else |
312 | sendReply( "removeFailed(QString)", currentPackage ); | 320 | sendReply( "removeFailed(QString)", currentPackage ); |
313 | 321 | ||
314 | #ifndef QT_NO_COP | 322 | #ifndef QT_NO_COP |
315 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 323 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
316 | QString lf = QString::null; | 324 | QString lf = QString::null; |
317 | e << lf; | 325 | e << lf; |
318 | #endif | 326 | #endif |
319 | } | 327 | } |
320 | 328 | ||
321 | void PackageHandler::readyReadStdout() | 329 | void PackageHandler::readyReadStdout() |
322 | { | 330 | { |
323 | while ( currentProcess->canReadLineStdout() ) { | 331 | while ( currentProcess->canReadLineStdout() ) { |
324 | QString line = currentProcess->readLineStdout(); | 332 | QString line = currentProcess->readLineStdout(); |
325 | currentProcessError.append("OUT:"+line); | 333 | currentProcessError.append("OUT:"+line); |
326 | if ( line.contains( "Unpacking" ) ) // No tr | 334 | if ( line.contains( "Unpacking" ) ) // No tr |
327 | sendReply( "installStep(QString)", "one" ); // No tr | 335 | sendReply( "installStep(QString)", "one" ); // No tr |
328 | else if ( line.contains( "Configuring" ) ) // No tr | 336 | else if ( line.contains( "Configuring" ) ) // No tr |
329 | sendReply( "installStep(QString)", "two" ); // No tr | 337 | sendReply( "installStep(QString)", "two" ); // No tr |
330 | } | 338 | } |
331 | } | 339 | } |
332 | 340 | ||
333 | void PackageHandler::readyReadStderr() | 341 | void PackageHandler::readyReadStderr() |
334 | { | 342 | { |
335 | while ( currentProcess->canReadLineStderr() ) { | 343 | while ( currentProcess->canReadLineStderr() ) { |
336 | QString line = currentProcess->readLineStderr(); | 344 | QString line = currentProcess->readLineStderr(); |
337 | currentProcessError.append("ERR:"+line); | 345 | currentProcessError.append("ERR:"+line); |
338 | } | 346 | } |