pause in the middle of copying a file w/o reset
authorLukas Hrazky <lukkash@email.cz>
Sat, 21 Aug 2010 23:00:52 +0000 (01:00 +0200)
committerLukas Hrazky <lukkash@email.cz>
Sun, 22 Aug 2010 13:38:00 +0000 (15:38 +0200)
Signed-off-by: Lukas Hrazky <lukkash@email.cz>

src/operationthread.cpp

index d0cf7e1..873ff72 100644 (file)
@@ -302,7 +302,7 @@ void OperationThread::copy(const QFileInfo &file) {
             engine.seek(0);
             fileValue = 0;
 
-            ERROR_PROMPT(!newEngine.open(QIODevice::WriteOnly | QIODevice::Truncate),
+            ERROR_PROMPT(!newEngine.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Unbuffered),
                 tr("Error writing file %1."), newPath)
 
             if (abort || response == IGNORE) {
@@ -321,13 +321,9 @@ void OperationThread::copy(const QFileInfo &file) {
             qint64 bytes;
 
             while ((bytes = engine.read(block, sizeof(block))) > 0) {
-                if (bytes == -1 || bytes != newEngine.write(block, bytes)) {
-                    if (bytes == -1) {
-                        SHOW_ERROR_PROMPT(tr("Error while reading from file %1."), path);
-                    } else {
-                        SHOW_ERROR_PROMPT(tr("Error while writing to file %1."), newPath);
-                    }
-
+                if (bytes == -1) {
+                    SHOW_ERROR_PROMPT(tr("Error while reading from file %1."), path);
+                
                     if (!abort) {
                         if (response == IGNORE) {
                             updateProgress(fileSizeMap[path] - fileValue);
@@ -339,10 +335,30 @@ void OperationThread::copy(const QFileInfo &file) {
                     }
                     error = true;
                     break;
+                } else {
+                    qint64 written = 0;
+                    char *blockPointer = block;
+                    while (bytes != (written = newEngine.write(blockPointer, bytes))) {
+                        SHOW_ERROR_PROMPT(tr("Error while writing to file %1."), newPath);
+
+                        if (response == IGNORE) {
+                            updateProgress(fileSizeMap[path] - fileValue);
+                            removeExcludeFiles.insert(path);
+                            ignore = true;
+                        }
+
+                        if (abort || ignore) break;
+
+                        if (written == -1) written = 0;
+                        bytes -= written;
+                        blockPointer += written;
+
+                        PAUSE();
+                    }
                 }
 
                 PAUSE();
-                if (abort) break;
+                if (abort || ignore) break;
 
                 updateProgress(1);
             }