Utils: Push FilePath::toString border line a bit further

... in SaveFile

Change-Id: I80164853b8a756af8c74038b0375c423a6f500e2
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-01-13 09:53:45 +01:00
parent 6585b3668c
commit 2ce413112b
4 changed files with 14 additions and 14 deletions

View File

@@ -192,7 +192,7 @@ FileSaver::FileSaver(const FilePath &filePath, QIODevice::OpenMode mode)
m_file.reset(new QFile{filePath.path()});
m_isSafe = false;
} else {
m_file.reset(new SaveFile{filePath.path()});
m_file.reset(new SaveFile(filePath));
m_isSafe = true;
}
if (!m_file->open(QIODevice::WriteOnly | mode)) {

View File

@@ -20,8 +20,8 @@ namespace Utils {
static QFile::Permissions m_umask;
SaveFile::SaveFile(const QString &filename) :
m_finalFileName(filename)
SaveFile::SaveFile(const FilePath &filePath) :
m_finalFilePath(filePath)
{
}
@@ -32,16 +32,16 @@ SaveFile::~SaveFile()
bool SaveFile::open(OpenMode flags)
{
QTC_ASSERT(!m_finalFileName.isEmpty(), return false);
QTC_ASSERT(!m_finalFilePath.isEmpty(), return false);
QFile ofi(m_finalFileName);
QFile ofi(m_finalFilePath.toFSPathString());
// Check whether the existing file is writable
if (ofi.exists() && !ofi.open(QIODevice::ReadWrite)) {
setErrorString(ofi.errorString());
return false;
}
m_tempFile = std::make_unique<QTemporaryFile>(m_finalFileName);
m_tempFile = std::make_unique<QTemporaryFile>(m_finalFilePath.toFSPathString());
m_tempFile->setAutoRemove(false);
if (!m_tempFile->open())
return false;
@@ -100,7 +100,7 @@ bool SaveFile::commit()
return false;
}
QString finalFileName = FilePath::fromString(m_finalFileName).resolveSymlinks().toString();
QString finalFileName = m_finalFilePath.resolveSymlinks().toString();
#ifdef Q_OS_WIN
// Release the file lock
@@ -200,4 +200,4 @@ void SaveFile::initializeUmask()
#endif
}
} // namespace Utils
} // Utils

View File

@@ -5,6 +5,8 @@
#include "utils_global.h"
#include "filepath.h"
#include <QFile>
QT_BEGIN_NAMESPACE
@@ -17,10 +19,8 @@ namespace Utils {
class QTCREATOR_UTILS_EXPORT SaveFile : public QFile
{
Q_OBJECT
public:
explicit SaveFile(const QString &filename);
explicit SaveFile(const FilePath &filePath);
~SaveFile() override;
bool open(OpenMode flags = QIODevice::WriteOnly) override;
@@ -31,9 +31,9 @@ public:
static void initializeUmask();
private:
const QString m_finalFileName;
const FilePath m_finalFilePath;
std::unique_ptr<QTemporaryFile> m_tempFile;
bool m_finalized = true;
};
} // namespace Utils
} // Utils

View File

@@ -358,7 +358,7 @@ void CppModelManager::showPreprocessedFile(bool inNextSplit)
};
static const auto saveAndOpen = [](const FilePath &filePath, const QByteArray &contents,
bool inNextSplit) {
SaveFile f(filePath.toString());
SaveFile f(filePath);
if (!f.open()) {
showError(Tr::tr("Failed to open output file \"%1\".").arg(filePath.toUserOutput()));
return;