summaryrefslogtreecommitdiff
authorwaspe <waspe>2003-11-05 18:34:52 (UTC)
committer waspe <waspe>2003-11-05 18:34:52 (UTC)
commitb7669e25027e64a721705548efc2a7f92daed704 (patch) (unidiff)
tree7bbb2a807f57e41896fe304b963d024eb22d5c7b
parent7f271d89922254226280f039ae53c5fee63ef94d (diff)
downloadopie-b7669e25027e64a721705548efc2a7f92daed704.zip
opie-b7669e25027e64a721705548efc2a7f92daed704.tar.gz
opie-b7669e25027e64a721705548efc2a7f92daed704.tar.bz2
double entries in function defintions
(i commented out the second entry)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/filemanager.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/library/filemanager.cpp b/library/filemanager.cpp
index c51ca2f..eff8429 100644
--- a/library/filemanager.cpp
+++ b/library/filemanager.cpp
@@ -224,220 +224,220 @@ bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest )
224 224
225 return ok; 225 return ok;
226} 226}
227 227
228bool FileManager::copyFile( const QString & src, const QString & dest ) { 228bool FileManager::copyFile( const QString & src, const QString & dest ) {
229 bool success = true; 229 bool success = true;
230 struct stat status; 230 struct stat status;
231 int read_fd=0; 231 int read_fd=0;
232 int write_fd=0; 232 int write_fd=0;
233 struct stat stat_buf; 233 struct stat stat_buf;
234 off_t offset = 0; 234 off_t offset = 0;
235 QFile srcFile(src); 235 QFile srcFile(src);
236 QFile destFile(dest); 236 QFile destFile(dest);
237 237
238 if(!srcFile.open( IO_ReadOnly|IO_Raw)) { 238 if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
239 return success = false; 239 return success = false;
240 } 240 }
241 read_fd = srcFile.handle(); 241 read_fd = srcFile.handle();
242 if(read_fd != -1) { 242 if(read_fd != -1) {
243 fstat (read_fd, &stat_buf); 243 fstat (read_fd, &stat_buf);
244 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) 244 if( !destFile.open( IO_WriteOnly|IO_Raw ) )
245 return success = false; 245 return success = false;
246 write_fd = destFile.handle(); 246 write_fd = destFile.handle();
247 if(write_fd != -1) { 247 if(write_fd != -1) {
248 int err=0; 248 int err=0;
249 QString msg; 249 QString msg;
250#ifdef Q_OS_MACX 250#ifdef Q_OS_MACX
251#ifdef SENDMAIL 251#ifdef SENDMAIL
252 /* FreeBSD does support a different kind of 252 /* FreeBSD does support a different kind of
253 * sendfile. (eilers) 253 * sendfile. (eilers)
254 * I took this from Very Secure FTPd 254 * I took this from Very Secure FTPd
255 * Licence: GPL 255 * Licence: GPL
256 * Author: Chris Evans 256 * Author: Chris Evans
257 * sysdeputil.c 257 * sysdeputil.c
258 */ 258 */
259 /* XXX - start_pos will truncate on 32-bit machines - can we 259 /* XXX - start_pos will truncate on 32-bit machines - can we
260 * say "start from current pos"? 260 * say "start from current pos"?
261 */ 261 */
262 off_t written = 0; 262 off_t written = 0;
263 int retval = 0; 263 int retval = 0;
264 retval = sendfile(read_fd, write_fd, offset, stat_buf.st_size, NULL, 264 retval = sendfile(read_fd, write_fd, offset, stat_buf.st_size, NULL,
265 &written, 0); 265 &written, 0);
266 /* Translate to Linux-like retval */ 266 /* Translate to Linux-like retval */
267 if (written > 0) 267 if (written > 0)
268 { 268 {
269 err = (int) written; 269 err = (int) written;
270 } 270 }
271#else /* SENDMAIL */ 271#else /* SENDMAIL */
272 err == -1; 272 err == -1;
273 msg = "FAILURE: Using unsupported function \"sendfile()\" Need Workaround !!"; 273 msg = "FAILURE: Using unsupported function \"sendfile()\" Need Workaround !!";
274 success = false; 274 success = false;
275# warning "Need workaround for sendfile!!(eilers)" 275# warning "Need workaround for sendfile!!(eilers)"
276#endif /* SENDMAIL */ 276#endif /* SENDMAIL */
277 277
278#else 278#else
279 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); 279 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
280 if( err == -1) { 280 if( err == -1) {
281 switch(err) { 281 switch(err) {
282 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; 282 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
283 case EINVAL: msg = "Descriptor is not valid or locked. "; 283 case EINVAL: msg = "Descriptor is not valid or locked. ";
284 case ENOMEM: msg = "Insufficient memory to read from in_fd."; 284 case ENOMEM: msg = "Insufficient memory to read from in_fd.";
285 case EIO: msg = "Unspecified error while reading from in_fd."; 285 case EIO: msg = "Unspecified error while reading from in_fd.";
286 }; 286 };
287 success = false; 287 success = false;
288 } 288 }
289#endif /* Q_OS_MACX */ 289#endif /* Q_OS_MACX */
290 if( !success ) 290 if( !success )
291 qWarning( msg ); 291 qWarning( msg );
292 } else { 292 } else {
293 qWarning("open write failed %s, %s",src.latin1(), dest.latin1()); 293 qWarning("open write failed %s, %s",src.latin1(), dest.latin1());
294 success = false; 294 success = false;
295 } 295 }
296 } else { 296 } else {
297 qWarning("open read failed %s, %s",src.latin1(), dest.latin1()); 297 qWarning("open read failed %s, %s",src.latin1(), dest.latin1());
298 success = false; 298 success = false;
299 } 299 }
300 srcFile.close(); 300 srcFile.close();
301 destFile.close(); 301 destFile.close();
302 // Set file permissions 302 // Set file permissions
303 if( stat( (const char *) src, &status ) == 0 ) { 303 if( stat( (const char *) src, &status ) == 0 ) {
304 chmod( (const char *) dest, status.st_mode ); 304 chmod( (const char *) dest, status.st_mode );
305 } 305 }
306 306
307 return success; 307 return success;
308} 308}
309 309
310 310
311bool FileManager::renameFile( const QString & src, const QString & dest ) { 311bool FileManager::renameFile( const QString & src, const QString & dest ) {
312 if(copyFile( src, dest )) { 312 if(copyFile( src, dest )) {
313 if(QFile::remove(src) ) { 313 if(QFile::remove(src) ) {
314 return true; 314 return true;
315 } 315 }
316 } 316 }
317 return false; 317 return false;
318} 318}
319 319
320 320/*
321bool FileManager::copyFile( const QString & src, const QString & dest ) { 321bool FileManager::copyFile( const QString & src, const QString & dest ) {
322 bool success = true; 322 bool success = true;
323 struct stat status; 323 struct stat status;
324 int read_fd=0; 324 int read_fd=0;
325 int write_fd=0; 325 int write_fd=0;
326 struct stat stat_buf; 326 struct stat stat_buf;
327 off_t offset = 0; 327 off_t offset = 0;
328 QFile srcFile(src); 328 QFile srcFile(src);
329 QFile destFile(dest); 329 QFile destFile(dest);
330 330
331 if(!srcFile.open( IO_ReadOnly|IO_Raw)) { 331 if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
332 return success = false; 332 return success = false;
333 } 333 }
334 read_fd = srcFile.handle(); 334 read_fd = srcFile.handle();
335 if(read_fd != -1) { 335 if(read_fd != -1) {
336 fstat (read_fd, &stat_buf); 336 fstat (read_fd, &stat_buf);
337 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) 337 if( !destFile.open( IO_WriteOnly|IO_Raw ) )
338 return success = false; 338 return success = false;
339 write_fd = destFile.handle(); 339 write_fd = destFile.handle();
340 if(write_fd != -1) { 340 if(write_fd != -1) {
341 int err=0; 341 int err=0;
342 QString msg; 342 QString msg;
343 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); 343 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
344 if( err == -1) { 344 if( err == -1) {
345 switch(err) { 345 switch(err) {
346 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; 346 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
347 case EINVAL: msg = "Descriptor is not valid or locked. "; 347 case EINVAL: msg = "Descriptor is not valid or locked. ";
348 case ENOMEM: msg = "Insufficient memory to read from in_fd."; 348 case ENOMEM: msg = "Insufficient memory to read from in_fd.";
349 case EIO: msg = "Unspecified error while reading from in_fd."; 349 case EIO: msg = "Unspecified error while reading from in_fd.";
350 }; 350 };
351 success = false; 351 success = false;
352 } 352 }
353 } else { 353 } else {
354 qWarning("open write failed %s, %s",src.latin1(), dest.latin1()); 354 qWarning("open write failed %s, %s",src.latin1(), dest.latin1());
355 success = false; 355 success = false;
356 } 356 }
357 } else { 357 } else {
358 qWarning("open read failed %s, %s",src.latin1(), dest.latin1()); 358 qWarning("open read failed %s, %s",src.latin1(), dest.latin1());
359 success = false; 359 success = false;
360 } 360 }
361 srcFile.close(); 361 srcFile.close();
362 destFile.close(); 362 destFile.close();
363 // Set file permissions 363 // Set file permissions
364 if( stat( (const char *) src, &status ) == 0 ) { 364 if( stat( (const char *) src, &status ) == 0 ) {
365 chmod( (const char *) dest, status.st_mode ); 365 chmod( (const char *) dest, status.st_mode );
366 } 366 }
367 367
368 return success; 368 return success;
369} 369}
370 370
371 371
372bool FileManager::renameFile( const QString & src, const QString & dest ) { 372bool FileManager::renameFile( const QString & src, const QString & dest ) {
373 if(copyFile( src, dest )) { 373 if(copyFile( src, dest )) {
374 if(QFile::remove(src) ) { 374 if(QFile::remove(src) ) {
375 return true; 375 return true;
376 } 376 }
377 } 377 }
378 return false; 378 return false;
379} 379}
380 380*/
381 381
382/*! 382/*!
383 Opens the document specified by \a f as a readable QIODevice. 383 Opens the document specified by \a f as a readable QIODevice.
384 The caller must delete the return value. 384 The caller must delete the return value.
385 385
386 Returns 0 if the operation fails. 386 Returns 0 if the operation fails.
387*/ 387*/
388QIODevice* FileManager::openFile( const DocLnk& f ) 388QIODevice* FileManager::openFile( const DocLnk& f )
389{ 389{
390 QString fn = f.file(); 390 QString fn = f.file();
391 QFile* fl = new QFile( fn ); 391 QFile* fl = new QFile( fn );
392 if ( !fl->open( IO_ReadOnly ) ) { 392 if ( !fl->open( IO_ReadOnly ) ) {
393 delete fl; 393 delete fl;
394 fl = 0; 394 fl = 0;
395 } 395 }
396 return fl; 396 return fl;
397} 397}
398 398
399/*! 399/*!
400 Opens the document specified by \a f as a writable QIODevice. 400 Opens the document specified by \a f as a writable QIODevice.
401 The caller must delete the return value. 401 The caller must delete the return value.
402 402
403 Returns 0 if the operation fails. 403 Returns 0 if the operation fails.
404*/ 404*/
405QIODevice* FileManager::saveFile( const DocLnk& f ) 405QIODevice* FileManager::saveFile( const DocLnk& f )
406{ 406{
407 QString fn = f.file(); 407 QString fn = f.file();
408 ensurePathExists( fn ); 408 ensurePathExists( fn );
409 QFile* fl = new QFile( fn ); 409 QFile* fl = new QFile( fn );
410 if ( fl->open( IO_WriteOnly ) ) { 410 if ( fl->open( IO_WriteOnly ) ) {
411 f.writeLink(); 411 f.writeLink();
412 } else { 412 } else {
413 delete fl; 413 delete fl;
414 fl = 0; 414 fl = 0;
415 } 415 }
416 return fl; 416 return fl;
417} 417}
418 418
419/*! 419/*!
420 Returns whether the document specified by \a f current exists 420 Returns whether the document specified by \a f current exists
421 as a file on disk. 421 as a file on disk.
422*/ 422*/
423bool FileManager::exists( const DocLnk &f ) 423bool FileManager::exists( const DocLnk &f )
424{ 424{
425 return QFile::exists(f.file()); 425 return QFile::exists(f.file());
426} 426}
427 427
428 428
429/*! 429/*!
430 Ensures that the path \a fn exists, by creating required directories. 430 Ensures that the path \a fn exists, by creating required directories.
431 Returns TRUE if successful. 431 Returns TRUE if successful.
432*/ 432*/
433bool FileManager::ensurePathExists( const QString &fn ) 433bool FileManager::ensurePathExists( const QString &fn )
434{ 434{
435 QFileInfo fi(fn); 435 QFileInfo fi(fn);
436 fi.setFile( fi.dirPath(TRUE) ); 436 fi.setFile( fi.dirPath(TRUE) );
437 if ( !fi.exists() ) { 437 if ( !fi.exists() ) {
438 if ( system(("mkdir -p "+fi.filePath())) ) 438 if ( system(("mkdir -p "+fi.filePath())) )
439 return FALSE; 439 return FALSE;
440 } 440 }
441 441
442 return TRUE; 442 return TRUE;
443} 443}