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_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)) {
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user