[Gambas-user] Pb instanciating inotify watch

Tobias Boege taboege at gmail.com
Thu Mar 7 07:16:21 CET 2019


On Wed, 06 Mar 2019, T Lee Davidson wrote:
> On 3/6/19 6:28 PM, Matthew Collins wrote:
> > On 2 Mar 2019, at 19:33, T Lee Davidson <t.lee.davidson at gmail.com <mailto:t.lee.davidson at gmail.com>> wrote:
> > > On 3/2/19 2:22 PM, Tobias Boege wrote:
> > > Indeed, the classes were redesigned. The 'too many arguments' error
> > > is caused by the parameters in the event handler's (Create, Delete)
> > > signatures.
> > > 
> > > The example needs a little reworking:
> > > 
> > > ' Gambas module file
> > > 
> > > Public Sub Main()
> > >  ' Disable all unneeded events to increase performance
> > >  Dim hWatch As New Watch("/tmp/gambas." & Str$(User.Id), True, 0) As "GambasDirectory"
> > > 
> > >  ' Capture creation and deletion of files or directories
> > >  hWatch.Events[Watch.Create] = True
> > >  hWatch.Events[Watch.Delete] = True
> > >  Print "I'm watching... You may now start Gambas projects."
> > > End
> > > 
> > > Public Sub GambasDirectory_Create()
> > >  If Not Watch.IsDir Then Return
> > >  Print "New directory for Gambas process";; Watch.Name;; " - ";;
> > >  With Split(File.Load("/proc" &/ Watch.Name &/ "cmdline"), "/")
> > >    Print "which is";; Left$(.[.Max], -1)
> > >  End With
> > > End
> > > 
> > > Public Sub GambasDirectory_Delete()
> > >  If Not Watch.IsDir Then Return
> > >  ' The directory in /proc/ may be removed at this time so we can't
> > >  ' get any more information.
> > >  Print "Gambas process";; Watch.Name;; "terminated (normally)"
> > > End
> > > 
> > Your example only notifies on delete and not create (the last event set)...
> > 
> > Please try out this new runnable example in the wiki:
> > http://gambaswiki.org/wiki/comp/gb.inotify/watch
> > 
> That actually wasn't my example. It was a very quick modification of an
> outdated example. I did not test it for proper operation since I figured it
> would be enough to get the OP started.
> 
> Thank you for the correction. I have deleted the commented lines in the Wiki example to avoid confusion.
> 

As far as I can see, you replaced

  hWatch.Events[Watch.Create] = True
  hWatch.Events[Watch.Delete] = True

by

  hWatch.Events[Watch.Delete Or Watch.Create] = True

Having to do this comes almost surely from a bug! It should be possible
to set events independently, because otherwise why would we have an
array accessor syntax for them instead of just a bitmask property?

The current implementation was done in the redesign phase mentioned
earlier in this thread and it doesn't use the RHS of the assignment
at all (try assigning False to .events[Watch.Create Or Watch.Delete],
it'll still work). That's a very strong sign it's an oversight bug.
I'm going to fix it, then fix the wiki example because why are you
watching "/" and observing changes?

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list