From: Lukas Hrazky Date: Sat, 24 Jul 2010 12:14:12 +0000 (+0200) Subject: dont delete source files on moving if error occurs X-Git-Tag: v0.1.2~4 X-Git-Url: http://vcs.maemo.org/git/?p=case;a=commitdiff_plain;h=e8d956a1b2271ff4c768ee9c902ac4f02212e6c2 dont delete source files on moving if error occurs Signed-off-by: Lukas Hrazky --- diff --git a/src/fileoperator.cpp b/src/fileoperator.cpp index 8d422e6..8a159c7 100644 --- a/src/fileoperator.cpp +++ b/src/fileoperator.cpp @@ -55,12 +55,15 @@ } -#define ERROR_PROMPT_XP(operation, promptString, fileName, onIgnore, quitCmd) \ +#define SPECIAL_COPY_ERROR_PROMPT(operation, promptString, fileName) \ { \ ERROR_PROMPT(operation, promptString, fileName) \ if (abort || response == FileOperator::IGNORE) { \ - if (!abort) onIgnore; \ - quitCmd; \ + if (!abort) { \ + updateProgress(fileSizeMap[path]); \ + removeExcludeFiles.insert(path); \ + } \ + return; \ } \ } @@ -384,12 +387,21 @@ bool FileManipulatorThread::remove(const QFileInfo &file, const bool doUpdates) std::cout << "DELETING " << file.absoluteFilePath().toStdString() << std::endl; QString path = file.absoluteFilePath(); + + if (removeExcludeFiles.contains(path)) { + if (doUpdates) updateProgress(1); + return false; + } + QFSFileEngine engine(path); if (doUpdates) updateFile(path); if (file.isDir()) { - if (!remove(listDirFiles(path), doUpdates)) return false; + if (!remove(listDirFiles(path), doUpdates)) { + if (doUpdates) updateProgress(1); + return false; + } if (!listDirFiles(path).size()) { ERROR_PROMPT(!engine.rmdir(path, false), tr("Error deleting directory %1."), path) @@ -428,6 +440,7 @@ void FileManipulatorThread::copy(const QFileInfo &file) { if (response == FileOperator::KEEP) { updateProgress(fileSizeMap[path]); + removeExcludeFiles.insert(path); return; } @@ -443,10 +456,8 @@ void FileManipulatorThread::copy(const QFileInfo &file) { } if (!newFile.exists()) { - ERROR_PROMPT_XP(!engine.mkdir(newPath, false), - tr("Error creating directory %1."), newPath, - updateProgress(fileSizeMap[path]), - return) + SPECIAL_COPY_ERROR_PROMPT(!engine.mkdir(newPath, false), + tr("Error creating directory %1."), newPath) } updateProgress(1); @@ -468,33 +479,27 @@ void FileManipulatorThread::copy(const QFileInfo &file) { dest = destBackup; } else { - ERROR_PROMPT_XP(engine.isSequential(), - tr("Cannot copy sequential file %1."), path, - updateProgress(fileSizeMap[path]), - return) + SPECIAL_COPY_ERROR_PROMPT(engine.isSequential(), tr("Cannot copy sequential file %1."), path) if (newFile.exists() && newFile.isDir()) { - ERROR_PROMPT_XP(!remove(newPath), - tr("Cannot replace directory %1 due to previous errors."), newPath, - updateProgress(fileSizeMap[path]), - return) + SPECIAL_COPY_ERROR_PROMPT(!remove(newPath), + tr("Cannot replace directory %1 due to previous errors."), newPath) } - ERROR_PROMPT_XP(!engine.open(QIODevice::ReadOnly), - tr("Error reading file %1."), path, - updateProgress(fileSizeMap[path]), - return) + SPECIAL_COPY_ERROR_PROMPT(!engine.open(QIODevice::ReadOnly), tr("Error reading file %1."), path) bool ignore = false; while (!abort && !ignore) { engine.seek(0); + fileValue = 0; ERROR_PROMPT(!newEngine.open(QIODevice::WriteOnly | QIODevice::Truncate), tr("Error writing file %1."), newPath) if (abort || response == FileOperator::IGNORE) { if (response == FileOperator::IGNORE) { - updateProgress(fileSizeMap[path] - fileValue); + updateProgress(fileSizeMap[path]); + removeExcludeFiles.insert(path); ignore = true; } break; @@ -514,6 +519,7 @@ void FileManipulatorThread::copy(const QFileInfo &file) { if (!abort) { if (response == FileOperator::IGNORE) { updateProgress(fileSizeMap[path] - fileValue); + removeExcludeFiles.insert(path); ignore = true; } else { updateProgress(-fileValue); @@ -701,8 +707,6 @@ void MoveThread::rename(const QFileInfoList &files, const QDir &dest) { OVERWRITE_PROMPT(files[i], QFileInfo(newPath)) if (response == FileOperator::KEEP) { - // TODO lets not remove the source for now, I'm not sure what is correct behavior - // remove(path); if (abort) break; updateProgress(1); continue; diff --git a/src/fileoperator.h b/src/fileoperator.h index 1604b9e..221eaf8 100644 --- a/src/fileoperator.h +++ b/src/fileoperator.h @@ -26,6 +26,7 @@ #include #include #include +#include class FileManipulatorThread; @@ -108,6 +109,10 @@ protected: bool abort; bool ignoreAll[256]; + // set of files that won't be deleted by the remove(...) functions + // used when move(...) would not overwrite target file to ensure the source file doesn't get deleted + QSet removeExcludeFiles; + QMap fileSizeMap; QMutex mutex;