[Balooctl] remove directory parent check
ClosedPublic

Authored by ngraham on Sep 18 2018, 2:18 AM.

Details

Summary

balooctl add includeFolders/excludeFolders was checking for parent directories before allowing the user to add a subdirectory. This is unnecessary since Baloo itself supports the logic of (for example) excluding ~/foo but including ~/foo/bar. Removing the check solves the problem and fixes 396535.

BUG: 396535
FIXED-IN: 5.51

Test Plan
mkdir ~/test1 ~/test2 ~/test1-test ~/test1-test/foo
balooctl config add excludeFolders ~/test1
balooctl config add excludeFolders ~/test2
balooctl config add excludeFolders ~/test1-test
balooctl config add includeFolders ~/test1-test/foo

If it worked, you don't get any errors.

Diff Detail

Repository
R293 Baloo
Branch
arcpatch-D15583
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 3128
Build 3146: arc lint + arc unit
ngraham created this revision.Sep 18 2018, 2:18 AM
Restricted Application added projects: Frameworks, Baloo. · View Herald TranscriptSep 18 2018, 2:18 AM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
ngraham requested review of this revision.Sep 18 2018, 2:18 AM
cfeck resigned from this revision.Sep 20 2018, 12:34 PM

In Qt 5.9 (if i remember correct) was introduced to not have trailing '/' so, QDir::separator should not be used, so better get folder as copy

for (QString folder : folders) {
    if (!folder.endsWith(QLatin1Char('/')) {
        folder += QLaitin1Char('/');
    }
    if (path.startsWith(folder)) {
ngraham planned changes to this revision.Sep 21 2018, 2:30 AM

Actually it looks like we shouldn't even use it anyway for other reasons per the documentation: https://doc.qt.io/qt-5/qdir.html#separator

They recommend always using / directly like you indicate, so I'll do that.

ngraham updated this revision to Diff 42018.Sep 21 2018, 2:38 AM
  • Address review comments and do it better
ngraham edited the summary of this revision. (Show Details)Sep 21 2018, 2:43 AM
ngraham edited the test plan for this revision. (Show Details)
bruns added a comment.Sep 22 2018, 1:41 PM

I think the whole startsWith is flawed - it should be possible to have a e.g. "/home/user/foo/bar" include when "/home/user/foo" has been excluded.

I think the whole startsWith is flawed - it should be possible to have a e.g. "/home/user/foo/bar" include when "/home/user/foo" has been excluded.

Hmm, I'm not sure how much that matches the user expectation. If a folder is explicitly marked as excluded, I think it's most commonly understood that all its sub-folders would also be excluded.

I could see the case for allowing this behavior to be explicitly overridden by an advanced user who marks ~/foo/ as excluded and then later marks ~foo/bar/ as included, but that would be material for another patch I think.

bruns added a comment.Sep 22 2018, 5:44 PM

I think the whole startsWith is flawed - it should be possible to have a e.g. "/home/user/foo/bar" include when "/home/user/foo" has been excluded.

Hmm, I'm not sure how much that matches the user expectation. If a folder is explicitly marked as excluded, I think it's most commonly understood that all its sub-folders would also be excluded.

I could see the case for allowing this behavior to be explicitly overridden by an advanced user who marks ~/foo/ as excluded and then later marks ~foo/bar/ as included, but that would be material for another patch I think.

If I read the unit tests correctly (https://phabricator.kde.org/source/baloo/browse/master/autotests/unit/file/fileindexerconfigtest.cpp), this is already supported. You just can not do it via balooctl.

Oh wow, you're right. Let me fix balooctl to support that, then.

ngraham updated this revision to Diff 42152.Sep 22 2018, 8:25 PM
ngraham edited the test plan for this revision. (Show Details)

Remove parent directory check entirely; it's not necessary

ngraham retitled this revision from [Balooctl] fix directory parent check to [Balooctl] remove directory parent check.Sep 22 2018, 8:28 PM
ngraham edited the summary of this revision. (Show Details)
ngraham edited the test plan for this revision. (Show Details)

Technically, this check isn't actually needed, though it does prevent the user from entering a path more than once. At first glance this looks like it should work:

if (folder.startsWith(path))

This doesn't prevent the user from also re-specifying valid paths.

bruns added a comment.EditedSep 24 2018, 3:14 AM

Technically, this check isn't actually needed, though it does prevent the user from entering a path more than once. At first glance this looks like it should work:

if (folder.startsWith(path))

This doesn't prevent the user from also re-specifying valid paths.

Exact matches are already rejected in the block above.

folder.startsWith(path) is also pointless, a user should be allowed to e.g. exclude <home>/foo/ if <home>/foo/bar/baz is excluded and <home>/foo/bar is included.

What was wrong with https://phabricator.kde.org/D15583?id=42018 ?

I could see the case for allowing this behavior to be explicitly overridden by an advanced user who marks ~/foo/ as excluded and then later marks ~foo/bar/ as included, but that would be material for another patch I think.

This is actually already how this works, the excludes and includes are both resolved into either an index path or do not index path outcome.

https://phabricator.kde.org/D15583?id=42018 didn't let you add ~/foo/bar to the list of includes or excludes if ~/foo was already present.

bruns accepted this revision.Sep 30 2018, 12:10 AM
This revision is now accepted and ready to land.Sep 30 2018, 12:10 AM
This revision was automatically updated to reflect the committed changes.