Bug 193298

Summary: Wrong free disk space displayed when directory beginn with the same name
Product: [Applications] dolphin Reporter: Thomas Thym <ungethym>
Component: bars: statusAssignee: Dolphin Bug Assignee <dolphin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: adaptee
Priority: NOR Keywords: investigated, triaged
Version: 2.1   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In: 4.10.3
Sentry Crash Report:

Description Thomas Thym 2009-05-19 23:50:25 UTC
Version:            (using KDE 4.2.85)
OS:                Linux
Installed from:    SuSE RPMs

After mounting a new partition (19GiB free) at ~/Videos the original dir ~/Videos-Home (subdir of /home) shows the wrong free disk space (19 GiB) instead of 8 GiB.

When I rename the old dir from Videos-Home to another name, where the second dirname "Videos" is not part of (e.g. Video-Home, without the "s") the size is displayed korrectly.

It's not a hi-priority bug. Just wanted to report it.
Comment 1 Jekyll Wu 2012-08-17 07:27:59 UTC
Still reproducing using dolphin 2.1 . 

To make the report clear, the two folders are "~/Videos"(the mount point) and "~/Videos-Home" . Actually, the same problem can be reproduced using "~/book" ( the mount point) and "~/books" (a empty folder) .
Comment 2 Jekyll Wu 2012-08-17 12:32:25 UTC
This is actually a bug of kdelibs. 

in kdelibs/kio/kfile/kdiskfreespaceinfo.cpp

KDiskFreeSpaceInfo KDiskFreeSpaceInfo::freeSpaceInfo( const QString& path )
{
    ...
    KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath( path );
    ...
}

in kdelibs/kdecore/io/kmountpoint.cpp

KMountPoint::Ptr KMountPoint::List::findByPath(const QString& path) const
{
    ...

    int max = 0;
    KMountPoint::Ptr result;
    for (const_iterator it = begin(); it != end(); ++it) {
        const QString mountpoint = (*it)->d->mountPoint;
        const int length = mountpoint.length();
        if (realname.startsWith(mountpoint) && length > max) {
            max = length;
            result = *it;
            // keep iterating to check for a better match (bigger max)
        }
    }
}

So if "/home/myself/book" is a mount point, "/home/myself/books" will be seen as 
belonging to the partition mounted at "/home/myself/book", which is clearly wrong.
Comment 3 Jeroen van Meeuwen (Kolab Systems) 2012-08-24 16:19:43 UTC
Resetting assignee to default as per bug #305719
Comment 4 Frank Reininghaus 2012-11-06 07:24:19 UTC
Good investigation, Jekyll! Maybe one could solve this by using KUrl::isParentOf(const KUrl&), rather than QString:.startsWith(const QString&)?
Comment 5 Frank Reininghaus 2013-04-28 20:22:14 UTC
Git commit 4f2ecbabfa5bec07985175798ea20d90bdca9f82 by Frank Reininghaus.
Committed on 28/04/2013 at 22:19.
Pushed by freininghaus into branch 'KDE/4.10'.

Fix KMountPoint::List::findByPath(): /books is not a child of /book

Thanks to Jekyll Wu for the analysis and to David Faure for pointing out
another problem which I had missed.
FIXED-IN: 4.10.3
REVIEW: 110225

M  +20   -1    kdecore/io/kmountpoint.cpp

http://commits.kde.org/kdelibs/4f2ecbabfa5bec07985175798ea20d90bdca9f82