summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-04-15 12:11:22 (UTC)
committer llornkcor <llornkcor>2003-04-15 12:11:22 (UTC)
commitd1b5bf7eeb365282356db49f49331c82f234086c (patch) (side-by-side diff)
tree476c3a1bc4c19ab25c3820619e1fa55e8ce8f0a2
parentd0de397e46581f6ed5fcfad320b2b61be3858c5d (diff)
downloadopie-d1b5bf7eeb365282356db49f49331c82f234086c.zip
opie-d1b5bf7eeb365282356db49f49331c82f234086c.tar.gz
opie-d1b5bf7eeb365282356db49f49331c82f234086c.tar.bz2
changed copy method from clunky to using sendfile(). should be 1. faster and 2. require less memory
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/advancedfm/advancedfmMenu.cpp71
1 files changed, 48 insertions, 23 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp
index 93203cd..eae86a4 100644
--- a/noncore/apps/advancedfm/advancedfmMenu.cpp
+++ b/noncore/apps/advancedfm/advancedfmMenu.cpp
@@ -46,3 +46,4 @@
#include <dirent.h>
-
+#include <sys/sendfile.h>
+#include <fcntl.h>
@@ -314,3 +315,3 @@ void AdvancedFm::copy()
msg=tr("Really copy\n%1 files?").arg(count);
- switch ( QMessageBox::warning(this,tr("Delete"),msg
+ switch ( QMessageBox::warning(this,tr("Copy"),msg
,tr("Yes"),tr("No"),0,0,1) )
@@ -522,29 +523,53 @@ bool AdvancedFm::copyFile( const QString & src, const QString & dest )
{
- char bf[ 50000 ];
- int bytesRead;
- bool success = TRUE;
+// char bf[ 50000 ];
+// int bytesRead;
+ bool success = true;
struct stat status;
- QFile s( src );
- QFile d( dest );
-
- if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) )
- {
- while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) )
- {
- if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){
- success = FALSE;
- break;
- }
- }
- if( success && (bytesRead > 0) )
- {
- d.writeBlock( bf, bytesRead );
+// QFile s( src );
+// QFile d( dest );
+
+ int read_fd=0;
+ int write_fd=0;
+ struct stat stat_buf;
+ off_t offset = 0;
+ read_fd = ::open(src.latin1(), O_RDONLY);
+ if(read_fd != -1) {
+ fstat (read_fd, &stat_buf);
+ write_fd = ::open(dest.latin1(), O_WRONLY | O_CREAT, stat_buf.st_mode);
+ if(write_fd != -1) {
+ if(sendfile(write_fd, read_fd, &offset, stat_buf.st_size) == -1) {
+ success = false;
}
+ } else {
+ success = false;
}
- else
- {
- success = FALSE;
+ } else {
+ success = false;
}
+ ::close (read_fd);
+ ::close (write_fd);
+
+
+// if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) )
+// {
+// while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) )
+// {
+// if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){
+// success = FALSE;
+// break;
+// }
+// }
+// if( success && (bytesRead > 0) )
+// {
+// d.writeBlock( bf, bytesRead );
+// }
+
+// }
+// else
+// {
+// success = FALSE;
+// }
+
// Set file permissions