forked from qt-creator/qt-creator
bugfix for windows: trying to open files stored on network drives relied on QFileInfo::isWritable() without using the real filesystem checks
This commit is contained in:
committed by
Thorbjørn Lindeijer
parent
fcfd3ae58a
commit
1898c4dbff
25
src/plugins/texteditor/basetextdocument.cpp
Normal file → Executable file
25
src/plugins/texteditor/basetextdocument.cpp
Normal file → Executable file
@@ -47,6 +47,8 @@
|
|||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
|
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
|
||||||
|
|
||||||
#if defined (Q_OS_WIN)
|
#if defined (Q_OS_WIN)
|
||||||
# define NATIVE_LINE_TERMINATOR CRLFLineTerminator
|
# define NATIVE_LINE_TERMINATOR CRLFLineTerminator
|
||||||
#else
|
#else
|
||||||
@@ -140,8 +142,21 @@ bool BaseTextDocument::isReadOnly() const
|
|||||||
return true;
|
return true;
|
||||||
if (m_fileName.isEmpty()) //have no corresponding file, so editing is ok
|
if (m_fileName.isEmpty()) //have no corresponding file, so editing is ok
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QFileInfo fi(m_fileName);
|
const QFileInfo fi(m_fileName);
|
||||||
return !fi.isWritable();
|
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
// be careful when getting info from files on network drives
|
||||||
|
int old_ntfs_permission_lookup = qt_ntfs_permission_lookup;
|
||||||
|
qt_ntfs_permission_lookup = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const int ro = !fi.isWritable();
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
qt_ntfs_permission_lookup = old_ntfs_permission_lookup;
|
||||||
|
#endif
|
||||||
|
return ro;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseTextDocument::isModified() const
|
bool BaseTextDocument::isModified() const
|
||||||
@@ -163,13 +178,9 @@ bool BaseTextDocument::open(const QString &fileName)
|
|||||||
if (!fi.isReadable())
|
if (!fi.isReadable())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!fi.isWritable()) {
|
if (!file.open(QIODevice::ReadWrite) && !file.open(QIODevice::ReadOnly))
|
||||||
if (!file.open(QIODevice::ReadOnly))
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
if (!file.open(QIODevice::ReadWrite))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
title = fi.fileName();
|
title = fi.fileName();
|
||||||
|
|
||||||
QByteArray buf = file.readAll();
|
QByteArray buf = file.readAll();
|
||||||
|
Reference in New Issue
Block a user