Bug 191016 - KFileDialog No error when not enough permissions to enter folder
Summary: KFileDialog No error when not enough permissions to enter folder
Status: RESOLVED FIXED
Alias: None
Product: kdelibs
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: kdelibs bugs
URL:
Keywords: investigated
Depends on:
Blocks:
 
Reported: 2009-04-29 11:39 UTC by Ivo Anjo
Modified: 2009-08-20 02:02 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch to preserve trailing slash when checking parent dir (614 bytes, patch)
2009-07-22 13:26 UTC, Ivo Anjo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ivo Anjo 2009-04-29 11:39:01 UTC
Version:            (using KDE 4.2.2)
OS:                Linux
Installed from:    SuSE RPMs

I created a test directory with
$ mkdir testdir
then I removed all permissions from it
$ chmod a-rwx testdir/

Now if I try to enter this directory in a KFileDialog, I can't, but no error is shown, my clicks are just ignored -- I click on the folder, and nothing happens.
Comment 1 Dario Andres 2009-04-29 16:58:55 UTC
Here using:

Qt: 4.5.1 (qt-copy  958974)
KDE: 4.2.71 (KDE 4.2.71 (KDE 4.3 >= 20090428))
kdelibs svn rev. 960693 / kdebase svn rev. 960693
on ArchLinux i686 - Kernel 2.6.29.1

I can confirm this behaviour
Comment 2 Dario Andres 2009-07-15 16:26:40 UTC
I just checked the code.

kdelibs/kfile/kdiroperator.cpp:1030~ ( "setUrl()" )
"
    if (!Private::isReadable(newurl)) {
        // maybe newurl is a file? check its parent directory
        newurl.setPath(newurl.directory());
        if (newurl.equals(d->currUrl, KUrl::CompareWithoutTrailingSlash))
            return; // parent is current dir, nothing to do (fixes #173454, too)
        KIO::UDSEntry entry;
        bool res = KIO::NetAccess::stat(newurl, entry, this);
        KFileItem i(entry, newurl);
        if ((!res || !Private::isReadable(newurl)) && i.isDir()) {
            resetCursor();
            KMessageBox::error(d->itemView,
                               i18n("The specified folder does not exist "
                                    "or was not readable."));
            return;
        } else if (!i.isDir()) {
            return;
        }
    }

"

We are getting into 
"
    if (!Private::isReadable(newurl)) {
        // maybe newurl is a file? check its parent directory
        newurl.setPath(newurl.directory());
        if (newurl.equals(d->currUrl, KUrl::CompareWithoutTrailingSlash))
            return; // parent is current dir, nothing to do (fixes #173454, too)
"

So it returns before showing the error messagebox.
@David: you introduced some of the code there (bug 173454) (even when the previous code should also fail I think). Should the messagebox code be moved up or will it affect the code. ?

Regards
Comment 3 Ivo Anjo 2009-07-17 02:34:24 UTC
(In reply to comment #2)
> We are getting into 
> "
>     if (!Private::isReadable(newurl)) {
>         // maybe newurl is a file? check its parent directory
>         newurl.setPath(newurl.directory());
>         if (newurl.equals(d->currUrl, KUrl::CompareWithoutTrailingSlash))
>             return; // parent is current dir, nothing to do (fixes #173454,
> too)
> "
> 
> So it returns before showing the error messagebox.

I think Dario is right. The problem is that if current path is /x/ and we try to enter /x/y/ and hit this codepath, newurl.setPath(newurl.directory()) will set newurl as /x/ again, and so current path will equal newurl, and no error will be shown.

This is because the default for KUrl::directory is KUrl::IgnoreTrailingSlash, so the last slash is "eaten". I think the correct thing to do is use the ObeyTrailingSlash, this way it works well for files (so bug 173454 is still fixed), and also fixes the problem for directories.

Waiting for the OK to commit this to trunk and branch :)

Index: kfile/kdiroperator.cpp
===================================================================
--- kfile/kdiroperator.cpp      (revision 996074)
+++ kfile/kdiroperator.cpp      (working copy)
@@ -1056,7 +1056,7 @@

     if (!Private::isReadable(newurl)) {
         // maybe newurl is a file? check its parent directory
-        newurl.setPath(newurl.directory());
+        newurl.setPath(newurl.directory(KUrl::ObeyTrailingSlash));
         if (newurl.equals(d->currUrl, KUrl::CompareWithoutTrailingSlash))
             return; // parent is current dir, nothing to do (fixes #173454, too)
         KIO::UDSEntry entry;
Comment 4 Ivo Anjo 2009-07-22 13:26:57 UTC
Created attachment 35542 [details]
Patch to preserve trailing slash when checking parent dir
Comment 5 Dario Andres 2009-07-22 16:05:32 UTC
I'm not confident to review this patch alone so I will wait a bit for David. You could also try to open a review request on reviewboard
Comment 6 Ivo Anjo 2009-08-05 17:26:35 UTC
Submitted to reviewboard: http://reviewboard.kde.org/r/1230/
Comment 7 David Faure 2009-08-19 17:22:00 UTC
Looks good to me, please commit.
Comment 8 Dario Andres 2009-08-20 01:59:18 UTC
SVN commit 1013462 by darioandres:

- Show an error message when a folder can't be accesed in the filedialog

BUG: 191016 


 M  +1 -1      kdiroperator.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1013462
Comment 9 Dario Andres 2009-08-20 02:01:57 UTC
SVN commit 1013463 by darioandres:

Backport to 4.3 of:
SVN commit 1013462 by darioandres:

- Show an error message when a folder can't be accesed in the filedialog

CCBUG: 191016 


 M  +1 -1      kdiroperator.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1013463
Comment 10 Dario Andres 2009-08-20 02:02:38 UTC
@Ivo Anjo: you can close the review request now :)