diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2014-05-28 19:25:17 +0200 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2014-07-24 18:50:40 +0200 |
commit | 8d15068911d7c0ba05732e2796aaa7a90e34a6a1 (patch) | |
tree | 8cdb778fb6136f1c20e3b4a2a372b350c2ac9f28 /tests | |
parent | d97624845ac87038413b692a6b256633226ee320 (diff) |
QSettings: use QSaveFile and QLockFile to write the settings
The old unix locking code is no longer working on unix since it locks on
a file descriptor, but QSaveFile creates a new file, and as a result we
get the lock on the wrong file. Also there is no need to keep the lock
held only for reading as QSaveFile is atomic. It just needs to be held
when doing a read before writing.
As a result, since we don't hold the same lock, there could be a race
with an application running an older version of Qt if they are writing
on the same configuration file.
[ChangeLog][QtCore][QSettings] Fixed data loss while writing the config
to the disk fails.
[ChangeLog][Important behavior changes] The locking mechanism inside
QSettings has changed and is no longer compatible with the one of
previous versions of Qt. There might be corruption if two applications
running different versions of Qt are writing to the same config file
at the same time. You must also now have write permissions in the
directory containing the settings file in order to write settings
Task-number: QTBUG-21739
Change-Id: I0844a5e96c8bc1e1222a3dac6cc48170ca77fe1b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 76 |
1 files changed, 73 insertions, 3 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 8174cd942f..37cb296ebb 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -78,9 +78,79 @@ #define Q_NO_SYMLINKS #endif -QT_BEGIN_NAMESPACE -extern Q_AUTOTEST_EXPORT bool qIsLikelyToBeNfs(int /* handle */); -QT_END_NAMESPACE + +#if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS) +inline bool qt_isEvilFsTypeName(const char *name) +{ + return (qstrncmp(name, "nfs", 3) == 0 + || qstrncmp(name, "autofs", 6) == 0 + || qstrncmp(name, "cachefs", 7) == 0); +} + +#if defined(Q_OS_BSD4) && !defined(Q_OS_NETBSD) +# include <sys/param.h> +# include <sys/mount.h> + +bool qIsLikelyToBeNfs(int handle) +{ + struct statfs buf; + if (fstatfs(handle, &buf) != 0) + return false; + return qt_isEvilFsTypeName(buf.f_fstypename); +} + +#elif defined(Q_OS_LINUX) || defined(Q_OS_HURD) + +# include <sys/vfs.h> +# ifdef QT_LINUXBASE + // LSB 3.2 has fstatfs in sys/statfs.h, sys/vfs.h is just an empty dummy header +# include <sys/statfs.h> +# endif + +# ifndef NFS_SUPER_MAGIC +# define NFS_SUPER_MAGIC 0x00006969 +# endif +# ifndef AUTOFS_SUPER_MAGIC +# define AUTOFS_SUPER_MAGIC 0x00000187 +# endif +# ifndef AUTOFSNG_SUPER_MAGIC +# define AUTOFSNG_SUPER_MAGIC 0x7d92b1a0 +# endif + +bool qIsLikelyToBeNfs(int handle) +{ + struct statfs buf; + if (fstatfs(handle, &buf) != 0) + return false; + return buf.f_type == NFS_SUPER_MAGIC + || buf.f_type == AUTOFS_SUPER_MAGIC + || buf.f_type == AUTOFSNG_SUPER_MAGIC; +} + +#elif defined(Q_OS_SOLARIS) || defined(Q_OS_IRIX) || defined(Q_OS_AIX) || defined(Q_OS_HPUX) \ + || defined(Q_OS_OSF) || defined(Q_OS_QNX) || defined(Q_OS_SCO) \ + || defined(Q_OS_UNIXWARE) || defined(Q_OS_RELIANT) || defined(Q_OS_NETBSD) + +# include <sys/statvfs.h> + +bool qIsLikelyToBeNfs(int handle) +{ + struct statvfs buf; + if (fstatvfs(handle, &buf) != 0) + return false; +#if defined(Q_OS_NETBSD) + return qt_isEvilFsTypeName(buf.f_fstypename); +#else + return qt_isEvilFsTypeName(buf.f_basetype); +#endif +} +#else +inline bool qIsLikelyToBeNfs(int /* handle */) +{ + return false; +} +#endif +#endif class tst_QFileInfo : public QObject { |