DevHeads.net

Review Request: Fix KConfigIniBackend::isWritable() when the parent directory doesn't exist

Review request for kdelibs.

Description
KConfigIniBackend::isWritable() tries to handle cases where the config
file doesn't exist and one or more of the deepest directories don't
exist either, in which case 'true' is returned if the deepest directory
is writable.

However, this fails because the code tries to use QDir::cdUp() to go
upwards until an existing directory is found. As per documentation,
cdUp() will fail when the parent directory doesn't exist, causing
isWritable() to bail out and return false without checking further
parent directories.

This will cause e.g. KConfig::accessMode() to return ReadOnly if the
configuration directory structure doesn't exist yet, even if the KConfig
is actually writeable (the parent directories are automatically created
by KConfigIniBackend at writing time). This was observed at
<a href="https://bugs.mageia.org/show_bug.cgi?id=3601#c10" title="https://bugs.mageia.org/show_bug.cgi?id=3601#c10">https://bugs.mageia.org/show_bug.cgi?id=3601#c10</a>

Fix that by walking through the tree using QFileInfo::absolutePath()
instead.

Diffs
kdecore/config/kconfigini.cpp 5f7ba7c

Diff: <a href="http://git.reviewboard.kde.org/r/103577/diff/diff" title="http://git.reviewboard.kde.org/r/103577/diff/diff">http://git.reviewboard.kde.org/r/103577/diff/diff</a>

Testing
Built kdelibs 4.7.95 with the patch, the error message in the referenced Mageia bugreport comment (which is shown when accessMode() returns ReadOnly) doesn't show up anymore when the ~/.kde4 directory tree doesn't exist. Also, if I create an empty ~/.kde4 dir without any permissions, the accessMode() call still returns ReadOnly as expected.

Thanks,

Anssi Hannula

Comments

Re: Review Request: Fix KConfigIniBackend::isWritable() when the

By Commit Hook at 01/27/2012 - 08:20

This review has been submitted with commit dec29afc01df5129049f232b5a8aa5080315b4c7 by David Faure to branch KDE/4.8.

- Commit Hook

On Dec. 30, 2011, 2:44 a.m., Anssi Hannula wrote:

Re: Review Request: Fix KConfigIniBackend::isWritable() when the

By Commit Hook at 01/04/2012 - 18:53

This review has been submitted with commit f8f07161e04f8ffececade97e8deaef7385dbaec by David Faure to branch KDE/4.8.

- Commit Hook

On Dec. 30, 2011, 2:44 a.m., Anssi Hannula wrote:

Re: Review Request: Fix KConfigIniBackend::isWritable() when the

By David Faure at 01/02/2012 - 05:12

Ship it!

Looks good. A bit hard to read, but that's QDir/QFileInfo's fault, not yours :)

You don't seem to have a kde contributor account, do you want to get one, or should I commit this for you?

- David Faure

On Dec. 30, 2011, 2:44 a.m., Anssi Hannula wrote:

Re: Review Request: Fix KConfigIniBackend::isWritable() when the

By Anssi Hannula at 01/02/2012 - 10:43

I expect to come up with patches only occasionally (a few per year at most thus far), so I guess I don't need an account, unless it is common in kde for even very infrequent contributors to have one.

- Anssi

On Dec. 30, 2011, 2:44 a.m., Anssi Hannula wrote: