summaryrefslogtreecommitdiff
path: root/core/launcher/packageslave.cpp
Unidiff
Diffstat (limited to 'core/launcher/packageslave.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/packageslave.cpp191
1 files changed, 95 insertions, 96 deletions
diff --git a/core/launcher/packageslave.cpp b/core/launcher/packageslave.cpp
index a11ac86..0461432 100644
--- a/core/launcher/packageslave.cpp
+++ b/core/launcher/packageslave.cpp
@@ -50,61 +50,61 @@ PackageHandler::PackageHandler( QObject *parent, char* name )
50 : QObject( parent, name ), packageChannel( 0 ), currentProcess( 0 ), mNoSpaceLeft( FALSE ) 50 : QObject( parent, name ), packageChannel( 0 ), currentProcess( 0 ), mNoSpaceLeft( FALSE )
51{ 51{
52 // setup qcop channel 52 // setup qcop channel
53#ifndef QT_NO_COP 53#ifndef QT_NO_COP
54 packageChannel = new QCopChannel( "QPE/Package", this ); 54 packageChannel = new QCopChannel( "QPE/Package", this );
55 connect( packageChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 55 connect( packageChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
56 this, SLOT( qcopMessage(const QCString&,const QByteArray&) ) ); 56 this, SLOT( qcopMessage(const QCString&,const QByteArray&) ) );
57#endif 57#endif
58} 58}
59 59
60void PackageHandler::qcopMessage( const QCString &msg, const QByteArray &data ) 60void PackageHandler::qcopMessage( const QCString &msg, const QByteArray &data )
61{ 61{
62 QDataStream stream( data, IO_ReadOnly ); 62 QDataStream stream( data, IO_ReadOnly );
63 63
64 if ( msg == "installPackage(QString)" ) { 64 if ( msg == "installPackage(QString)" ) {
65 QString file; 65 QString file;
66 stream >> file; 66 stream >> file;
67 installPackage( file ); 67 installPackage( file );
68 } else if ( msg == "removePackage(QString)" ) { 68 } else if ( msg == "removePackage(QString)" ) {
69 QString file; 69 QString file;
70 stream >> file; 70 stream >> file;
71 removePackage( file ); 71 removePackage( file );
72 } else if ( msg == "addPackageFiles(QString,QString)" ) { 72 } else if ( msg == "addPackageFiles(QString,QString)" ) {
73 QString location, listfile; 73 QString location, listfile;
74 stream >> location >> listfile; 74 stream >> location >> listfile;
75 addPackageFiles( location, listfile); 75 addPackageFiles( location, listfile);
76 } else if ( msg == "addPackages(QString)" ) { 76 } else if ( msg == "addPackages(QString)" ) {
77 QString location; 77 QString location;
78 stream >> location; 78 stream >> location;
79 addPackages( location ); 79 addPackages( location );
80 } else if ( msg == "cleanupPackageFiles(QString)" ) { 80 } else if ( msg == "cleanupPackageFiles(QString)" ) {
81 QString listfile; 81 QString listfile;
82 stream >> listfile; 82 stream >> listfile;
83 cleanupPackageFiles( listfile ); 83 cleanupPackageFiles( listfile );
84 } else if ( msg == "cleanupPackages(QString)" ) { 84 } else if ( msg == "cleanupPackages(QString)" ) {
85 QString location; 85 QString location;
86 stream >> location; 86 stream >> location;
87 cleanupPackages( location ); 87 cleanupPackages( location );
88 } else if ( msg == "prepareInstall(QString,QString)" ) { 88 } else if ( msg == "prepareInstall(QString,QString)" ) {
89 QString size, path; 89 QString size, path;
90 stream >> size; 90 stream >> size;
91 stream >> path; 91 stream >> path;
92 prepareInstall( size, path ); 92 prepareInstall( size, path );
93 } 93 }
94} 94}
95 95
96void PackageHandler::installPackage( const QString &package ) 96void PackageHandler::installPackage( const QString &package )
97{ 97{
98 if ( mNoSpaceLeft ) { 98 if ( mNoSpaceLeft ) {
99 mNoSpaceLeft = FALSE; 99 mNoSpaceLeft = FALSE;
100 // Don't emit that for now, I still couldn't test it (Wener) 100 // Don't emit that for now, I still couldn't test it (Wener)
101 //sendReply( "installFailed(QString)", package ); 101 //sendReply( "installFailed(QString)", package );
102 //return; 102 //return;
103 } 103 }
104 104
105 currentProcess = new QProcess( QStringList() << "ipkg" << "install" << package ); // No tr 105 currentProcess = new QProcess( QStringList() << "ipkg" << "install" << package ); // No tr
106 connect( currentProcess, SIGNAL( processExited() ), SLOT( iProcessExited() ) ); 106 connect( currentProcess, SIGNAL( processExited() ), SLOT( iProcessExited() ) );
107 connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); 107 connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) );
108 connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); 108 connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) );
109 currentPackage = package; 109 currentPackage = package;
110 110
@@ -131,162 +131,161 @@ void PackageHandler::sendReply( const QCString& msg, const QString& arg )
131#ifndef QT_NO_COP 131#ifndef QT_NO_COP
132 QCopEnvelope e( "QPE/Desktop", msg ); 132 QCopEnvelope e( "QPE/Desktop", msg );
133 e << arg; 133 e << arg;
134#endif 134#endif
135} 135}
136 136
137void PackageHandler::addPackageFiles( const QString &location, 137void PackageHandler::addPackageFiles( const QString &location,
138 const QString &listfile ) 138 const QString &listfile )
139{ 139{
140 QFile f(listfile); 140 QFile f(listfile);
141#ifndef Q_OS_WIN32 141#ifndef Q_OS_WIN32
142 //make a copy so we can remove the symlinks later 142 //make a copy so we can remove the symlinks later
143 mkdir( ("/usr/lib/ipkg/info/"+location).ascii(), 0777 ); 143 mkdir( ("/usr/lib/ipkg/info/"+location).ascii(), 0777 );
144 system(("cp " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); 144 system(("cp " + f.name() + " /usr/lib/ipkg/info/"+location).ascii());
145#else 145#else
146 QDir d; 146 QDir d;
147 //#### revise 147 //#### revise
148 odebug << "Copy file at " << __FILE__ << ": " << __LINE__ << "" << oendl; 148 odebug << "Copy file at " << __FILE__ << ": " << __LINE__ << "" << oendl;
149 d.mkdir(("/usr/lib/ipkg/info/" + location).ascii()); 149 d.mkdir(("/usr/lib/ipkg/info/" + location).ascii());
150 system(("copy " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); 150 system(("copy " + f.name() + " /usr/lib/ipkg/info/"+location).ascii());
151#endif 151#endif
152 152
153
154 if ( f.open(IO_ReadOnly) ) {
155 QTextStream ts(&f);
156 153
157 QString s; 154 if ( f.open(IO_ReadOnly) ) {
158 while ( !ts.eof() ) { // until end of file... 155 QTextStream ts(&f);
159 s = ts.readLine(); // line of text excluding '\n' 156
160 // for s, do link/mkdir. 157 QString s;
161 if ( s.right(1) == "/" ) { 158 while ( !ts.eof() ) { // until end of file...
159 s = ts.readLine(); // line of text excluding '\n'
160 // for s, do link/mkdir.
161 if ( s.right(1) == "/" ) {
162 odebug << "do mkdir for " << s.ascii() << "" << oendl; 162 odebug << "do mkdir for " << s.ascii() << "" << oendl;
163#ifndef Q_OS_WIN32 163#ifndef Q_OS_WIN32
164 mkdir( s.ascii(), 0777 ); 164 mkdir( s.ascii(), 0777 );
165 //possible optimization: symlink directories 165 //possible optimization: symlink directories
166 //that don't exist already. -- Risky. 166 //that don't exist already. -- Risky.
167#else 167#else
168 d.mkdir( s.ascii()); 168 d.mkdir( s.ascii());
169#endif 169#endif
170 170
171 } else { 171 } else {
172#ifndef Q_OS_WIN32 172#ifndef Q_OS_WIN32
173 odebug << "do symlink for " << s.ascii() << "" << oendl; 173 odebug << "do symlink for " << s.ascii() << "" << oendl;
174 symlink( (location + s).ascii(), s.ascii() ); 174 symlink( (location + s).ascii(), s.ascii() );
175#else 175#else
176 odebug << "Copy file instead of a symlink for WIN32" << oendl; 176 odebug << "Copy file instead of a symlink for WIN32" << oendl;
177 if (!CopyFile((TCHAR*)qt_winTchar((location + s), TRUE), (TCHAR*)qt_winTchar(s, TRUE), FALSE)) 177 if (!CopyFile((TCHAR*)qt_winTchar((location + s), TRUE), (TCHAR*)qt_winTchar(s, TRUE), FALSE))
178 qWarning("Unable to create symlinkfor %s", 178 owarn << "Unable to create symlinkfor " << (location + s).ascii() << oendl;
179 (location + s).ascii());
180#endif 179#endif
181 } 180 }
182 } 181 }
183 f.close(); 182 f.close();
184 } 183 }
185} 184}
186 185
187void PackageHandler::addPackages( const QString &location ) 186void PackageHandler::addPackages( const QString &location )
188{ 187{
189 // get list of *.list in location/usr/lib/ipkg/info/*.list 188 // get list of *.list in location/usr/lib/ipkg/info/*.list
190 QDir dir(location + "/usr/lib/ipkg/info", "*.list", // No tr 189 QDir dir(location + "/usr/lib/ipkg/info", "*.list", // No tr
191 QDir::Name, QDir::Files); 190 QDir::Name, QDir::Files);
192 if ( !dir.exists() ) 191 if ( !dir.exists() )
193 return; 192 return;
194 193
195 QStringList packages = dir.entryList(); 194 QStringList packages = dir.entryList();
196 for ( QStringList::Iterator it = packages.begin(); 195 for ( QStringList::Iterator it = packages.begin();
197 it != packages.end(); ++it ) { 196 it != packages.end(); ++it ) {
198 addPackageFiles( location, *it ); 197 addPackageFiles( location, *it );
199 } 198 }
200} 199}
201 200
202 201
203void PackageHandler::cleanupPackageFiles( const QString &listfile ) 202void PackageHandler::cleanupPackageFiles( const QString &listfile )
204{ 203{
205 QFile f(listfile); 204 QFile f(listfile);
206 205
207 if ( f.open(IO_ReadOnly) ) { 206 if ( f.open(IO_ReadOnly) ) {
208 QTextStream ts(&f); 207 QTextStream ts(&f);
209 208
210 QString s; 209 QString s;
211 while ( !ts.eof() ) { // until end of file... 210 while ( !ts.eof() ) { // until end of file...
212 s = ts.readLine(); // line of text excluding '\n' 211 s = ts.readLine(); // line of text excluding '\n'
213 // for s, do link/mkdir. 212 // for s, do link/mkdir.
214 if ( s.right(1) == "/" ) { 213 if ( s.right(1) == "/" ) {
215 //should rmdir if empty, after all files have been removed 214 //should rmdir if empty, after all files have been removed
216 } else { 215 } else {
217#ifndef Q_OS_WIN32 216#ifndef Q_OS_WIN32
218 odebug << "remove symlink for " << s.ascii() << "" << oendl; 217 odebug << "remove symlink for " << s.ascii() << "" << oendl;
219 //check if it is a symlink first (don't remove /etc/passwd...) 218 //check if it is a symlink first (don't remove /etc/passwd...)
220 char buf[10]; //we don't care about the contents 219 char buf[10]; //we don't care about the contents
221 if ( ::readlink( s.ascii(),buf, 10 >= 0 ) ) 220 if ( ::readlink( s.ascii(),buf, 10 >= 0 ) )
222 ::unlink( s.ascii() ); 221 ::unlink( s.ascii() );
223 #else 222#else
224 // ### revise 223 // ### revise
225 owarn << "Unable to remove symlink " << __FILE__ << ":" << __LINE__ << "" << oendl; 224 owarn << "Unable to remove symlink " << __FILE__ << ":" << __LINE__ << "" << oendl;
226#endif 225#endif
227 } 226 }
228 } 227 }
229 f.close(); 228 f.close();
230 229
231 //remove the list file 230 //remove the list file
232 ::unlink( listfile.ascii() ); 231 ::unlink( listfile.ascii() );
233 232
234 } 233 }
235} 234}
236 235
237void PackageHandler::cleanupPackages( const QString &location ) 236void PackageHandler::cleanupPackages( const QString &location )
238{ 237{
239 // get list of *.list in location/usr/lib/ipkg/info/*.list 238 // get list of *.list in location/usr/lib/ipkg/info/*.list
240 QDir dir( "/usr/lib/ipkg/info/"+location, "*.list", // No tr 239 QDir dir( "/usr/lib/ipkg/info/"+location, "*.list", // No tr
241 QDir::Name, QDir::Files); 240 QDir::Name, QDir::Files);
242 if ( !dir.exists() ) 241 if ( !dir.exists() )
243 return; 242 return;
244 243
245 QStringList packages = dir.entryList(); 244 QStringList packages = dir.entryList();
246 for ( QStringList::Iterator it = packages.begin(); 245 for ( QStringList::Iterator it = packages.begin();
247 it != packages.end(); ++it ) { 246 it != packages.end(); ++it ) {
248 cleanupPackageFiles( *it ); 247 cleanupPackageFiles( *it );
249 } 248 }
250 249
251 //remove the backup directory 250 //remove the backup directory
252 //### 251 //###
253} 252}
254 253
255void PackageHandler::prepareInstall( const QString& size, const QString& path ) 254void PackageHandler::prepareInstall( const QString& size, const QString& path )
256{ 255{
257 // Check whether there will be enough space to install the next package. 256 // Check whether there will be enough space to install the next package.
258 bool ok; 257 bool ok;
259 unsigned int s = size.toUInt( &ok ); 258 unsigned int s = size.toUInt( &ok );
260 259
261 if ( !ok ) 260 if ( !ok )
262 return; 261 return;
263 262
264 // Shamelessly stolen from the sysinfo application (Werner) 263 // Shamelessly stolen from the sysinfo application (Werner)
265#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 264#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
266 struct statfs fs; 265 struct statfs fs;
267 if ( statfs( path.latin1(), &fs ) == 0 ) 266 if ( statfs( path.latin1(), &fs ) == 0 )
268 if ( s > fs.f_bsize * fs.f_bavail ) { 267 if ( s > fs.f_bsize * fs.f_bavail ) {
269 //odebug << "############### Not enough space left ###############" << oendl; 268 //odebug << "############### Not enough space left ###############" << oendl;
270 mNoSpaceLeft = TRUE; 269 mNoSpaceLeft = TRUE;
271 } 270 }
272#endif 271#endif
273} 272}
274 273
275void PackageHandler::iProcessExited() 274void PackageHandler::iProcessExited()
276{ 275{
277 if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) 276 if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 )
278 sendReply( "installDone(QString)", currentPackage ); 277 sendReply( "installDone(QString)", currentPackage );
279 else { 278 else {
280#ifndef QT_NO_COP 279#ifndef QT_NO_COP
281 QCopEnvelope e( "QPE/Desktop", "installFailed(QString,int,QString)" ); 280 QCopEnvelope e( "QPE/Desktop", "installFailed(QString,int,QString)" );
282 e << currentPackage << currentProcess->exitStatus() 281 e << currentPackage << currentProcess->exitStatus()
283 << currentProcessError; 282 << currentProcessError;
284#endif 283#endif
285 } 284 }
286 285
287 delete currentProcess; 286 delete currentProcess;
288 currentProcess = 0; 287 currentProcess = 0;
289 288
290#ifndef QT_NO_COP 289#ifndef QT_NO_COP
291 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 290 QCopEnvelope e("QPE/System", "linkChanged(QString)");
292 QString lf = QString::null; 291 QString lf = QString::null;
@@ -295,40 +294,40 @@ void PackageHandler::iProcessExited()
295 unlink( currentPackage ); 294 unlink( currentPackage );
296} 295}
297 296
298void PackageHandler::rmProcessExited() 297void PackageHandler::rmProcessExited()
299{ 298{
300 if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) 299 if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 )
301 sendReply( "removeDone(QString)", currentPackage ); 300 sendReply( "removeDone(QString)", currentPackage );
302 else 301 else
303 sendReply( "removeFailed(QString)", currentPackage ); 302 sendReply( "removeFailed(QString)", currentPackage );
304 303
305#ifndef QT_NO_COP 304#ifndef QT_NO_COP
306 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 305 QCopEnvelope e("QPE/System", "linkChanged(QString)");
307 QString lf = QString::null; 306 QString lf = QString::null;
308 e << lf; 307 e << lf;
309#endif 308#endif
310} 309}
311 310
312void PackageHandler::readyReadStdout() 311void PackageHandler::readyReadStdout()
313{ 312{
314 while ( currentProcess->canReadLineStdout() ) { 313 while ( currentProcess->canReadLineStdout() ) {
315 QString line = currentProcess->readLineStdout(); 314 QString line = currentProcess->readLineStdout();
316 currentProcessError.append("OUT:"+line); 315 currentProcessError.append("OUT:"+line);
317 if ( line.contains( "Unpacking" ) ) // No tr 316 if ( line.contains( "Unpacking" ) ) // No tr
318 sendReply( "installStep(QString)", "one" ); // No tr 317 sendReply( "installStep(QString)", "one" ); // No tr
319 else if ( line.contains( "Configuring" ) ) // No tr 318 else if ( line.contains( "Configuring" ) ) // No tr
320 sendReply( "installStep(QString)", "two" ); // No tr 319 sendReply( "installStep(QString)", "two" ); // No tr
321 } 320 }
322} 321}
323 322
324void PackageHandler::readyReadStderr() 323void PackageHandler::readyReadStderr()
325{ 324{
326 while ( currentProcess->canReadLineStderr() ) { 325 while ( currentProcess->canReadLineStderr() ) {
327 QString line = currentProcess->readLineStderr(); 326 QString line = currentProcess->readLineStderr();
328 currentProcessError.append("ERR:"+line); 327 currentProcessError.append("ERR:"+line);
329 } 328 }
330} 329}
331 330
332void PackageHandler::redoPackages() 331void PackageHandler::redoPackages()
333{ 332{
334 //get list of filesystems 333 //get list of filesystems