forked from qt-creator/qt-creator
Utils: Remove remote specific code from FileSaver
Remote devices support enough functionality now that this is no longer needed. Change-Id: I5c9d3cba6d9e7511b43360f95472cc5c7893676f Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -190,22 +190,15 @@ FileSaver::FileSaver(const FilePath &filePath, QIODevice::OpenMode mode)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (filePath.needsDevice()) {
|
|
||||||
// Write to a local temporary file first. Actual saving to the selected location
|
const bool readOnlyOrAppend = mode & (QIODevice::ReadOnly | QIODevice::Append);
|
||||||
// is done via m_filePath.writeFileContents() in finalize()
|
m_isSafe = !readOnlyOrAppend && !filePath.hasHardLinks()
|
||||||
m_isSafe = false;
|
&& !qtcEnvironmentVariableIsSet("QTC_DISABLE_ATOMICSAVE");
|
||||||
auto tf = new QTemporaryFile(QDir::tempPath() + "/remotefilesaver-XXXXXX");
|
if (m_isSafe)
|
||||||
tf->setAutoRemove(false);
|
m_file.reset(new SaveFile(filePath));
|
||||||
m_file.reset(tf);
|
else
|
||||||
} else {
|
m_file.reset(new QFile{filePath.toFSPathString()});
|
||||||
const bool readOnlyOrAppend = mode & (QIODevice::ReadOnly | QIODevice::Append);
|
|
||||||
m_isSafe = !readOnlyOrAppend && !filePath.hasHardLinks()
|
|
||||||
&& !qtcEnvironmentVariableIsSet("QTC_DISABLE_ATOMICSAVE");
|
|
||||||
if (m_isSafe)
|
|
||||||
m_file.reset(new SaveFile(filePath));
|
|
||||||
else
|
|
||||||
m_file.reset(new QFile{filePath.path()});
|
|
||||||
}
|
|
||||||
if (!m_file->open(QIODevice::WriteOnly | mode)) {
|
if (!m_file->open(QIODevice::WriteOnly | mode)) {
|
||||||
QString err = filePath.exists() ?
|
QString err = filePath.exists() ?
|
||||||
Tr::tr("Cannot overwrite file %1: %2") : Tr::tr("Cannot create file %1: %2");
|
Tr::tr("Cannot overwrite file %1: %2") : Tr::tr("Cannot create file %1: %2");
|
||||||
@@ -216,16 +209,6 @@ FileSaver::FileSaver(const FilePath &filePath, QIODevice::OpenMode mode)
|
|||||||
|
|
||||||
bool FileSaver::finalize()
|
bool FileSaver::finalize()
|
||||||
{
|
{
|
||||||
if (m_filePath.needsDevice()) {
|
|
||||||
m_file->close();
|
|
||||||
m_file->open(QIODevice::ReadOnly);
|
|
||||||
const QByteArray data = m_file->readAll();
|
|
||||||
const expected_str<qint64> res = m_filePath.writeFileContents(data);
|
|
||||||
m_file->remove();
|
|
||||||
m_file.reset();
|
|
||||||
return res.has_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_isSafe)
|
if (!m_isSafe)
|
||||||
return FileSaverBase::finalize();
|
return FileSaverBase::finalize();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user