-rw-r--r-- | library/filemanager.cpp | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/library/filemanager.cpp b/library/filemanager.cpp index 1c1c998..c51ca2f 100644 --- a/library/filemanager.cpp +++ b/library/filemanager.cpp | |||
@@ -257,129 +257,128 @@ bool FileManager::copyFile( const QString & src, const QString & dest ) { | |||
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 | ||
311 | bool FileManager::renameFile( const QString & src, const QString & dest ) { | 311 | bool 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 | ||
321 | ======= | ||
322 | bool FileManager::copyFile( const QString & src, const QString & dest ) { | 321 | bool FileManager::copyFile( const QString & src, const QString & dest ) { |
323 | bool success = true; | 322 | bool success = true; |
324 | struct stat status; | 323 | struct stat status; |
325 | int read_fd=0; | 324 | int read_fd=0; |
326 | int write_fd=0; | 325 | int write_fd=0; |
327 | struct stat stat_buf; | 326 | struct stat stat_buf; |
328 | off_t offset = 0; | 327 | off_t offset = 0; |
329 | QFile srcFile(src); | 328 | QFile srcFile(src); |
330 | QFile destFile(dest); | 329 | QFile destFile(dest); |
331 | 330 | ||
332 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { | 331 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { |
333 | return success = false; | 332 | return success = false; |
334 | } | 333 | } |
335 | read_fd = srcFile.handle(); | 334 | read_fd = srcFile.handle(); |
336 | if(read_fd != -1) { | 335 | if(read_fd != -1) { |
337 | fstat (read_fd, &stat_buf); | 336 | fstat (read_fd, &stat_buf); |
338 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) | 337 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) |
339 | return success = false; | 338 | return success = false; |
340 | write_fd = destFile.handle(); | 339 | write_fd = destFile.handle(); |
341 | if(write_fd != -1) { | 340 | if(write_fd != -1) { |
342 | int err=0; | 341 | int err=0; |
343 | QString msg; | 342 | QString msg; |
344 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); | 343 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); |
345 | if( err == -1) { | 344 | if( err == -1) { |
346 | switch(err) { | 345 | switch(err) { |
347 | 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. "; |
348 | case EINVAL: msg = "Descriptor is not valid or locked. "; | 347 | case EINVAL: msg = "Descriptor is not valid or locked. "; |
349 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; | 348 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; |
350 | case EIO: msg = "Unspecified error while reading from in_fd."; | 349 | case EIO: msg = "Unspecified error while reading from in_fd."; |
351 | }; | 350 | }; |
352 | success = false; | 351 | success = false; |
353 | } | 352 | } |
354 | } else { | 353 | } else { |
355 | qWarning("open write failed %s, %s",src.latin1(), dest.latin1()); | 354 | qWarning("open write failed %s, %s",src.latin1(), dest.latin1()); |
356 | success = false; | 355 | success = false; |
357 | } | 356 | } |
358 | } else { | 357 | } else { |
359 | qWarning("open read failed %s, %s",src.latin1(), dest.latin1()); | 358 | qWarning("open read failed %s, %s",src.latin1(), dest.latin1()); |
360 | success = false; | 359 | success = false; |
361 | } | 360 | } |
362 | srcFile.close(); | 361 | srcFile.close(); |
363 | destFile.close(); | 362 | destFile.close(); |
364 | // Set file permissions | 363 | // Set file permissions |
365 | if( stat( (const char *) src, &status ) == 0 ) { | 364 | if( stat( (const char *) src, &status ) == 0 ) { |
366 | chmod( (const char *) dest, status.st_mode ); | 365 | chmod( (const char *) dest, status.st_mode ); |
367 | } | 366 | } |
368 | 367 | ||
369 | return success; | 368 | return success; |
370 | } | 369 | } |
371 | 370 | ||
372 | 371 | ||
373 | bool FileManager::renameFile( const QString & src, const QString & dest ) { | 372 | bool FileManager::renameFile( const QString & src, const QString & dest ) { |
374 | if(copyFile( src, dest )) { | 373 | if(copyFile( src, dest )) { |
375 | if(QFile::remove(src) ) { | 374 | if(QFile::remove(src) ) { |
376 | return true; | 375 | return true; |
377 | } | 376 | } |
378 | } | 377 | } |
379 | return false; | 378 | return false; |
380 | } | 379 | } |
381 | 380 | ||
382 | 381 | ||
383 | /*! | 382 | /*! |
384 | Opens the document specified by \a f as a readable QIODevice. | 383 | Opens the document specified by \a f as a readable QIODevice. |
385 | The caller must delete the return value. | 384 | The caller must delete the return value. |