summaryrefslogtreecommitdiff
path: root/library
Unidiff
Diffstat (limited to 'library') (more/less context) (show whitespace changes)
-rw-r--r--library/filemanager.cpp64
1 files changed, 62 insertions, 2 deletions
diff --git a/library/filemanager.cpp b/library/filemanager.cpp
index 91986a0..1c1c998 100644
--- a/library/filemanager.cpp
+++ b/library/filemanager.cpp
@@ -225,8 +225,6 @@ bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest )
225 return ok; 225 return ok;
226} 226}
227 227
228
229
230bool FileManager::copyFile( const QString & src, const QString & dest ) { 228bool FileManager::copyFile( const QString & src, const QString & dest ) {
231 bool success = true; 229 bool success = true;
232 struct stat status; 230 struct stat status;
@@ -320,6 +318,68 @@ bool FileManager::renameFile( const QString & src, const QString & dest ) {
320} 318}
321 319
322 320
321=======
322bool 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
373bool 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/*!
324 Opens the document specified by \a f as a readable QIODevice. 384 Opens the document specified by \a f as a readable QIODevice.
325 The caller must delete the return value. 385 The caller must delete the return value.