summaryrefslogtreecommitdiff
path: root/plugins-alternative/CopyEngine/Rsync/RmPath.cpp
diff options
context:
space:
mode:
authorThomas Preud'homme <robotux@celest.fr>2013-03-21 11:01:59 +0100
committerThomas Preud'homme <robotux@celest.fr>2013-03-21 11:01:59 +0100
commite297dbd8052ef4e66f069e2dd1865ae7fa8af28e (patch)
tree342fea0a2f6f33b8b62dad2d1729f8209da1a1ba /plugins-alternative/CopyEngine/Rsync/RmPath.cpp
parent8f9f382e1c97cab2e72e97495650c73ac4b97314 (diff)
Imported Upstream version 0.3.1.0
Diffstat (limited to 'plugins-alternative/CopyEngine/Rsync/RmPath.cpp')
-rw-r--r--plugins-alternative/CopyEngine/Rsync/RmPath.cpp179
1 files changed, 179 insertions, 0 deletions
diff --git a/plugins-alternative/CopyEngine/Rsync/RmPath.cpp b/plugins-alternative/CopyEngine/Rsync/RmPath.cpp
new file mode 100644
index 0000000..636b5ba
--- /dev/null
+++ b/plugins-alternative/CopyEngine/Rsync/RmPath.cpp
@@ -0,0 +1,179 @@
+#include "RmPath.h"
+
+RmPath::RmPath()
+{
+ stopIt=false;
+ waitAction=false;
+ setObjectName("RmPath");
+ moveToThread(this);
+ start();
+}
+
+RmPath::~RmPath()
+{
+ stopIt=true;
+ quit();
+ wait();
+}
+
+void RmPath::addPath(const QString &path,const bool &toSync)
+{
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start: "+path);
+ if(stopIt)
+ return;
+ emit internalStartAddPath(path,toSync);
+}
+
+void RmPath::skip()
+{
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
+ emit internalStartSkip();
+}
+
+void RmPath::retry()
+{
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
+ emit internalStartRetry();
+}
+
+void RmPath::run()
+{
+ connect(this,SIGNAL(internalStartAddPath(QString,bool)),this,SLOT(internalAddPath(QString,bool)),Qt::QueuedConnection);
+ connect(this,SIGNAL(internalStartDoThisPath()),this,SLOT(internalDoThisPath()),Qt::QueuedConnection);
+ connect(this,SIGNAL(internalStartSkip()),this,SLOT(internalSkip()),Qt::QueuedConnection);
+ connect(this,SIGNAL(internalStartRetry()),this,SLOT(internalRetry()),Qt::QueuedConnection);
+ exec();
+}
+
+void RmPath::internalDoThisPath()
+{
+ if(waitAction || pathList.isEmpty())
+ return;
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start: "+pathList.first());
+ if(!toSyncList.first())
+ {
+ if(!rmpath(pathList.first(),false))
+ {
+ if(stopIt)
+ return;
+ waitAction=true;
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to remove the folder: "+pathList.first());
+ emit errorOnFolder(pathList.first(),tr("Unable to remove the folder"));
+ return;
+ }
+ }
+ else
+ {
+ if(QFileInfo(pathList.first()).isDir())
+ {
+ if(!rmpath(pathList.first(),true))
+ {
+ if(stopIt)
+ return;
+ waitAction=true;
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to remove the folder: "+pathList.first());
+ emit errorOnFolder(pathList.first(),tr("Unable to remove the folder"));
+ return;
+ }
+ }
+ else if(!rmfile(pathList.first()))
+ {
+ if(stopIt)
+ return;
+ waitAction=true;
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to remove the file: "+pathList.first());
+ emit errorOnFolder(pathList.first(),tr("Unable to remove the file"));
+ return;
+ }
+ }
+ pathList.removeFirst();
+ toSyncList.removeFirst();
+ emit firstFolderFinish();
+ checkIfCanDoTheNext();
+}
+
+bool RmPath::rmfile(QString filePath)
+{
+ QFile file(filePath);
+ if(!file.remove())
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"unable to remove the file: "+file.fileName()+", error: "+file.errorString());
+ return false;
+ }
+ else
+ return true;
+}
+
+/** remplace QDir::rmpath() because it return false if the folder not exists
+ and seam bug with parent folder */
+bool RmPath::rmpath(const QDir &dir,const bool &toSync)
+{
+ if(!dir.exists())
+ return true;
+ bool allHaveWork=true;
+ QFileInfoList list = dir.entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System,QDir::DirsFirst);
+ for (int i = 0; i < list.size(); ++i)
+ {
+ QFileInfo fileInfo(list.at(i));
+ if(!fileInfo.isDir())
+ {
+ if(toSync)
+ {
+ if(!rmfile(fileInfo.absoluteFilePath()))
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"unable to remove a file: "+fileInfo.fileName());
+ allHaveWork=false;
+ }
+ }
+ else
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"found a file: "+fileInfo.fileName());
+ allHaveWork=false;
+ }
+ }
+ else
+ {
+ //return the fonction for scan the new folder
+ if(!rmpath(dir.absolutePath()+'/'+fileInfo.fileName()+'/',toSync))
+ allHaveWork=false;
+ }
+ }
+ if(!allHaveWork)
+ return false;
+ allHaveWork=dir.rmdir(dir.absolutePath());
+ if(!allHaveWork)
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"unable to remove the folder: "+dir.absolutePath());
+ return allHaveWork;
+}
+
+void RmPath::internalAddPath(const QString &path,const bool &toSync)
+{
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start: "+path);
+ pathList << path;
+ toSyncList << toSync;
+ if(!waitAction)
+ checkIfCanDoTheNext();
+}
+
+void RmPath::checkIfCanDoTheNext()
+{
+ if(!waitAction && !stopIt && pathList.size()>0)
+ emit internalStartDoThisPath();
+}
+
+void RmPath::internalSkip()
+{
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
+ waitAction=false;
+ pathList.removeFirst();
+ emit firstFolderFinish();
+ checkIfCanDoTheNext();
+}
+
+void RmPath::internalRetry()
+{
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
+ waitAction=false;
+ checkIfCanDoTheNext();
+}
+