aboutsummaryrefslogtreecommitdiff
path: root/src/core/kconfiggroup.cpp
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2022-04-24 15:08:59 +0200
committerDavid Faure <faure@kde.org>2022-05-04 09:37:32 +0000
commita0bf7b8e857eba8032e2c828ea2ed0ade09abbad (patch)
tree00da8f36c58a00bf5c8f2547f6f2bcba16a68eec /src/core/kconfiggroup.cpp
parent329c4f2ef85a1617cabc1b096b33dd114075138c (diff)
downloadkconfig-a0bf7b8e857eba8032e2c828ea2ed0ade09abbad.tar.gz
kconfig-a0bf7b8e857eba8032e2c828ea2ed0ade09abbad.tar.bz2
KConfigGroup: fix writePathEntry/readPathEntry roundtrip for symlinks
If $HOME isn't canonical (e.g. on FreeBSD it's /home/user while the canonical path is /usr/home/user), replacing the canonical version of $HOME with $HOME means that we'll read back a different value than we wrote in. It might seem "equivalent" but it leads to surprises like KRecentDocuments showing duplicates because /usr/home/user became /home/user in the KConfig roundtrip (but not in the XBEL roundtrip). This commit loses the replacement of /usr/home/user with $HOME on FreeBSD, but I think an exact roundtrip is what we expect, rather than stuff being modified under our feet. The alternative would be to canonicalize everything in KRecentDocuments but users don't want to see the /usr in front, I assume (so we would have to use a cache of canonicalized path, for the removal of duplicates, awful performance wise).
Diffstat (limited to 'src/core/kconfiggroup.cpp')
-rw-r--r--src/core/kconfiggroup.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/core/kconfiggroup.cpp b/src/core/kconfiggroup.cpp
index 8b7cd863..f3ab2202 100644
--- a/src/core/kconfiggroup.cpp
+++ b/src/core/kconfiggroup.cpp
@@ -425,16 +425,13 @@ static QString translatePath(QString path) // krazy:exclude=passbyvalue
return path;
}
- // we can not use KGlobal::dirs()->relativeLocation("home", path) here,
- // since it would not recognize paths without a trailing '/'.
- // All of the 3 following functions to return the user's home directory
- // can return different paths. We have to test all them.
- const QString homeDir0 = QFile::decodeName(qgetenv("HOME"));
- const QString homeDir1 = QDir::homePath();
- const QString homeDir2 = QDir(homeDir1).canonicalPath();
- if (cleanHomeDirPath(path, homeDir0) || cleanHomeDirPath(path, homeDir1) || cleanHomeDirPath(path, homeDir2)) {
- // qDebug() << "Path was replaced\n";
- }
+ // Use the same thing as what expandString() will do, to keep data intact
+#ifdef Q_OS_WIN
+ const QString homeDir = QDir::homePath();
+#else
+ const QString homeDir = QFile::decodeName(qgetenv("HOME"));
+#endif
+ (void)cleanHomeDirPath(path, homeDir);
if (startsWithFile) {
path = QUrl::fromLocalFile(path).toString();