1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-13 10:32:11 +01:00

QzTools: Fix ensureUniqueFileName when file has no suffix

Closes #1706
This commit is contained in:
David Rosca 2015-10-01 20:05:36 +02:00
parent 800cc14dcd
commit ffcf137967

View File

@ -223,22 +223,23 @@ QString QzTools::ensureUniqueFilename(const QString &name, const QString &append
return name; return name;
} }
QString tmpFileName = name; QString tmpPath = name;
int i = 1; int i = 1;
while (QFile::exists(tmpFileName)) { while (QFile::exists(tmpPath)) {
tmpFileName = name; tmpPath = name;
int index = tmpFileName.lastIndexOf(QLatin1Char('.')); int fileNameIndex = tmpPath.lastIndexOf(QL1C('/'));
int index = tmpPath.lastIndexOf(QL1C('.'), fileNameIndex);
QString appendString = appendFormat.arg(i); QString appendString = appendFormat.arg(i);
if (index == -1) { if (index == -1) {
tmpFileName.append(appendString); tmpPath.append(appendString);
} }
else { else {
tmpFileName = tmpFileName.left(index) + appendString + tmpFileName.mid(index); tmpPath = tmpPath.left(index) + appendString + tmpPath.mid(index);
} }
i++; i++;
} }
return tmpFileName; return tmpPath;
} }
QString QzTools::getFileNameFromUrl(const QUrl &url) QString QzTools::getFileNameFromUrl(const QUrl &url)