what happens when calling KDirWatch::addDir() multiple times with the same path?

David Faure faure at kde.org
Sun Dec 3 11:01:12 UTC 2017


On samedi 2 décembre 2017 21:56:12 CET René J.V. Bertin wrote:
> On Saturday December 02 2017 20:50:01 David Faure wrote:
> >Doesn't that function know that it already loaded that directory?
> 
> No. Well, in a sense it has access to that information somewhere, but
> checking that isn't different from having it check if the dirwatcher
> already has set a watch on the directory.

Both solutions are possible indeed, on paper.

> >I don't know what wrapper you have in mind.
> 
> The one I showed, checking KDirWatch::contains().

That's one if(), not necessarily a wrapper ;)
How many calls to addDir() are we talking about?

> I find it more elegant to
> write a thin wrapper around KDW (or extend KDW to support a mode without
> ref-counting) than query the app's internal data structure (directory
> representation) to see if the directory has already been loaded.

I disagree. I find it more elegant for an app to know what it's doing. Whatever 
else it's doing when "loading a directory" might also need to know that it 
already did that before, no? Clearing previous data structures, whatever.

> The dirwatcher can also be exported to other parts of the app's code which
> presumably can set or unset watches (still need to check that).

Which is exactly why refcounting exists. If those other parts of the code
need to stop watching for some reason (other than dir deletion!),
then you still want your "directory loader" to keep watching.

> >I don't expect trouble. Why removeDir() at all, then?
> 
> With iNotify it may not be necessary if I read you correctly. Other backends
> used by QFileSystemWatcher have platform-dependent limitations which make
> it a good idea not to leave resource allocated unnecesarily.

All KDirWatch backends do the same, they remember "it was deleted"
and are ready to notify again if it reappears.
This is about KDevelop iirc? How many times do people delete entire 
directories in kdevelop? Is one dormant entry in KDirWatch really worth all 
this trouble?

I was rather expecting that the use case for removeDir would be closing a 
project though.

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5





More information about the Kde-frameworks-devel mailing list