[qet] qet/qet: [4831] Bad behavior fix : in element collection tree, when user drop a directory into itself, this directory is copied in recursive way infinitely.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 4831
Author:   blacksun
Date:     2017-01-03 17:47:39 +0100 (Tue, 03 Jan 2017)
Log Message:
-----------
Bad behavior fix : in element collection tree, when user drop a directory into itself, this directory is copied in recursive way infinitely.
See bug report N° 121

Modified Paths:
--------------
    trunk/sources/ElementsCollection/elementcollectionhandler.cpp
    trunk/sources/ElementsCollection/elementscollectionmodel.cpp

Modified: trunk/sources/ElementsCollection/elementcollectionhandler.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementcollectionhandler.cpp	2017-01-02 18:46:19 UTC (rev 4830)
+++ trunk/sources/ElementsCollection/elementcollectionhandler.cpp	2017-01-03 16:47:39 UTC (rev 4831)
@@ -96,11 +96,25 @@
 
             //Copy all dirs found in source_dir to destination_dir
 		ElementsLocation created_location(created_dir.canonicalPath());
-        foreach(QString str, source_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name))
-        {
+			//Used this bool when user drop a folder into itself to avoid infinite recursive creation of the dropped dir
+		bool copy_itself = false;
+		if (source_dir == destination_dir)
+			copy_itself = true;
+
+		foreach(QString str, source_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name))
+		{
+			if (copy_itself)
+			{
+				if (source_dir.dirName() == str)
+				{
+					copy_itself = false;
+					continue;
+				}
+			}
+
 			ElementsLocation sub_source(source.fileSystemPath() + "/" + str);
-            copyDirectory(sub_source, created_location);
-        }
+			copyDirectory(sub_source, created_location);
+		}
 
             //Copy all elements found in source_dir to destination_dir
         source_dir.setNameFilters(QStringList() << "*.elmt");

Modified: trunk/sources/ElementsCollection/elementscollectionmodel.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementscollectionmodel.cpp	2017-01-02 18:46:19 UTC (rev 4830)
+++ trunk/sources/ElementsCollection/elementscollectionmodel.cpp	2017-01-03 16:47:39 UTC (rev 4831)
@@ -122,8 +122,8 @@
 
 	ElementCollectionItem *eci = static_cast<ElementCollectionItem *>(qsi);
 
-	if (data->hasFormat("application/x-qet-element-uri") || data->hasFormat("application/x-qet-category-uri")) {
-		return true;
+	if (data->hasFormat("application/x-qet-element-uri") || data->hasFormat("application/x-qet-category-uri"))
+	{
 			//Return false if user try to drop a item from a folder to the same folder
 		ElementsLocation drop_location(data->text());
 		for (int i=0 ; i<eci->rowCount() ; i++)
@@ -154,7 +154,8 @@
 	if (!qsi)
 		qsi = itemFromIndex(parent);
 
-	if (qsi->type() == FileElementCollectionItem::Type) {
+	if (qsi->type() == FileElementCollectionItem::Type)
+	{
 		FileElementCollectionItem *feci = static_cast<FileElementCollectionItem *>(qsi);
 
 		if (feci->isCommonCollection())


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/