diff options
Diffstat (limited to 'src/libs/kdtools/kdsavefile.cpp')
-rw-r--r-- | src/libs/kdtools/kdsavefile.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/libs/kdtools/kdsavefile.cpp b/src/libs/kdtools/kdsavefile.cpp index 88b95f42e..8e2209604 100644 --- a/src/libs/kdtools/kdsavefile.cpp +++ b/src/libs/kdtools/kdsavefile.cpp @@ -54,7 +54,7 @@ #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> -#ifdef Q_OS_LINUX +#ifdef Q_OS_UNIX #include <unistd.h> #endif @@ -174,11 +174,10 @@ static QFile *createFile(const QString &path, QIODevice::OpenMode m, QFile::Perm */ static QString generateTempFileName(const QString &path) { - const QString tmp = path + QLatin1String("tmp.dsfdf.%1"); //TODO: use random suffix - int count = 1; - while (QFile::exists(tmp.arg(count))) - ++count; - return tmp.arg(count); + QTemporaryFile tmpfile(path); + tmpfile.open(); + const QString tmp = tmpfile.fileName(); + return tmp; } /*! @@ -384,7 +383,7 @@ bool KDSaveFile::commit(KDSaveFile::CommitMode mode) } if (mode == OverwriteExistingFile) { QFile tmp(backup); - const bool removed = !tmp.exists() || tmp.remove(backup); + const bool removed = !tmp.exists() || tmp.remove(); if (!removed) qWarning() << "Could not remove the backup: " << tmp.errorString(); } |