[DirectorySizeJob] Fix sub-dirs count when resolving symlinks to dirs
ClosedPublic

Authored by ahmadsamir on Apr 1 2020, 7:23 AM.

Details

Summary

After 730a6ddd828fb1fbdf0f3, the behaviour changed and the code sets
KIO::UDSEntry::UDS_DEVICE_ID after symlinks are resovled (if
KIO::StatResolveSymlink is set); this meant that if we have dir A and
a symlink to it B, the loop that detects hard-links will skip A if B
was processed before, as both will have the same inode.

This fixes the directorySize() unit test from kiocore-jobtest; the
totalSubdirs() count didn't match the expected value.

Test Plan

make && ctest

Diff Detail

Repository
R241 KIO
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ahmadsamir created this revision.Apr 1 2020, 7:23 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptApr 1 2020, 7:23 AM
ahmadsamir requested review of this revision.Apr 1 2020, 7:23 AM
dfaure accepted this revision.Apr 1 2020, 8:49 AM

Yay for unittests (and my bad for not running them when making that change). Thanks for the fix!

This revision is now accepted and ready to land.Apr 1 2020, 8:49 AM
This revision was automatically updated to reflect the committed changes.
dfaure added a comment.Apr 5 2020, 6:30 PM

Does the test pass for you now?

For me it fails (and it fails on FreeBSD CI too https://build.kde.org/job/Frameworks/job/kio/job/kf5-qt5%20FreeBSDQt5.14/37/testReport/junit/projectroot/autotests/kiocore_jobtest/)

FAIL! : JobTest::directorySize() Compared values are not the same

Actual   (job->totalSubdirs()): 3
Expected (4ULL)               : 4
Loc: [/d/kde/src/5/frameworks/kio/autotests/jobtest.cpp(1133)]

What's happening is

QDEBUG : JobTest::directorySize() KIO::DirectorySizeJobPrivate::slotEntries subdir "dirFromHome" => 1
QDEBUG : JobTest::directorySize() KIO::DirectorySizeJobPrivate::slotEntries Skip visited inode "dirFromHome_link"
QDEBUG : JobTest::directorySize() KIO::DirectorySizeJobPrivate::slotEntries subdir "dirFromHome_copied" => 2
QDEBUG : JobTest::directorySize() KIO::DirectorySizeJobPrivate::slotEntries subdir "dirFromHome_copied/dirFromHome" => 3

http://www.davidfaure.fr/2020/debug.diff

I think the problem is that order is undefined. If the symlink is seen first, both will be counted (your if() is only around the insert). If it's seen second, it'll be skipped.

I think we should skip the whole visitedInodes thing for symlinks, not just the insert.

dfaure added a comment.Apr 5 2020, 6:34 PM

Suggested fix in D28601