forked from qt-creator/qt-creator
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:
@@ -192,7 +192,7 @@ FileSaver::FileSaver(const FilePath &filePath, QIODevice::OpenMode mode)
|
|||||||
m_file.reset(new QFile{filePath.path()});
|
m_file.reset(new QFile{filePath.path()});
|
||||||
m_isSafe = false;
|
m_isSafe = false;
|
||||||
} else {
|
} else {
|
||||||
m_file.reset(new SaveFile{filePath.path()});
|
m_file.reset(new SaveFile(filePath));
|
||||||
m_isSafe = true;
|
m_isSafe = true;
|
||||||
}
|
}
|
||||||
if (!m_file->open(QIODevice::WriteOnly | mode)) {
|
if (!m_file->open(QIODevice::WriteOnly | mode)) {
|
||||||
|
@@ -20,8 +20,8 @@ namespace Utils {
|
|||||||
|
|
||||||
static QFile::Permissions m_umask;
|
static QFile::Permissions m_umask;
|
||||||
|
|
||||||
SaveFile::SaveFile(const QString &filename) :
|
SaveFile::SaveFile(const FilePath &filePath) :
|
||||||
m_finalFileName(filename)
|
m_finalFilePath(filePath)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,16 +32,16 @@ SaveFile::~SaveFile()
|
|||||||
|
|
||||||
bool SaveFile::open(OpenMode flags)
|
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
|
// Check whether the existing file is writable
|
||||||
if (ofi.exists() && !ofi.open(QIODevice::ReadWrite)) {
|
if (ofi.exists() && !ofi.open(QIODevice::ReadWrite)) {
|
||||||
setErrorString(ofi.errorString());
|
setErrorString(ofi.errorString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_tempFile = std::make_unique<QTemporaryFile>(m_finalFileName);
|
m_tempFile = std::make_unique<QTemporaryFile>(m_finalFilePath.toFSPathString());
|
||||||
m_tempFile->setAutoRemove(false);
|
m_tempFile->setAutoRemove(false);
|
||||||
if (!m_tempFile->open())
|
if (!m_tempFile->open())
|
||||||
return false;
|
return false;
|
||||||
@@ -100,7 +100,7 @@ bool SaveFile::commit()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString finalFileName = FilePath::fromString(m_finalFileName).resolveSymlinks().toString();
|
QString finalFileName = m_finalFilePath.resolveSymlinks().toString();
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
// Release the file lock
|
// Release the file lock
|
||||||
@@ -200,4 +200,4 @@ void SaveFile::initializeUmask()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // Utils
|
||||||
|
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "utils_global.h"
|
#include "utils_global.h"
|
||||||
|
|
||||||
|
#include "filepath.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@@ -17,10 +19,8 @@ namespace Utils {
|
|||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT SaveFile : public QFile
|
class QTCREATOR_UTILS_EXPORT SaveFile : public QFile
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SaveFile(const QString &filename);
|
explicit SaveFile(const FilePath &filePath);
|
||||||
~SaveFile() override;
|
~SaveFile() override;
|
||||||
|
|
||||||
bool open(OpenMode flags = QIODevice::WriteOnly) override;
|
bool open(OpenMode flags = QIODevice::WriteOnly) override;
|
||||||
@@ -31,9 +31,9 @@ public:
|
|||||||
static void initializeUmask();
|
static void initializeUmask();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_finalFileName;
|
const FilePath m_finalFilePath;
|
||||||
std::unique_ptr<QTemporaryFile> m_tempFile;
|
std::unique_ptr<QTemporaryFile> m_tempFile;
|
||||||
bool m_finalized = true;
|
bool m_finalized = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Utils
|
} // Utils
|
||||||
|
@@ -358,7 +358,7 @@ void CppModelManager::showPreprocessedFile(bool inNextSplit)
|
|||||||
};
|
};
|
||||||
static const auto saveAndOpen = [](const FilePath &filePath, const QByteArray &contents,
|
static const auto saveAndOpen = [](const FilePath &filePath, const QByteArray &contents,
|
||||||
bool inNextSplit) {
|
bool inNextSplit) {
|
||||||
SaveFile f(filePath.toString());
|
SaveFile f(filePath);
|
||||||
if (!f.open()) {
|
if (!f.open()) {
|
||||||
showError(Tr::tr("Failed to open output file \"%1\".").arg(filePath.toUserOutput()));
|
showError(Tr::tr("Failed to open output file \"%1\".").arg(filePath.toUserOutput()));
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user