-rw-r--r-- | library/filemanager.cpp | 66 |
1 files changed, 63 insertions, 3 deletions
diff --git a/library/filemanager.cpp b/library/filemanager.cpp index 91986a0..1c1c998 100644 --- a/library/filemanager.cpp +++ b/library/filemanager.cpp | |||
@@ -208,3 +208,3 @@ bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest ) | |||
208 | } | 208 | } |
209 | 209 | ||
210 | if ( ok ) | 210 | if ( ok ) |
@@ -227,4 +227,2 @@ bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest ) | |||
227 | 227 | ||
228 | |||
229 | |||
230 | bool FileManager::copyFile( const QString & src, const QString & dest ) { | 228 | bool FileManager::copyFile( const QString & src, const QString & dest ) { |
@@ -322,2 +320,64 @@ bool FileManager::renameFile( const QString & src, const QString & dest ) { | |||
322 | 320 | ||
321 | ======= | ||
322 | bool FileManager::copyFile( const QString & src, const QString & dest ) { | ||
323 | bool success = true; | ||
324 | struct stat status; | ||
325 | int read_fd=0; | ||
326 | int write_fd=0; | ||
327 | struct stat stat_buf; | ||
328 | off_t offset = 0; | ||
329 | QFile srcFile(src); | ||
330 | QFile destFile(dest); | ||
331 | |||
332 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { | ||
333 | return success = false; | ||
334 | } | ||
335 | read_fd = srcFile.handle(); | ||
336 | if(read_fd != -1) { | ||
337 | fstat (read_fd, &stat_buf); | ||
338 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) | ||
339 | return success = false; | ||
340 | write_fd = destFile.handle(); | ||
341 | if(write_fd != -1) { | ||
342 | int err=0; | ||
343 | QString msg; | ||
344 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); | ||
345 | if( err == -1) { | ||
346 | switch(err) { | ||
347 | 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. "; | ||
349 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; | ||
350 | case EIO: msg = "Unspecified error while reading from in_fd."; | ||
351 | }; | ||
352 | success = false; | ||
353 | } | ||
354 | } else { | ||
355 | qWarning("open write failed %s, %s",src.latin1(), dest.latin1()); | ||
356 | success = false; | ||
357 | } | ||
358 | } else { | ||
359 | qWarning("open read failed %s, %s",src.latin1(), dest.latin1()); | ||
360 | success = false; | ||
361 | } | ||
362 | srcFile.close(); | ||
363 | destFile.close(); | ||
364 | // Set file permissions | ||
365 | if( stat( (const char *) src, &status ) == 0 ) { | ||
366 | chmod( (const char *) dest, status.st_mode ); | ||
367 | } | ||
368 | |||
369 | return success; | ||
370 | } | ||
371 | |||
372 | |||
373 | bool FileManager::renameFile( const QString & src, const QString & dest ) { | ||
374 | if(copyFile( src, dest )) { | ||
375 | if(QFile::remove(src) ) { | ||
376 | return true; | ||
377 | } | ||
378 | } | ||
379 | return false; | ||
380 | } | ||
381 | |||
382 | |||
323 | /*! | 383 | /*! |