r24866 by jghali - Try to avoid better copying a file over itself

scribus-commit scribus-commit at lists.scribus.net
Sun Jan 30 16:28:42 UTC 2022


Author: jghali
Date: Sun Jan 30 16:28:42 2022
New Revision: 24866

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24866
Log:
Try to avoid better copying a file over itself

Modified:
    trunk/Scribus/scribus/util_file.cpp

Modified: trunk/Scribus/scribus/util_file.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24866&path=/trunk/Scribus/scribus/util_file.cpp
==============================================================================
--- trunk/Scribus/scribus/util_file.cpp	(original)
+++ trunk/Scribus/scribus/util_file.cpp	Sun Jan 30 16:28:42 2022
@@ -60,8 +60,15 @@
 	bool success = true;
 	if ((source.isEmpty()) || (target.isEmpty()))
 		return false;
-	if (source == target)
-		return false;
+
+	// Make sure to compare source and target paths
+	// by using same directory separators. Source and target
+	// arguments might use native and Qt's separators for eg
+	QString qtSource = QDir::fromNativeSeparators(source);
+	QString qtTarget = QDir::fromNativeSeparators(target);
+	if (qtSource == qtTarget)
+		return false;
+
 	QFile s(source);
 	if (!s.exists())
 		return false;
@@ -84,8 +91,15 @@
 	bool success = false;
 	if ((source.isEmpty()) || (target.isEmpty()))
 		return false;
-	if (source == target)
-		return false;
+
+	// Make sure to compare source and target paths
+	// by using same directory separators. Source and target
+	// arguments might use native and Qt's separators for eg
+	QString qtSource = QDir::fromNativeSeparators(source);
+	QString qtTarget = QDir::fromNativeSeparators(target);
+	if (qtSource == qtTarget)
+		return false;
+
 	QFile srcFile(source);
 	QString tempFileName;
 	QTemporaryFile* tempFile = new QTemporaryFile(target + "_XXXXXX");
@@ -178,8 +192,15 @@
 {
 	if (source.isEmpty() || target.isEmpty())
 		return false;
-	if (source == target)
-		return false;
+
+	// Make sure to compare source and target paths
+	// by using same directory separators. Source and target
+	// arguments might use native and Qt's separators for eg
+	QString qtSource = QDir::fromNativeSeparators(source);
+	QString qtTarget = QDir::fromNativeSeparators(target);
+	if (qtSource == qtTarget)
+		return false;
+
 	bool moveSucceed = copyFile(source, target);
 	if (moveSucceed)
 		moveSucceed &= QFile::remove(source);




More information about the scribus-commit mailing list